diff options
Diffstat (limited to 'platform/android/MapboxGLAndroidSDKTestApp/src/androidTest/java/com/mapbox/mapboxsdk/integration/BaseIntegrationTest.kt')
-rw-r--r-- | platform/android/MapboxGLAndroidSDKTestApp/src/androidTest/java/com/mapbox/mapboxsdk/integration/BaseIntegrationTest.kt | 60 |
1 files changed, 60 insertions, 0 deletions
diff --git a/platform/android/MapboxGLAndroidSDKTestApp/src/androidTest/java/com/mapbox/mapboxsdk/integration/BaseIntegrationTest.kt b/platform/android/MapboxGLAndroidSDKTestApp/src/androidTest/java/com/mapbox/mapboxsdk/integration/BaseIntegrationTest.kt new file mode 100644 index 0000000000..4d39b55a25 --- /dev/null +++ b/platform/android/MapboxGLAndroidSDKTestApp/src/androidTest/java/com/mapbox/mapboxsdk/integration/BaseIntegrationTest.kt @@ -0,0 +1,60 @@ +package com.mapbox.mapboxsdk.integration + +import android.content.Intent +import android.support.test.InstrumentationRegistry +import android.support.test.uiautomator.* +import org.hamcrest.CoreMatchers +import org.hamcrest.MatcherAssert +import org.junit.Before + +const val LAUNCH_TIMEOUT = 2500L +private const val TEST_APP_PACKAGE = "com.mapbox.mapboxsdk.testapp" + +abstract class BaseIntegrationTest { + + protected lateinit var device: UiDevice + + @Before + open fun beforeTest() { + // Initialize UiDevice instance + device = UiDevice.getInstance(InstrumentationRegistry.getInstrumentation()) + + // Start from the home screen + device.pressHome() + + // Wait for launcher + val launcherPackage: String = device.launcherPackageName + MatcherAssert.assertThat(launcherPackage, CoreMatchers.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(TEST_APP_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(TEST_APP_PACKAGE).depth(0)), + LAUNCH_TIMEOUT + ) + } + + fun openFeature(featureName: String) { + scrollRecyclerViewTo(featureName) + device.findObject(UiSelector().text(featureName)).clickAndWaitForNewWindow() + device.waitForIdle(LAUNCH_TIMEOUT) + } + + fun scrollRecyclerViewTo(recycleItem: String) { + val appView = UiScrollable(UiSelector().scrollable(true)) + appView.scrollIntoView(UiSelector().text(recycleItem)) + } + + fun pressHomeReturnWithRecentApps(){ + device.pressRecentApps() + device.findObject(UiSelector().text(InstrumentationRegistry.getTargetContext().getString(InstrumentationRegistry.getTargetContext().applicationInfo.labelRes))).click() + } +}
\ No newline at end of file |