summaryrefslogtreecommitdiff
path: root/platform/android/MapboxGLAndroidSDKTestApp/src/androidTest/java/com/mapbox/mapboxsdk/integration/BaseIntegrationTest.kt
diff options
context:
space:
mode:
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.kt59
1 files changed, 15 insertions, 44 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
index 4d39b55a25..be57fb3e2d 100644
--- 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
@@ -1,60 +1,31 @@
package com.mapbox.mapboxsdk.integration
+import android.content.Context
import android.content.Intent
+import android.content.Intent.FLAG_ACTIVITY_SINGLE_TOP
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()
}
+}
+
+fun UiDevice.launchActivity(context: Context, clazz: Class<*>) {
+ val applicationPackage = InstrumentationRegistry.getTargetContext().packageName
+ val intent = Intent(context, clazz)
+ intent.addFlags(FLAG_ACTIVITY_SINGLE_TOP)
+ InstrumentationRegistry.getContext().startActivity(intent)
+ wait(Until.hasObject(By.pkg(applicationPackage).depth(0)), 5000)
+}
+
+fun UiDevice.scrollRecyclerViewTo(recycleItem: String) {
+ val appView = UiScrollable(UiSelector().scrollable(true))
+ appView.scrollIntoView(UiSelector().text(recycleItem))
} \ No newline at end of file