|
@@ -1,42 +1,13 @@
|
1
|
1
|
package com.reactnativenavigation.e2e.androide2e;
|
2
|
2
|
|
3
|
|
-import android.support.test.runner.AndroidJUnit4;
|
4
|
3
|
import android.support.test.uiautomator.By;
|
5
|
|
-import android.support.test.uiautomator.BySelector;
|
6
|
|
-import android.support.test.uiautomator.UiDevice;
|
7
|
|
-import android.support.test.uiautomator.UiObject;
|
8
|
|
-import android.support.test.uiautomator.UiObjectNotFoundException;
|
9
|
|
-import android.support.test.uiautomator.UiScrollable;
|
10
|
|
-import android.support.test.uiautomator.UiSelector;
|
11
|
|
-import android.support.test.uiautomator.Until;
|
12
|
|
-
|
13
|
|
-import org.junit.After;
|
14
|
|
-import org.junit.Before;
|
|
4
|
+
|
15
|
5
|
import org.junit.FixMethodOrder;
|
16
|
6
|
import org.junit.Test;
|
17
|
|
-import org.junit.runner.RunWith;
|
18
|
7
|
import org.junit.runners.MethodSorters;
|
19
|
8
|
|
20
|
|
-import static android.support.test.InstrumentationRegistry.getInstrumentation;
|
21
|
|
-import static org.assertj.core.api.Java6Assertions.assertThat;
|
22
|
|
-
|
23
|
|
-@RunWith(AndroidJUnit4.class)
|
24
|
9
|
@FixMethodOrder(MethodSorters.NAME_ASCENDING)
|
25
|
|
-public class ApplicationLifecycleTest {
|
26
|
|
-
|
27
|
|
- private static final String PACKAGE_NAME = "com.reactnativenavigation.playground";
|
28
|
|
- private static final long TIMEOUT = 3000;
|
29
|
|
-
|
30
|
|
- @Before
|
31
|
|
- public void beforeEach() throws Exception {
|
32
|
|
- uiDevice().wakeUp();
|
33
|
|
- uiDevice().setOrientationNatural();
|
34
|
|
- }
|
35
|
|
-
|
36
|
|
- @After
|
37
|
|
- public void afterEach() throws Exception {
|
38
|
|
- uiDevice().executeShellCommand("am force-stop " + PACKAGE_NAME);
|
39
|
|
- }
|
|
10
|
+public class ApplicationLifecycleTest extends BaseTest {
|
40
|
11
|
|
41
|
12
|
@Test
|
42
|
13
|
public void _1_acceptsOverlayPermissions_ShowsWelcomeScreen() throws Exception {
|
|
@@ -48,23 +19,23 @@ public class ApplicationLifecycleTest {
|
48
|
19
|
public void _2_relaunchFromBackground() throws Exception {
|
49
|
20
|
launchTheApp();
|
50
|
21
|
assertMainShown();
|
51
|
|
- push();
|
52
|
|
- assertPushedScreenShown();
|
|
22
|
+ elementByText("PUSH").click();
|
|
23
|
+ assertExists(By.text("Pushed Screen"));
|
53
|
24
|
|
54
|
|
- uiDevice().pressHome();
|
55
|
|
- uiDevice().pressRecentApps();
|
|
25
|
+ device().pressHome();
|
|
26
|
+ device().pressRecentApps();
|
56
|
27
|
elementByText("Playground").click();
|
57
|
28
|
|
58
|
|
- assertPushedScreenShown();
|
|
29
|
+ assertExists(By.text("Pushed Screen"));
|
59
|
30
|
}
|
60
|
31
|
|
61
|
32
|
@Test
|
62
|
33
|
public void _3_relaunchAfterClose() throws Exception {
|
63
|
34
|
launchTheApp();
|
64
|
|
- push();
|
65
|
|
- assertPushedScreenShown();
|
|
35
|
+ elementByText("PUSH").click();
|
|
36
|
+ assertExists(By.text("Pushed Screen"));
|
66
|
37
|
|
67
|
|
- uiDevice().pressBack();
|
|
38
|
+ device().pressBack();
|
68
|
39
|
|
69
|
40
|
launchTheApp();
|
70
|
41
|
assertMainShown();
|
|
@@ -73,74 +44,31 @@ public class ApplicationLifecycleTest {
|
73
|
44
|
@Test
|
74
|
45
|
public void _4_deviceOrientationDoesNotDestroyActivity() throws Exception {
|
75
|
46
|
launchTheApp();
|
76
|
|
- push();
|
77
|
|
- assertPushedScreenShown();
|
|
47
|
+ elementByText("PUSH").click();
|
|
48
|
+ assertExists(By.text("Pushed Screen"));
|
78
|
49
|
|
79
|
|
- uiDevice().setOrientationLeft();
|
|
50
|
+ device().setOrientationLeft();
|
80
|
51
|
Thread.sleep(100);
|
81
|
52
|
|
82
|
|
- assertPushedScreenShown();
|
|
53
|
+ assertExists(By.text("Pushed Screen"));
|
83
|
54
|
}
|
84
|
55
|
|
85
|
56
|
@Test
|
86
|
57
|
public void _5_relaunchAfterActivityKilledBySystem() throws Exception {
|
87
|
58
|
launchTheApp();
|
88
|
|
- push();
|
89
|
|
- assertPushedScreenShown();
|
|
59
|
+ elementByText("PUSH").click();
|
|
60
|
+ assertExists(By.text("Pushed Screen"));
|
90
|
61
|
|
91
|
|
- uiDevice().pressHome();
|
92
|
|
- uiDevice().waitForIdle();
|
93
|
|
- uiDevice().executeShellCommand("am kill " + PACKAGE_NAME);
|
|
62
|
+ device().pressHome();
|
|
63
|
+ device().waitForIdle();
|
|
64
|
+ device().executeShellCommand("am kill " + PACKAGE_NAME);
|
94
|
65
|
|
95
|
|
- uiDevice().pressRecentApps();
|
|
66
|
+ device().pressRecentApps();
|
96
|
67
|
elementByText("Playground").click();
|
97
|
68
|
assertMainShown();
|
98
|
69
|
}
|
99
|
70
|
|
100
|
|
- private void push() throws UiObjectNotFoundException {
|
101
|
|
- elementByText("PUSH").click();
|
102
|
|
- }
|
103
|
|
-
|
104
|
71
|
private void assertMainShown() {
|
105
|
72
|
assertExists(By.text("React Native Navigation!"));
|
106
|
73
|
}
|
107
|
|
-
|
108
|
|
- private void launchTheApp() throws Exception {
|
109
|
|
- uiDevice().executeShellCommand("am start -n " + PACKAGE_NAME + "/.MainActivity");
|
110
|
|
- uiDevice().waitForIdle();
|
111
|
|
- acceptOverlayPermissionIfNeeded();
|
112
|
|
- uiDevice().wait(Until.gone(By.textContains("Please wait")), 1000 * 60 * 3);
|
113
|
|
- }
|
114
|
|
-
|
115
|
|
- private void acceptOverlayPermissionIfNeeded() throws Exception {
|
116
|
|
- if (elementByText("Draw over other apps").exists()) {
|
117
|
|
- if (!elementByText("Playground").exists()) {
|
118
|
|
- scrollToText("Playground");
|
119
|
|
- }
|
120
|
|
- elementByText("Playground").click();
|
121
|
|
- elementByText("Permit drawing over other apps").click();
|
122
|
|
- uiDevice().pressBack();
|
123
|
|
- uiDevice().pressBack();
|
124
|
|
- }
|
125
|
|
- }
|
126
|
|
-
|
127
|
|
- private UiDevice uiDevice() {
|
128
|
|
- return UiDevice.getInstance(getInstrumentation());
|
129
|
|
- }
|
130
|
|
-
|
131
|
|
- private UiObject elementByText(String text) {
|
132
|
|
- return uiDevice().findObject(new UiSelector().text(text));
|
133
|
|
- }
|
134
|
|
-
|
135
|
|
- private void scrollToText(String txt) throws Exception {
|
136
|
|
- new UiScrollable(new UiSelector().scrollable(true)).scrollTextIntoView(txt);
|
137
|
|
- }
|
138
|
|
-
|
139
|
|
- private void assertExists(BySelector selector) {
|
140
|
|
- assertThat(uiDevice().wait(Until.hasObject(selector), TIMEOUT)).isTrue();
|
141
|
|
- }
|
142
|
|
-
|
143
|
|
- private void assertPushedScreenShown() {
|
144
|
|
- assertExists(By.text("Pushed Screen"));
|
145
|
|
- }
|
146
|
74
|
}
|