Browse Source

breaking e2e

Daniel Zlotin 7 years ago
parent
commit
236ea22927

+ 13
- 30
AndroidE2E/app/src/androidTest/java/com/reactnativenavigation/e2e/androide2e/ApplicationLifecycleTest.java View File

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

+ 0
- 4
AndroidE2E/app/src/androidTest/java/com/reactnativenavigation/e2e/androide2e/EnvironmentTest.java View File

@@ -1,7 +1,5 @@
1 1
 package com.reactnativenavigation.e2e.androide2e;
2 2
 
3
-import android.annotation.TargetApi;
4
-import android.support.test.filters.SdkSuppress;
5 3
 import android.support.test.runner.AndroidJUnit4;
6 4
 
7 5
 import org.junit.Test;
@@ -11,8 +9,6 @@ import static android.support.test.InstrumentationRegistry.getInstrumentation;
11 9
 import static org.assertj.core.api.Java6Assertions.assertThat;
12 10
 
13 11
 @RunWith(AndroidJUnit4.class)
14
-@SdkSuppress(minSdkVersion = 23)
15
-@TargetApi(23)
16 12
 public class EnvironmentTest {
17 13
     @Test
18 14
     public void instrumentationAndAssertJ() throws Exception {

+ 0
- 124
playground/android/app/src/androidTest/java/com/reactnativenavigation/playground/ApplicationLifecycleTest.java View File

@@ -1,124 +0,0 @@
1
-package com.reactnativenavigation.playground;
2
-
3
-import android.annotation.TargetApi;
4
-import android.provider.Settings;
5
-import android.support.test.espresso.Espresso;
6
-import android.support.test.filters.SdkSuppress;
7
-import android.support.test.rule.ActivityTestRule;
8
-import android.support.test.runner.AndroidJUnit4;
9
-import android.support.test.uiautomator.UiDevice;
10
-import android.support.test.uiautomator.UiSelector;
11
-
12
-import com.reactnativenavigation.views.NavigationSplashView;
13
-
14
-import org.junit.After;
15
-import org.junit.Before;
16
-import org.junit.FixMethodOrder;
17
-import org.junit.Rule;
18
-import org.junit.Test;
19
-import org.junit.runner.RunWith;
20
-import org.junit.runners.MethodSorters;
21
-
22
-import static android.support.test.InstrumentationRegistry.getInstrumentation;
23
-import static android.support.test.espresso.Espresso.onView;
24
-import static android.support.test.espresso.assertion.ViewAssertions.matches;
25
-import static android.support.test.espresso.matcher.ViewMatchers.isDisplayed;
26
-import static android.support.test.espresso.matcher.ViewMatchers.withText;
27
-import static org.assertj.core.api.Java6Assertions.assertThat;
28
-
29
-@RunWith(AndroidJUnit4.class)
30
-@FixMethodOrder(value = MethodSorters.NAME_ASCENDING)
31
-@SdkSuppress(minSdkVersion = 23)
32
-@TargetApi(23)
33
-public class ApplicationLifecycleTest {
34
-
35
-    private ReactIdlingResource reactIdlingResource = new ReactIdlingResource();
36
-
37
-    @Rule
38
-    public ActivityTestRule<MainActivity> rule = new ActivityTestRule<>(MainActivity.class, false, false);
39
-
40
-    @Before
41
-    public void beforeEach() throws Exception {
42
-        uiDevice().wakeUp();
43
-        reactIdlingResource.start();
44
-        Espresso.registerIdlingResources(reactIdlingResource);
45
-    }
46
-
47
-    @After
48
-    public void afterEach() {
49
-        reactIdlingResource.stop();
50
-        Espresso.unregisterIdlingResources(reactIdlingResource);
51
-        uiDevice().waitForIdle();
52
-    }
53
-
54
-    @Test
55
-    public void _1_showSplash_AcceptsOverlayPermissions_ShowsWelcomeScreen() throws Exception {
56
-        rule.launchActivity(null);
57
-        assertThat(rule.getActivity().getContentView()).isNotNull().isInstanceOf(NavigationSplashView.class);
58
-        acceptOverlayPermissionIfNeeded();
59
-        assertMainShown();
60
-    }
61
-
62
-    @Test
63
-    public void _2_relaunchFromBackground() throws Exception {
64
-        rule.launchActivity(null);
65
-        acceptOverlayPermissionIfNeeded();
66
-        assertMainShown();
67
-
68
-        uiDevice().pressHome();
69
-        uiDevice().pressRecentApps();
70
-        uiDevice().findObject(new UiSelector().text("Playground")).click();
71
-        uiDevice().waitForIdle();
72
-
73
-        assertMainShown();
74
-    }
75
-
76
-    @Test
77
-    public void _3_relaunchAfterClose() throws Exception {
78
-        rule.launchActivity(null);
79
-        acceptOverlayPermissionIfNeeded();
80
-        assertMainShown();
81
-
82
-        uiDevice().pressBack();
83
-        uiDevice().waitForIdle();
84
-
85
-        rule.launchActivity(null);
86
-        uiDevice().waitForIdle();
87
-
88
-        assertMainShown();
89
-    }
90
-
91
-    @Test
92
-    public void _4_deviceOrientationDoesNotDestroyActivity() throws Exception {
93
-        MainActivity mainActivity = rule.launchActivity(null);
94
-        acceptOverlayPermissionIfNeeded();
95
-        assertMainShown();
96
-
97
-        uiDevice().setOrientationRight();
98
-        uiDevice().waitForIdle();
99
-
100
-        Thread.sleep(5000);
101
-        assertMainShown();
102
-        assertThat(rule.getActivity()).isSameAs(mainActivity);
103
-    }
104
-
105
-    private void assertMainShown() {
106
-        onView(withText("React Native Navigation!")).check(matches(isDisplayed()));
107
-        uiDevice().waitForIdle();
108
-    }
109
-
110
-    private UiDevice uiDevice() {
111
-        return UiDevice.getInstance(getInstrumentation());
112
-    }
113
-
114
-    private void acceptOverlayPermissionIfNeeded() throws Exception {
115
-        if (Settings.canDrawOverlays(getInstrumentation().getContext())) {
116
-            return;
117
-        }
118
-        uiDevice().waitForIdle();
119
-        uiDevice().findObject(new UiSelector().text("Playground")).click();
120
-        uiDevice().findObject(new UiSelector().text("Permit drawing over other apps")).click();
121
-        uiDevice().pressBack();
122
-        uiDevice().pressBack();
123
-    }
124
-}

+ 0
- 82
playground/android/app/src/androidTest/java/com/reactnativenavigation/playground/ReactIdlingResource.java View File

@@ -1,82 +0,0 @@
1
-package com.reactnativenavigation.playground;
2
-
3
-import android.support.test.espresso.IdlingResource;
4
-
5
-import com.facebook.react.ReactNativeHost;
6
-import com.facebook.react.bridge.NotThreadSafeBridgeIdleDebugListener;
7
-import com.reactnativenavigation.NavigationApplication;
8
-import com.reactnativenavigation.utils.UiThread;
9
-
10
-import java.util.concurrent.atomic.AtomicBoolean;
11
-
12
-class ReactIdlingResource implements IdlingResource, NotThreadSafeBridgeIdleDebugListener {
13
-    private ResourceCallback callback;
14
-    private AtomicBoolean registered = new AtomicBoolean(false);
15
-    private AtomicBoolean bridgeIdle = new AtomicBoolean(false);
16
-    private AtomicBoolean shouldRun = new AtomicBoolean(false);
17
-
18
-    ReactIdlingResource() {
19
-    }
20
-
21
-    public void start() {
22
-        shouldRun.set(true);
23
-        UiThread.postDelayed(new Runnable() {
24
-            @Override
25
-            public void run() {
26
-                if (shouldRun.get()) {
27
-                    isIdleNow();
28
-                    UiThread.postDelayed(this, 100);
29
-                }
30
-            }
31
-        }, 100);
32
-    }
33
-
34
-    public void stop() {
35
-        shouldRun.set(false);
36
-        ReactNativeHost host = NavigationApplication.instance.getReactNativeHost();
37
-        if (host != null && host.getReactInstanceManager().getCurrentReactContext() != null)
38
-            host.getReactInstanceManager().getCurrentReactContext().getCatalystInstance().removeBridgeIdleDebugListener(this);
39
-    }
40
-
41
-
42
-    @Override
43
-    public String getName() {
44
-        return "ReactIdlingResource";
45
-    }
46
-
47
-    @Override
48
-    public boolean isIdleNow() {
49
-        ReactNativeHost host = NavigationApplication.instance.getReactNativeHost();
50
-        boolean hasContext = host != null
51
-                && host.getReactInstanceManager() != null
52
-                && host.getReactInstanceManager().getCurrentReactContext() != null;
53
-        if (!hasContext) {
54
-            return false;
55
-        }
56
-
57
-        if (registered.compareAndSet(false, true)) {
58
-            host.getReactInstanceManager().getCurrentReactContext().getCatalystInstance().addBridgeIdleDebugListener(this);
59
-        }
60
-
61
-        boolean idle = bridgeIdle.get();
62
-        if (idle && callback != null) {
63
-            callback.onTransitionToIdle();
64
-        }
65
-        return idle;
66
-    }
67
-
68
-    @Override
69
-    public void registerIdleTransitionCallback(final ResourceCallback callback) {
70
-        this.callback = callback;
71
-    }
72
-
73
-    @Override
74
-    public void onTransitionToBridgeIdle() {
75
-        bridgeIdle.set(true);
76
-    }
77
-
78
-    @Override
79
-    public void onTransitionToBridgeBusy() {
80
-        bridgeIdle.set(false);
81
-    }
82
-}

+ 4
- 0
scripts/test.android.js View File

@@ -6,6 +6,10 @@ function run() {
6 6
   }
7 7
 
8 8
   exec.execSync(`cd android && ./gradlew clean testDebugUnitTest`);
9
+
10
+  if (!process.env.CI) {
11
+    exec.execSync(`cd playground && yarn run e2e-android`);
12
+  }
9 13
 }
10 14
 
11 15
 run();