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();
       }

  • 相关阅读:
    hdu 3790 最短路径问题
    hdu 2112 HDU Today
    最短路问题 以hdu1874为例
    hdu 1690 Bus System Floyd
    hdu 2066 一个人的旅行
    hdu 2680 Choose the best route
    hdu 1596 find the safest road
    hdu 1869 六度分离
    hdu 3339 In Action
    序列化和反序列化
  • 原文地址:https://www.cnblogs.com/ccxniit2004/p/2314266.html
Copyright © 2011-2022 走看看