|
@@ -24,123 +24,123 @@ import static org.assertj.core.api.Java6Assertions.assertThat;
|
24
|
24
|
@FixMethodOrder(MethodSorters.NAME_ASCENDING)
|
25
|
25
|
public class ApplicationLifecycleTest {
|
26
|
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
|
|
- }
|
40
|
|
-
|
41
|
|
- @Test
|
42
|
|
- public void _1_acceptsOverlayPermissions_ShowsWelcomeScreen() throws Exception {
|
43
|
|
- launchTheApp();
|
44
|
|
- assertMainShown();
|
45
|
|
- }
|
46
|
|
-
|
47
|
|
- @Test
|
48
|
|
- public void _2_relaunchFromBackground() throws Exception {
|
49
|
|
- launchTheApp();
|
50
|
|
- assertMainShown();
|
51
|
|
- push();
|
52
|
|
- assertPushedScreenShown();
|
53
|
|
-
|
54
|
|
- uiDevice().pressHome();
|
55
|
|
- uiDevice().pressRecentApps();
|
56
|
|
- elementByText("Playground").click();
|
57
|
|
-
|
58
|
|
- assertPushedScreenShown();
|
59
|
|
- }
|
60
|
|
-
|
61
|
|
- @Test
|
62
|
|
- public void _3_relaunchAfterClose() throws Exception {
|
63
|
|
- launchTheApp();
|
64
|
|
- push();
|
65
|
|
- assertPushedScreenShown();
|
66
|
|
-
|
67
|
|
- uiDevice().pressBack();
|
68
|
|
-
|
69
|
|
- launchTheApp();
|
70
|
|
- assertMainShown();
|
71
|
|
- }
|
72
|
|
-
|
73
|
|
- @Test
|
74
|
|
- public void _4_deviceOrientationDoesNotDestroyActivity() throws Exception {
|
75
|
|
- launchTheApp();
|
76
|
|
- push();
|
77
|
|
- assertPushedScreenShown();
|
78
|
|
-
|
79
|
|
- uiDevice().setOrientationLeft();
|
80
|
|
- Thread.sleep(100);
|
81
|
|
-
|
82
|
|
- assertPushedScreenShown();
|
83
|
|
- }
|
84
|
|
-
|
85
|
|
- @Test
|
86
|
|
- public void _5_relaunchAfterActivityKilledBySystem() throws Exception {
|
87
|
|
- launchTheApp();
|
88
|
|
- push();
|
89
|
|
- assertPushedScreenShown();
|
90
|
|
-
|
91
|
|
- uiDevice().pressHome();
|
92
|
|
- uiDevice().waitForIdle();
|
93
|
|
- uiDevice().executeShellCommand("am kill " + PACKAGE_NAME);
|
94
|
|
-
|
95
|
|
- uiDevice().pressRecentApps();
|
96
|
|
- elementByText("Playground").click();
|
97
|
|
- assertMainShown();
|
98
|
|
- }
|
99
|
|
-
|
100
|
|
- private void push() throws UiObjectNotFoundException {
|
101
|
|
- elementByText("PUSH").click();
|
102
|
|
- }
|
103
|
|
-
|
104
|
|
- private void assertMainShown() {
|
105
|
|
- assertExists(By.text("React Native Navigation!"));
|
106
|
|
- }
|
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
|
|
- }
|
|
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
|
+ }
|
|
40
|
+
|
|
41
|
+ @Test
|
|
42
|
+ public void _1_acceptsOverlayPermissions_ShowsWelcomeScreen() throws Exception {
|
|
43
|
+ launchTheApp();
|
|
44
|
+ assertMainShown();
|
|
45
|
+ }
|
|
46
|
+
|
|
47
|
+ @Test
|
|
48
|
+ public void _2_relaunchFromBackground() throws Exception {
|
|
49
|
+ launchTheApp();
|
|
50
|
+ assertMainShown();
|
|
51
|
+ push();
|
|
52
|
+ assertPushedScreenShown();
|
|
53
|
+
|
|
54
|
+ uiDevice().pressHome();
|
|
55
|
+ uiDevice().pressRecentApps();
|
|
56
|
+ elementByText("Playground").click();
|
|
57
|
+
|
|
58
|
+ assertPushedScreenShown();
|
|
59
|
+ }
|
|
60
|
+
|
|
61
|
+ @Test
|
|
62
|
+ public void _3_relaunchAfterClose() throws Exception {
|
|
63
|
+ launchTheApp();
|
|
64
|
+ push();
|
|
65
|
+ assertPushedScreenShown();
|
|
66
|
+
|
|
67
|
+ uiDevice().pressBack();
|
|
68
|
+
|
|
69
|
+ launchTheApp();
|
|
70
|
+ assertMainShown();
|
|
71
|
+ }
|
|
72
|
+
|
|
73
|
+ @Test
|
|
74
|
+ public void _4_deviceOrientationDoesNotDestroyActivity() throws Exception {
|
|
75
|
+ launchTheApp();
|
|
76
|
+ push();
|
|
77
|
+ assertPushedScreenShown();
|
|
78
|
+
|
|
79
|
+ uiDevice().setOrientationLeft();
|
|
80
|
+ Thread.sleep(100);
|
|
81
|
+
|
|
82
|
+ assertPushedScreenShown();
|
|
83
|
+ }
|
|
84
|
+
|
|
85
|
+ @Test
|
|
86
|
+ public void _5_relaunchAfterActivityKilledBySystem() throws Exception {
|
|
87
|
+ launchTheApp();
|
|
88
|
+ push();
|
|
89
|
+ assertPushedScreenShown();
|
|
90
|
+
|
|
91
|
+ uiDevice().pressHome();
|
|
92
|
+ uiDevice().waitForIdle();
|
|
93
|
+ uiDevice().executeShellCommand("am kill " + PACKAGE_NAME);
|
|
94
|
+
|
|
95
|
+ uiDevice().pressRecentApps();
|
|
96
|
+ elementByText("Playground").click();
|
|
97
|
+ assertMainShown();
|
|
98
|
+ }
|
|
99
|
+
|
|
100
|
+ private void push() throws UiObjectNotFoundException {
|
|
101
|
+ elementByText("PUSH").click();
|
|
102
|
+ }
|
|
103
|
+
|
|
104
|
+ private void assertMainShown() {
|
|
105
|
+ assertExists(By.text("React Native Navigation!"));
|
|
106
|
+ }
|
|
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
|
146
|
}
|