|
@@ -5,6 +5,7 @@ import android.support.test.uiautomator.By;
|
5
|
5
|
import android.support.test.uiautomator.BySelector;
|
6
|
6
|
import android.support.test.uiautomator.UiDevice;
|
7
|
7
|
import android.support.test.uiautomator.UiObject;
|
|
8
|
+import android.support.test.uiautomator.UiObjectNotFoundException;
|
8
|
9
|
import android.support.test.uiautomator.UiScrollable;
|
9
|
10
|
import android.support.test.uiautomator.UiSelector;
|
10
|
11
|
import android.support.test.uiautomator.Until;
|
|
@@ -48,18 +49,21 @@ public class ApplicationLifecycleTest {
|
48
|
49
|
public void _2_relaunchFromBackground() throws Exception {
|
49
|
50
|
launchTheApp();
|
50
|
51
|
assertMainShown();
|
|
52
|
+ push();
|
|
53
|
+ assertPushedScreenShown();
|
51
|
54
|
|
52
|
55
|
uiDevice().pressHome();
|
53
|
56
|
uiDevice().pressRecentApps();
|
54
|
57
|
elementByText("Playground").click();
|
55
|
58
|
|
56
|
|
- assertMainShown();
|
|
59
|
+ assertPushedScreenShown();
|
57
|
60
|
}
|
58
|
61
|
|
59
|
62
|
@Test
|
60
|
63
|
public void _3_relaunchAfterClose() throws Exception {
|
61
|
64
|
launchTheApp();
|
62
|
|
- assertMainShown();
|
|
65
|
+ push();
|
|
66
|
+ assertPushedScreenShown();
|
63
|
67
|
|
64
|
68
|
uiDevice().pressBack();
|
65
|
69
|
|
|
@@ -70,20 +74,20 @@ public class ApplicationLifecycleTest {
|
70
|
74
|
@Test
|
71
|
75
|
public void _4_deviceOrientationDoesNotDestroyActivity() throws Exception {
|
72
|
76
|
launchTheApp();
|
73
|
|
- assertMainShown();
|
74
|
|
- elementByText("PUSH").click();
|
75
|
|
- assertExists(By.text("Pushed screen"));
|
|
77
|
+ push();
|
|
78
|
+ assertPushedScreenShown();
|
76
|
79
|
|
77
|
80
|
uiDevice().setOrientationLeft();
|
78
|
81
|
Thread.sleep(100);
|
79
|
82
|
|
80
|
|
- assertExists(By.text("Pushed screen"));
|
|
83
|
+ assertPushedScreenShown();
|
81
|
84
|
}
|
82
|
85
|
|
83
|
86
|
@Test
|
84
|
87
|
public void _5_relaunchAfterActivityKilledBySystem() throws Exception {
|
85
|
88
|
launchTheApp();
|
86
|
|
- assertMainShown();
|
|
89
|
+ push();
|
|
90
|
+ assertPushedScreenShown();
|
87
|
91
|
|
88
|
92
|
uiDevice().pressHome();
|
89
|
93
|
uiDevice().executeShellCommand("am kill " + PACKAGE_NAME);
|
|
@@ -93,10 +97,20 @@ public class ApplicationLifecycleTest {
|
93
|
97
|
assertMainShown();
|
94
|
98
|
}
|
95
|
99
|
|
|
100
|
+ private void push() throws UiObjectNotFoundException {
|
|
101
|
+ elementByText("PUSH").click();
|
|
102
|
+ }
|
|
103
|
+
|
96
|
104
|
private void assertMainShown() {
|
97
|
105
|
assertExists(By.text("React Native Navigation!"));
|
98
|
106
|
}
|
99
|
107
|
|
|
108
|
+ private void launchTheApp() throws Exception {
|
|
109
|
+ uiDevice().executeShellCommand("am start -n " + PACKAGE_NAME + "/.MainActivity");
|
|
110
|
+ uiDevice().waitForIdle();
|
|
111
|
+ acceptOverlayPermissionIfNeeded();
|
|
112
|
+ }
|
|
113
|
+
|
100
|
114
|
private void acceptOverlayPermissionIfNeeded() throws Exception {
|
101
|
115
|
if (elementByText("Draw over other apps").exists()) {
|
102
|
116
|
if (!elementByText("Playground").exists()) {
|
|
@@ -109,12 +123,6 @@ public class ApplicationLifecycleTest {
|
109
|
123
|
}
|
110
|
124
|
}
|
111
|
125
|
|
112
|
|
- private void launchTheApp() throws Exception {
|
113
|
|
- uiDevice().executeShellCommand("am start -n " + PACKAGE_NAME + "/.MainActivity");
|
114
|
|
- uiDevice().waitForIdle();
|
115
|
|
- acceptOverlayPermissionIfNeeded();
|
116
|
|
- }
|
117
|
|
-
|
118
|
126
|
private UiDevice uiDevice() {
|
119
|
127
|
return UiDevice.getInstance(getInstrumentation());
|
120
|
128
|
}
|
|
@@ -130,4 +138,8 @@ public class ApplicationLifecycleTest {
|
130
|
138
|
private void assertExists(BySelector selector) {
|
131
|
139
|
assertThat(uiDevice().wait(Until.hasObject(selector), TIMEOUT)).isTrue();
|
132
|
140
|
}
|
|
141
|
+
|
|
142
|
+ private void assertPushedScreenShown() {
|
|
143
|
+ assertExists(By.text("Pushed screen"));
|
|
144
|
+ }
|
133
|
145
|
}
|