|
@@ -1,9 +1,13 @@
|
1
|
1
|
package com.reactnativenavigation.e2e.androide2e;
|
2
|
2
|
|
3
|
3
|
import android.support.test.runner.AndroidJUnit4;
|
|
4
|
+import android.support.test.uiautomator.By;
|
|
5
|
+import android.support.test.uiautomator.BySelector;
|
4
|
6
|
import android.support.test.uiautomator.UiDevice;
|
|
7
|
+import android.support.test.uiautomator.UiObject;
|
5
|
8
|
import android.support.test.uiautomator.UiScrollable;
|
6
|
9
|
import android.support.test.uiautomator.UiSelector;
|
|
10
|
+import android.support.test.uiautomator.Until;
|
7
|
11
|
|
8
|
12
|
import org.junit.After;
|
9
|
13
|
import org.junit.Before;
|
|
@@ -18,11 +22,11 @@ import static android.support.test.InstrumentationRegistry.getInstrumentation;
|
18
|
22
|
import static org.assertj.core.api.Java6Assertions.assertThat;
|
19
|
23
|
|
20
|
24
|
@RunWith(AndroidJUnit4.class)
|
21
|
|
-@FixMethodOrder(value = MethodSorters.NAME_ASCENDING)
|
|
25
|
+@FixMethodOrder(MethodSorters.NAME_ASCENDING)
|
22
|
26
|
public class ApplicationLifecycleTest {
|
23
|
27
|
|
24
|
28
|
private static final String PACKAGE_NAME = "com.reactnativenavigation.playground";
|
25
|
|
- private static final int TIMEOUT = 2000;
|
|
29
|
+ private static final long TIMEOUT = 3000;
|
26
|
30
|
|
27
|
31
|
@Before
|
28
|
32
|
public void beforeEach() {
|
|
@@ -38,7 +42,6 @@ public class ApplicationLifecycleTest {
|
38
|
42
|
public void _1_showSplash_AcceptsOverlayPermissions_ShowsWelcomeScreen() throws Exception {
|
39
|
43
|
launchTheApp();
|
40
|
44
|
// assertThat(uiDevice().wait(Until.hasObject(By.desc("NavigationSplashView")), TIMEOUT)).isTrue();
|
41
|
|
- acceptOverlayPermissionIfNeeded();
|
42
|
45
|
assertMainShown();
|
43
|
46
|
}
|
44
|
47
|
|
|
@@ -49,7 +52,7 @@ public class ApplicationLifecycleTest {
|
49
|
52
|
|
50
|
53
|
uiDevice().pressHome();
|
51
|
54
|
uiDevice().pressRecentApps();
|
52
|
|
- uiDevice().findObject(new UiSelector().text("Playground")).click();
|
|
55
|
+ elementByText("Playground").click();
|
53
|
56
|
assertMainShown();
|
54
|
57
|
}
|
55
|
58
|
|
|
@@ -64,14 +67,31 @@ public class ApplicationLifecycleTest {
|
64
|
67
|
assertMainShown();
|
65
|
68
|
}
|
66
|
69
|
|
|
70
|
+ @Test
|
|
71
|
+ public void _4_deviceOrientationDoesNotDestroyActivity() throws Exception {
|
|
72
|
+ launchTheApp();
|
|
73
|
+ assertMainShown();
|
|
74
|
+
|
|
75
|
+ elementByText("PUSH").click();
|
|
76
|
+ assertExists(By.text("Pushed screen"));
|
|
77
|
+
|
|
78
|
+ uiDevice().setOrientationLeft();
|
|
79
|
+ Thread.sleep(100);
|
|
80
|
+
|
|
81
|
+ assertExists(By.text("Pushed screen"));
|
|
82
|
+ }
|
|
83
|
+
|
67
|
84
|
private void assertMainShown() {
|
68
|
|
- assertThat(uiDevice().findObject(new UiSelector().text("React Native Navigation!")).exists()).isTrue();
|
|
85
|
+ assertExists(By.text("React Native Navigation!"));
|
69
|
86
|
}
|
70
|
87
|
|
71
|
88
|
private void acceptOverlayPermissionIfNeeded() throws Exception {
|
72
|
|
- if (uiDevice().findObject(new UiSelector().text("Draw over other apps")).exists()) {
|
73
|
|
- uiDevice().findObject(new UiSelector().text("Playground")).click();
|
74
|
|
- uiDevice().findObject(new UiSelector().text("Permit drawing over other apps")).click();
|
|
89
|
+ if (elementByText("Draw over other apps").exists()) {
|
|
90
|
+ if (!elementByText("Playground").exists()) {
|
|
91
|
+ scrollToText("Playground");
|
|
92
|
+ }
|
|
93
|
+ elementByText("Playground").click();
|
|
94
|
+ elementByText("Permit drawing over other apps").click();
|
75
|
95
|
uiDevice().pressBack();
|
76
|
96
|
uiDevice().pressBack();
|
77
|
97
|
}
|
|
@@ -80,13 +100,29 @@ public class ApplicationLifecycleTest {
|
80
|
100
|
private void launchTheApp() throws Exception {
|
81
|
101
|
uiDevice().wakeUp();
|
82
|
102
|
uiDevice().pressHome();
|
83
|
|
- uiDevice().findObject(new UiSelector().description("Apps")).clickAndWaitForNewWindow();
|
84
|
|
- new UiScrollable(new UiSelector().scrollable(true)).scrollTextIntoView("Playground");
|
85
|
|
- uiDevice().findObject(new UiSelector().text("Playground")).clickAndWaitForNewWindow();
|
|
103
|
+ elementByDesc("Apps").clickAndWaitForNewWindow();
|
|
104
|
+ scrollToText("Playground");
|
|
105
|
+ elementByText("Playground").clickAndWaitForNewWindow();
|
|
106
|
+ acceptOverlayPermissionIfNeeded();
|
86
|
107
|
}
|
87
|
108
|
|
88
|
109
|
private UiDevice uiDevice() {
|
89
|
110
|
return UiDevice.getInstance(getInstrumentation());
|
90
|
111
|
}
|
91
|
112
|
|
|
113
|
+ private UiObject elementByText(String text) {
|
|
114
|
+ return uiDevice().findObject(new UiSelector().text(text));
|
|
115
|
+ }
|
|
116
|
+
|
|
117
|
+ private UiObject elementByDesc(String text) {
|
|
118
|
+ return uiDevice().findObject(new UiSelector().description(text));
|
|
119
|
+ }
|
|
120
|
+
|
|
121
|
+ private void scrollToText(String txt) throws Exception {
|
|
122
|
+ new UiScrollable(new UiSelector().scrollable(true)).scrollTextIntoView(txt);
|
|
123
|
+ }
|
|
124
|
+
|
|
125
|
+ private void assertExists(BySelector selector) {
|
|
126
|
+ assertThat(uiDevice().wait(Until.hasObject(selector), TIMEOUT)).isTrue();
|
|
127
|
+ }
|
92
|
128
|
}
|