|  | 
 |  | 
 | 
												
													
														| 1 |  package com.reactnativenavigation.e2e.androide2e;
 | 1 |  package com.reactnativenavigation.e2e.androide2e;
 | 
												
													
														| 2 |  
 | 2 |  
 | 
												
													
														| 3 |  import android.annotation.TargetApi;
 | 3 |  import android.annotation.TargetApi;
 | 
												
													
														|  | 
 | 4 | +import android.app.Instrumentation;
 | 
												
													
														| 4 |  import android.content.Intent;
 | 5 |  import android.content.Intent;
 | 
												
													
														|  | 
 | 6 | +import android.provider.Settings;
 | 
												
													
														| 5 |  import android.support.test.filters.SdkSuppress;
 | 7 |  import android.support.test.filters.SdkSuppress;
 | 
												
													
														| 6 |  import android.support.test.runner.AndroidJUnit4;
 | 8 |  import android.support.test.runner.AndroidJUnit4;
 | 
												
													
														| 7 |  import android.support.test.uiautomator.By;
 | 9 |  import android.support.test.uiautomator.By;
 | 
												
													
														| 8 |  import android.support.test.uiautomator.UiDevice;
 | 10 |  import android.support.test.uiautomator.UiDevice;
 | 
												
													
														|  | 
 | 11 | +import android.support.test.uiautomator.UiSelector;
 | 
												
													
														| 9 |  import android.support.test.uiautomator.Until;
 | 12 |  import android.support.test.uiautomator.Until;
 | 
												
													
														| 10 |  
 | 13 |  
 | 
												
													
														|  | 
 | 14 | +import org.junit.After;
 | 
												
													
														|  | 
 | 15 | +import org.junit.Before;
 | 
												
													
														| 11 |  import org.junit.Test;
 | 16 |  import org.junit.Test;
 | 
												
													
														| 12 |  import org.junit.runner.RunWith;
 | 17 |  import org.junit.runner.RunWith;
 | 
												
													
														| 13 |  
 | 18 |  
 | 
												
											
												
													
														|  | 
 |  | 
 | 
												
													
														| 19 |  @TargetApi(23)
 | 24 |  @TargetApi(23)
 | 
												
													
														| 20 |  public class ApplicationLifecycleTest {
 | 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 |      @Test
 | 42 |      @Test
 | 
												
													
														| 25 |      public void showSplash_AcceptsOverlayPermissions_ShowsWelcomeScreen() throws Exception {
 | 43 |      public void showSplash_AcceptsOverlayPermissions_ShowsWelcomeScreen() throws Exception {
 | 
												
													
														| 26 |          launchTheApp();
 | 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 |  //        acceptOverlayPermissionIfNeeded();
 | 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 |  //        assertMainShown();
 | 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 |  //        uiDevice().findObject(new UiSelector().description("Apps")).clickAndWaitForNewWindow();
 | 69 |  //        uiDevice().findObject(new UiSelector().description("Apps")).clickAndWaitForNewWindow();
 | 
												
													
														| 44 |  
 | 70 |  
 | 
												
													
														| 45 |      private void launchTheApp() throws Exception {
 | 71 |      private void launchTheApp() throws Exception {
 | 
												
													
														| 46 |          uiDevice().wakeUp();
 | 72 |          uiDevice().wakeUp();
 | 
												
													
														| 47 |          uiDevice().pressHome();
 | 73 |          uiDevice().pressHome();
 | 
												
													
														| 48 |          uiDevice().waitForIdle();
 | 74 |          uiDevice().waitForIdle();
 | 
												
													
														| 49 | -        Intent intent = getInstrumentation().getTargetContext().getPackageManager().getLaunchIntentForPackage(PACKAGE_NAME);
 |  | 
 | 
												
													
														|  | 
 | 75 | +        Intent intent = getInstrumentation().getContext().getPackageManager().getLaunchIntentForPackage(PACKAGE_NAME);
 | 
												
													
														| 50 |          assertThat(intent).isNotNull();
 | 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 |      private UiDevice uiDevice() {
 | 81 |      private UiDevice uiDevice() {
 |