1. 程式人生 > >Robotium環境搭建與新手入門教程

Robotium環境搭建與新手入門教程

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
package com.example.android.notepad.test;
 
import android.test.ActivityInstrumentationTestCase2;
 
import com.example.android.notepad.NotesList;
import
com.jayway.android.robotium.solo.Solo;   public class NotePadTest extends ActivityInstrumentationTestCase2 { private Solo solo;//宣告Solo public NotePadTest()//構造方法 { super(NotesList.class);   }   @Override public void setUp() throws Exception { solo = new Solo(getInstrumentation(), getActivity(
)); }   @Override public void tearDown() throws Exception { solo.finishOpenedActivities(); }   public void testAddNote() throws Exception { //點選add note按鈕 solo.clickOnMenuItem("Add note"); //比對結果 solo.assertCurrentActivity("Expected NoteEditor activity", "NoteEditor"); //在第一個TextEdit控制元件上輸入內容
solo.enterText(0, "Note 1"); //返回上個介面 solo.goBack(); //點選選單中的Add note solo.clickOnMenuItem("Add note"); //在第一個EditText中輸入內容 solo.enterText(0, "Note 2"); //返回NotesList activity solo.goBackToActivity("NotesList"); //截圖 solo.takeScreenshot(); 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);   }   }