package com.mapbox.mapboxsdk.maps import android.content.Intent import android.support.test.InstrumentationRegistry import android.support.test.filters.SdkSuppress import android.support.test.runner.AndroidJUnit4 import android.support.test.uiautomator.* import org.hamcrest.CoreMatchers.notNullValue import org.hamcrest.MatcherAssert.assertThat import org.junit.Before import org.junit.Test import org.junit.runner.RunWith private const val BASIC_SAMPLE_PACKAGE = "com.mapbox.mapboxsdk.testapp" private const val LAUNCH_TIMEOUT = 5000L @RunWith(AndroidJUnit4::class) @SdkSuppress(minSdkVersion = 18) class TextureViewReopenTest { private lateinit var device: UiDevice @Before fun startSimpleMapActivityFromHomeScreen() { // Initialize UiDevice instance device = UiDevice.getInstance(InstrumentationRegistry.getInstrumentation()) // Start from the home screen device.pressHome() // Wait for launcher val launcherPackage: String = device.launcherPackageName assertThat(launcherPackage, notNullValue()) device.wait(Until.hasObject(By.pkg(launcherPackage).depth(0)), LAUNCH_TIMEOUT) // Launch the app val context = InstrumentationRegistry.getInstrumentation().context val intent = context.packageManager.getLaunchIntentForPackage(BASIC_SAMPLE_PACKAGE).apply { // Clear out any previous instances addFlags(Intent.FLAG_ACTIVITY_CLEAR_TASK) } context.startActivity(intent) // Wait for the app to appear device.wait( Until.hasObject(By.pkg(BASIC_SAMPLE_PACKAGE).depth(0)), LAUNCH_TIMEOUT ) // open TextureView debug activity val appView = UiScrollable(UiSelector().scrollable(true)) appView.scrollIntoView(UiSelector().text("TextureView debug")) device.findObject(UiSelector().text("TextureView debug")).clickAndWaitForNewWindow() // wait for idle device.waitForIdle(LAUNCH_TIMEOUT) } @Test fun reopenTextureViewDebugActivity() { // press recent apps button device.pressRecentApps() // return to app device.findObject(UiSelector().text(InstrumentationRegistry.getTargetContext().getString(InstrumentationRegistry.getTargetContext().applicationInfo.labelRes))).click() // wait for idle device.waitForIdle(LAUNCH_TIMEOUT) } }