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
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
|
package course.labs.activitylab.test;
import course.labs.activitylab.ActivityOne;
import com.robotium.solo.*;
import android.test.ActivityInstrumentationTestCase2;
public class Test2 extends ActivityInstrumentationTestCase2<ActivityOne> {
private Solo solo;
public Test2() {
super(ActivityOne.class);
}
public void setUp() throws Exception {
solo = new Solo(getInstrumentation());
getActivity();
}
@Override
public void tearDown() throws Exception {
solo.finishOpenedActivities();
}
public void testRun() {
// Wait for activity: 'course.labs.activitylab.ActivityOne'
assertTrue("course.labs.activitylab.ActivityOne is not found!",
solo.waitForActivity(course.labs.activitylab.ActivityOne.class));
// Check for proper counts
assertTrue("onCreate() count was off.",
solo.searchText("onCreate\\(\\) calls: 1"));
assertTrue("onStart() count was off.",
solo.searchText("onStart\\(\\) calls: 1"));
assertTrue("onResume() count was off.",
solo.searchText("onResume\\(\\) calls: 1"));
assertTrue("onRestart() count was off.",
solo.searchText("onRestart\\(\\) calls: 0"));
assertTrue("Log message for 'onCreate()' was not found in Log", solo.waitForLogMessage("onCreate",5));
assertTrue("Log message for 'onStart()' was not found in Log", solo.waitForLogMessage("onStart",5));
assertTrue("Log message for 'onResume()' was not found in Log", solo.waitForLogMessage("onResume",5));
solo.clearLog();
// Click on Start Activity Two
solo.clickOnView(solo
.getView(course.labs.activitylab.R.id.bLaunchActivityTwo));
// Wait for activity: 'course.labs.activitylab.ActivityTwo'
assertTrue("course.labs.activitylab.ActivityTwo is not found!",
solo.waitForActivity(course.labs.activitylab.ActivityTwo.class));
// Check for proper counts
assertTrue("onCreate() count was off.",
solo.searchText("onCreate\\(\\) calls: 1"));
assertTrue("onStart() count was off.",
solo.searchText("onStart\\(\\) calls: 1"));
assertTrue("onResume() count was off.",
solo.searchText("onResume\\(\\) calls: 1"));
assertTrue("onRestart() count was off.",
solo.searchText("onRestart\\(\\) calls: 0"));
assertTrue("Log message for 'onPause()' was not found in the Log", solo.waitForLogMessage("onPause",5));
assertTrue("Log message for 'onCreate()' was not found in the Log", solo.waitForLogMessage("onCreate",5));
assertTrue("Log message for 'onStart()' was not found in the Log", solo.waitForLogMessage("onStart",5));
assertTrue("Log message for 'onResume()' was not found in the Log", solo.waitForLogMessage("onResume",5));
solo.clearLog();
// Rotate the screen
solo.setActivityOrientation(Solo.LANDSCAPE);
// Wait for activity: 'course.labs.activitylab.ActivityTwo'
assertTrue("course.labs.activitylab.ActivityTwo is not found!",
solo.waitForActivity(course.labs.activitylab.ActivityTwo.class));
// Check for proper counts
assertTrue("onCreate() count was off.",
solo.searchText("onCreate\\(\\) calls: 2"));
assertTrue("onStart() count was off.",
solo.searchText("onStart\\(\\) calls: 2"));
assertTrue("onResume() count was off.",
solo.searchText("onResume\\(\\) calls: 2"));
assertTrue("onRestart() count was off.",
solo.searchText("onRestart\\(\\) calls: 0"));
assertTrue("Log message for 'onPause()' was not found in the Log", solo.waitForLogMessage("onPause",5));
assertTrue("Log message for 'onCreate()' was not found in the Log", solo.waitForLogMessage("onCreate",5));
assertTrue("Log message for 'onStart()' was not found in the Log", solo.waitForLogMessage("onStart",5));
assertTrue("Log message for 'onResume()' was not found in the Log", solo.waitForLogMessage("onResume",5));
solo.clearLog();
// Rotate the screen
solo.setActivityOrientation(Solo.PORTRAIT);
// Wait for activity: 'course.labs.activitylab.ActivityTwo'
assertTrue("course.labs.activitylab.ActivityTwo is not found!",
solo.waitForActivity(course.labs.activitylab.ActivityTwo.class));
// Check for proper counts
assertTrue("onCreate() count was off.",
solo.searchText("onCreate\\(\\) calls: 3"));
assertTrue("onStart() count was off.",
solo.searchText("onStart\\(\\) calls: 3"));
assertTrue("onResume() count was off.",
solo.searchText("onResume\\(\\) calls: 3"));
assertTrue("onRestart() count was off.",
solo.searchText("onRestart\\(\\) calls: 0"));
assertTrue("Log message for 'onPause()' was not found in the Log", solo.waitForLogMessage("onPause",5));
assertTrue("Log message for 'onCreate()' was not found in the Log", solo.waitForLogMessage("onCreate",5));
assertTrue("Log message for 'onStart()' was not found in the Log", solo.waitForLogMessage("onStart",5));
assertTrue("Log message for 'onResume()' was not found in the Log", solo.waitForLogMessage("onResume",5));
}
}
|