zoukankan      html  css  js  c++  java
  • Autotest NotePad with robotium

    1. private Solo solo;

       public NotePadTest() {
        super("com.example.android.notepad", NotesList.class);
        
       }
       
        public void setUp() throws Exception {
         solo = new Solo(getInstrumentation(), getActivity());
          }

       
        @Smoke
        public void testAddNote() throws Exception {
         solo.clickOnMenuItem("Add note");
         solo.assertCurrentActivity("Expected NoteEditor activity", "NoteEditor"); //Assert that NoteEditor activity is opened
         solo.enterText(0, "Note 1"); //In text field 0, add Note 1
         solo.goBack(); //Go back
         solo.clickOnMenuItem("Add note"); //Clicks on menu item
         solo.enterText(0, "Note 2"); //In text field 0, add Note 2
         solo.goBackToActivity("NotesList"); //Go back to first activity named "NotesList"
         boolean expected = true;
         boolean actual = solo.searchText("Note 1") && solo.searchText("Note 2");
         assertEquals("Note 1 and/or Note 2 are not found", expected, actual); //Assert that Note 1 & Note 2 are found
        
        }
       
       @Smoke
       public void testEditNote() throws Exception {
        solo.clickInList(2); // Clicks on the second list line
        solo.setActivityOrientation(Solo.LANDSCAPE); // Change orientation of activity
        solo.clickOnMenuItem("Edit title"); // Change title
        solo.enterText(0, " test"); //In first text field (0), add test.
        solo.goBackToActivity("NotesList");
        boolean expected = true;
        boolean actual = solo.searchText("(?i).*?note 1 test"); // (Regexp) case insensitive            // insensitive
        assertEquals("Note 1 test is not found", expected, actual); //Assert that Note 1 test is found

       }
       

       @Smoke
        public void testRemoveNote() throws Exception {
         solo.clickOnText("(?i).*?test.*");   //(Regexp) case insensitive/text that contains "test"
         solo.clickOnMenuItem("Delete");   //Delete Note 1 test
         boolean expected = false;   //Note 1 test & Note 2 should not be found
         boolean actual = solo.searchText("Note 1 test");
         assertEquals("Note 1 Test is found", expected, actual);  //Assert that Note 1 test is not found
         solo.clickLongOnText("Note 2");
         solo.clickOnText("(?i).*?Delete.*");  //Clicks on Delete in the context menu
         actual = solo.searchText("Note 2");
         assertEquals("Note 2 is found", expected, actual);  //Assert that Note 2 is not found
        }

       @Override
       public void tearDown() throws Exception {
        try {
         solo.finalize();  //Robotium will finish all the activities that have been open
        } catch (Throwable e) {
         e.printStackTrace();
        }
        getActivity().finish();
        super.tearDown();
       }

  • 相关阅读:
    JS校验 if (! temp_var) {} //拦截 ''和 undefined
    17 JQuery高级----学习笔记
    16 JQuery---JavaScript框架
    15 Filter过滤器和Listener监听器
    14 用户信息展示综合案例
    13 JSP、MVC开发模式、EL表达式和JSPL标签+软件设计架构---学习笔记
    12 Cookie、Session和JSP基础
    11 Reponse对象+ServletContext对象
    10 Servlet+Http+Request对象
    09 Servlet相关知识点---学习笔记
  • 原文地址:https://www.cnblogs.com/ccxniit2004/p/2314266.html
Copyright © 2011-2022 走看看