|
@@ -1,13 +1,18 @@
|
1
|
1
|
package com.reactnativenavigation.e2e.androide2e;
|
2
|
2
|
|
3
|
3
|
import android.annotation.TargetApi;
|
|
4
|
+import android.app.Instrumentation;
|
4
|
5
|
import android.content.Intent;
|
|
6
|
+import android.provider.Settings;
|
5
|
7
|
import android.support.test.filters.SdkSuppress;
|
6
|
8
|
import android.support.test.runner.AndroidJUnit4;
|
7
|
9
|
import android.support.test.uiautomator.By;
|
8
|
10
|
import android.support.test.uiautomator.UiDevice;
|
|
11
|
+import android.support.test.uiautomator.UiSelector;
|
9
|
12
|
import android.support.test.uiautomator.Until;
|
10
|
13
|
|
|
14
|
+import org.junit.After;
|
|
15
|
+import org.junit.Before;
|
11
|
16
|
import org.junit.Test;
|
12
|
17
|
import org.junit.runner.RunWith;
|
13
|
18
|
|
|
@@ -19,37 +24,58 @@ import static org.assertj.core.api.Java6Assertions.assertThat;
|
19
|
24
|
@TargetApi(23)
|
20
|
25
|
public class ApplicationLifecycleTest {
|
21
|
26
|
|
22
|
|
- public static final String PACKAGE_NAME = "com.reactnativenavigation.playground";
|
|
27
|
+ private static final String PACKAGE_NAME = "com.reactnativenavigation.playground";
|
|
28
|
+ private static final int TIMEOUT = 10000;
|
|
29
|
+ private Instrumentation.ActivityMonitor activityMonitor;
|
|
30
|
+
|
|
31
|
+ @Before
|
|
32
|
+ public void beforeEach() {
|
|
33
|
+ activityMonitor = new Instrumentation.ActivityMonitor("com.reactnativenavigation.playground.MainActivity", null, false);
|
|
34
|
+ getInstrumentation().addMonitor(activityMonitor);
|
|
35
|
+ }
|
|
36
|
+
|
|
37
|
+ @After
|
|
38
|
+ public void afterEach() {
|
|
39
|
+ getInstrumentation().removeMonitor(activityMonitor);
|
|
40
|
+ }
|
23
|
41
|
|
24
|
42
|
@Test
|
25
|
43
|
public void showSplash_AcceptsOverlayPermissions_ShowsWelcomeScreen() throws Exception {
|
26
|
44
|
launchTheApp();
|
|
45
|
+ assertThat(uiDevice().wait(Until.hasObject(By.desc("NavigationSplashView")), TIMEOUT)).isTrue();
|
27
|
46
|
|
28
|
|
-// assertThat(rule.getActivity().getContentView()).isNotNull().isInstanceOf(NavigationSplashView.class);
|
|
47
|
+// UiObject2 o = uiDevice().findObject(By.desc("NavigationSplashView"));
|
|
48
|
+// assertThat(uiDevice().wait(Until.hasObject(By.clazz("com.reactnativenavigation.views.NavigationSplashView")), TIMEOUT)).isTrue();
|
|
49
|
+// assertThat(activityMonitor.waitForActivity()).isNotNull();
|
|
50
|
+// activity = activityMonitor.getLastActivity();
|
|
51
|
+// uiDevice().wait(Until.hasObject(By.clazz("com.reactnativenavigation.views.NavigationSplashView")), TIMEOUT);
|
29
|
52
|
// acceptOverlayPermissionIfNeeded();
|
|
53
|
+
|
|
54
|
+// assertThat(uiDevice().findObject(new UiSelector().className("com.reactnativenavigation.views.NavigationSplashView")).exists()).isTrue();
|
|
55
|
+// assertThat(rule.getActivity().getContentView()).isNotNull().isInstanceOf(NavigationSplashView.class);
|
30
|
56
|
// assertMainShown();
|
31
|
57
|
}
|
32
|
58
|
|
33
|
|
-// private void acceptOverlayPermissionIfNeeded() throws Exception {
|
34
|
|
-// if (Settings.canDrawOverlays(getInstrumentation().getTargetContext())) {
|
35
|
|
-// return;
|
36
|
|
-// }
|
37
|
|
-// uiDevice().waitForIdle();
|
38
|
|
-// uiDevice().findObject(new UiSelector().text("Playground")).click();
|
39
|
|
-// uiDevice().findObject(new UiSelector().text("Permit drawing over other apps")).click();
|
40
|
|
-// uiDevice().pressBack();
|
41
|
|
-// uiDevice().pressBack();
|
42
|
|
-// }
|
|
59
|
+ private void acceptOverlayPermissionIfNeeded() throws Exception {
|
|
60
|
+ if (Settings.canDrawOverlays(activityMonitor.getLastActivity())) {
|
|
61
|
+ return;
|
|
62
|
+ }
|
|
63
|
+ uiDevice().waitForIdle();
|
|
64
|
+ uiDevice().findObject(new UiSelector().text("Playground")).click();
|
|
65
|
+ uiDevice().findObject(new UiSelector().text("Permit drawing over other apps")).click();
|
|
66
|
+ uiDevice().pressBack();
|
|
67
|
+ uiDevice().pressBack();
|
|
68
|
+ }
|
43
|
69
|
// uiDevice().findObject(new UiSelector().description("Apps")).clickAndWaitForNewWindow();
|
44
|
70
|
|
45
|
71
|
private void launchTheApp() throws Exception {
|
46
|
72
|
uiDevice().wakeUp();
|
47
|
73
|
uiDevice().pressHome();
|
48
|
74
|
uiDevice().waitForIdle();
|
49
|
|
- Intent intent = getInstrumentation().getTargetContext().getPackageManager().getLaunchIntentForPackage(PACKAGE_NAME);
|
|
75
|
+ Intent intent = getInstrumentation().getContext().getPackageManager().getLaunchIntentForPackage(PACKAGE_NAME);
|
50
|
76
|
assertThat(intent).isNotNull();
|
51
|
|
- getInstrumentation().getTargetContext().startActivity(intent);
|
52
|
|
- uiDevice().wait(Until.hasObject(By.pkg("com.reactnativenavigation.playground").depth(0)), 5000);
|
|
77
|
+ getInstrumentation().getContext().startActivity(intent);
|
|
78
|
+ uiDevice().wait(Until.hasObject(By.pkg(PACKAGE_NAME).depth(0)), TIMEOUT);
|
53
|
79
|
}
|
54
|
80
|
|
55
|
81
|
private UiDevice uiDevice() {
|