From 3b1de2bfecad1b8d8348acbdf6adcac9cbcbdc5a Mon Sep 17 00:00:00 2001 From: tobrun Date: Fri, 22 Mar 2019 14:02:58 +0100 Subject: [android] - rework intregration test suite, lower used amount of UiSelectors --- .../mapboxsdk/integration/BaseIntegrationTest.kt | 57 +++++----------------- .../mapboxsdk/integration/FragmentBackStackTest.kt | 17 ++++--- .../integration/GLSurfaceViewReopenTest.kt | 18 ++++--- .../integration/GLSurfaceViewReuseTest.kt | 15 +++--- .../mapboxsdk/integration/OrientationChangeTest.kt | 11 +++-- .../mapboxsdk/integration/TextureViewReopenTest.kt | 17 ++++--- .../mapboxsdk/integration/TextureViewReuseTest.kt | 16 +++--- .../mapboxsdk/integration/ViewPagerScrollTest.kt | 11 +++-- .../src/main/AndroidManifest.xml | 9 ++-- 9 files changed, 78 insertions(+), 93 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..d0d0a50b33 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,29 @@ package com.mapbox.mapboxsdk.integration +import android.content.Context 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() } +} + +fun UiDevice.launchActivity(context: Context, clazz: Class<*>) { + val applicationPackage = InstrumentationRegistry.getTargetContext().packageName + val intent = Intent(context, clazz) + 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 diff --git a/platform/android/MapboxGLAndroidSDKTestApp/src/androidTest/java/com/mapbox/mapboxsdk/integration/FragmentBackStackTest.kt b/platform/android/MapboxGLAndroidSDKTestApp/src/androidTest/java/com/mapbox/mapboxsdk/integration/FragmentBackStackTest.kt index 9eb03bd1c5..cc7af202e2 100644 --- a/platform/android/MapboxGLAndroidSDKTestApp/src/androidTest/java/com/mapbox/mapboxsdk/integration/FragmentBackStackTest.kt +++ b/platform/android/MapboxGLAndroidSDKTestApp/src/androidTest/java/com/mapbox/mapboxsdk/integration/FragmentBackStackTest.kt @@ -1,9 +1,13 @@ package com.mapbox.mapboxsdk.integration import android.support.test.filters.LargeTest +import android.support.test.rule.ActivityTestRule import android.support.test.runner.AndroidJUnit4 import android.support.test.uiautomator.UiSelector +import com.mapbox.mapboxsdk.testapp.activity.fragment.FragmentBackStackActivity +import com.mapbox.mapboxsdk.testapp.activity.maplayout.SimpleMapActivity import org.junit.Before +import org.junit.Rule import org.junit.Test import org.junit.runner.RunWith @@ -13,21 +17,20 @@ import org.junit.runner.RunWith @RunWith(AndroidJUnit4::class) class FragmentBackStackTest : BaseIntegrationTest() { - @Before - override fun beforeTest() { - super.beforeTest() - openFeature("Backstack Map Fragment") - } + @get:Rule + var activityRule: ActivityTestRule = ActivityTestRule(FragmentBackStackActivity::class.java) + @Test @LargeTest fun backPressedOnBackStackResumed(){ device.waitForIdle() clickReplaceFragmentButton() + device.pressHome() device.waitForIdle() - pressHomeReturnWithRecentApps() - device.waitForIdle() + device.launchActivity(activityRule.activity.applicationContext, FragmentBackStackActivity::class.java) backPressBackStack() + device.waitForIdle() } private fun clickReplaceFragmentButton(){ diff --git a/platform/android/MapboxGLAndroidSDKTestApp/src/androidTest/java/com/mapbox/mapboxsdk/integration/GLSurfaceViewReopenTest.kt b/platform/android/MapboxGLAndroidSDKTestApp/src/androidTest/java/com/mapbox/mapboxsdk/integration/GLSurfaceViewReopenTest.kt index 07fea012eb..755c5fc560 100644 --- a/platform/android/MapboxGLAndroidSDKTestApp/src/androidTest/java/com/mapbox/mapboxsdk/integration/GLSurfaceViewReopenTest.kt +++ b/platform/android/MapboxGLAndroidSDKTestApp/src/androidTest/java/com/mapbox/mapboxsdk/integration/GLSurfaceViewReopenTest.kt @@ -1,27 +1,29 @@ package com.mapbox.mapboxsdk.integration import android.support.test.filters.LargeTest +import android.support.test.rule.ActivityTestRule import android.support.test.runner.AndroidJUnit4 -import org.junit.Before +import com.mapbox.mapboxsdk.testapp.activity.maplayout.SimpleMapActivity +import org.junit.Rule import org.junit.Test import org.junit.runner.RunWith + /** * Regression test that validates reopening an Activity with a GLSurfaceView */ @RunWith(AndroidJUnit4::class) class GLSurfaceViewReopenTest : BaseIntegrationTest() { - @Before - override fun beforeTest() { - super.beforeTest() - openFeature("Simple Map") - } + @get:Rule + var activityRule: ActivityTestRule = ActivityTestRule(SimpleMapActivity::class.java) @Test @LargeTest fun reopenSimpleMapActivity() { - pressHomeReturnWithRecentApps() device.waitForIdle() + device.pressHome() + device.waitForIdle() + device.launchActivity(activityRule.activity.applicationContext, SimpleMapActivity::class.java) } -} \ No newline at end of file +} diff --git a/platform/android/MapboxGLAndroidSDKTestApp/src/androidTest/java/com/mapbox/mapboxsdk/integration/GLSurfaceViewReuseTest.kt b/platform/android/MapboxGLAndroidSDKTestApp/src/androidTest/java/com/mapbox/mapboxsdk/integration/GLSurfaceViewReuseTest.kt index 95f05566c3..a117c26c2c 100644 --- a/platform/android/MapboxGLAndroidSDKTestApp/src/androidTest/java/com/mapbox/mapboxsdk/integration/GLSurfaceViewReuseTest.kt +++ b/platform/android/MapboxGLAndroidSDKTestApp/src/androidTest/java/com/mapbox/mapboxsdk/integration/GLSurfaceViewReuseTest.kt @@ -1,8 +1,12 @@ package com.mapbox.mapboxsdk.integration import android.support.test.filters.LargeTest +import android.support.test.rule.ActivityTestRule import android.support.test.runner.AndroidJUnit4 +import com.mapbox.mapboxsdk.testapp.activity.maplayout.GLSurfaceRecyclerViewActivity +import com.mapbox.mapboxsdk.testapp.activity.maplayout.SimpleMapActivity import org.junit.Before +import org.junit.Rule import org.junit.Test import org.junit.runner.RunWith @@ -12,19 +16,16 @@ import org.junit.runner.RunWith @RunWith(AndroidJUnit4::class) class GLSurfaceViewReuseTest : BaseIntegrationTest() { - @Before - override fun beforeTest() { - super.beforeTest() - openFeature("RecyclerView GLSurfaceView") - } + @get:Rule + var activityRule: ActivityTestRule = ActivityTestRule(GLSurfaceRecyclerViewActivity::class.java) @Test @LargeTest fun scrollRecylerView() { device.waitForIdle() - scrollRecyclerViewTo("Twenty-one") + device.scrollRecyclerViewTo("Twenty-one") device.waitForIdle() - scrollRecyclerViewTo("One") + device.scrollRecyclerViewTo("One") device.waitForIdle() } } \ No newline at end of file diff --git a/platform/android/MapboxGLAndroidSDKTestApp/src/androidTest/java/com/mapbox/mapboxsdk/integration/OrientationChangeTest.kt b/platform/android/MapboxGLAndroidSDKTestApp/src/androidTest/java/com/mapbox/mapboxsdk/integration/OrientationChangeTest.kt index b79303a1a8..6a3e662e73 100644 --- a/platform/android/MapboxGLAndroidSDKTestApp/src/androidTest/java/com/mapbox/mapboxsdk/integration/OrientationChangeTest.kt +++ b/platform/android/MapboxGLAndroidSDKTestApp/src/androidTest/java/com/mapbox/mapboxsdk/integration/OrientationChangeTest.kt @@ -1,19 +1,20 @@ package com.mapbox.mapboxsdk.integration import android.support.test.filters.LargeTest +import android.support.test.rule.ActivityTestRule import android.support.test.runner.AndroidJUnit4 +import com.mapbox.mapboxsdk.testapp.activity.maplayout.GLSurfaceRecyclerViewActivity +import com.mapbox.mapboxsdk.testapp.activity.maplayout.SimpleMapActivity import org.junit.Before +import org.junit.Rule import org.junit.Test import org.junit.runner.RunWith @RunWith(AndroidJUnit4::class) class OrientationChangeTest : BaseIntegrationTest() { - @Before - override fun beforeTest() { - super.beforeTest() - openFeature("Simple Map") - } + @get:Rule + var activityRule: ActivityTestRule = ActivityTestRule(SimpleMapActivity::class.java) @Test @LargeTest diff --git a/platform/android/MapboxGLAndroidSDKTestApp/src/androidTest/java/com/mapbox/mapboxsdk/integration/TextureViewReopenTest.kt b/platform/android/MapboxGLAndroidSDKTestApp/src/androidTest/java/com/mapbox/mapboxsdk/integration/TextureViewReopenTest.kt index 3de8ece8c3..cc171ca905 100644 --- a/platform/android/MapboxGLAndroidSDKTestApp/src/androidTest/java/com/mapbox/mapboxsdk/integration/TextureViewReopenTest.kt +++ b/platform/android/MapboxGLAndroidSDKTestApp/src/androidTest/java/com/mapbox/mapboxsdk/integration/TextureViewReopenTest.kt @@ -1,8 +1,13 @@ package com.mapbox.mapboxsdk.integration import android.support.test.filters.LargeTest +import android.support.test.rule.ActivityTestRule import android.support.test.runner.AndroidJUnit4 +import com.mapbox.mapboxsdk.testapp.activity.maplayout.GLSurfaceRecyclerViewActivity +import com.mapbox.mapboxsdk.testapp.activity.maplayout.SimpleMapActivity +import com.mapbox.mapboxsdk.testapp.activity.textureview.TextureViewDebugModeActivity import org.junit.Before +import org.junit.Rule import org.junit.Test import org.junit.runner.RunWith import java.lang.Thread.sleep @@ -13,17 +18,15 @@ import java.lang.Thread.sleep @RunWith(AndroidJUnit4::class) class TextureViewReopenTest : BaseIntegrationTest() { - @Before - override fun beforeTest() { - super.beforeTest() - openFeature("TextureView debug") - } + @get:Rule + var activityRule: ActivityTestRule = ActivityTestRule(TextureViewDebugModeActivity::class.java) @Test @LargeTest fun reopenTextureViewDebugActivity() { - pressHomeReturnWithRecentApps() device.waitForIdle() - sleep(LAUNCH_TIMEOUT) + device.pressHome() + device.waitForIdle() + device.launchActivity(activityRule.activity.applicationContext, TextureViewDebugModeActivity::class.java) } } \ No newline at end of file diff --git a/platform/android/MapboxGLAndroidSDKTestApp/src/androidTest/java/com/mapbox/mapboxsdk/integration/TextureViewReuseTest.kt b/platform/android/MapboxGLAndroidSDKTestApp/src/androidTest/java/com/mapbox/mapboxsdk/integration/TextureViewReuseTest.kt index 6053e696d6..aff0b0f979 100644 --- a/platform/android/MapboxGLAndroidSDKTestApp/src/androidTest/java/com/mapbox/mapboxsdk/integration/TextureViewReuseTest.kt +++ b/platform/android/MapboxGLAndroidSDKTestApp/src/androidTest/java/com/mapbox/mapboxsdk/integration/TextureViewReuseTest.kt @@ -1,8 +1,12 @@ package com.mapbox.mapboxsdk.integration import android.support.test.filters.LargeTest +import android.support.test.rule.ActivityTestRule import android.support.test.runner.AndroidJUnit4 +import com.mapbox.mapboxsdk.testapp.activity.maplayout.GLSurfaceRecyclerViewActivity +import com.mapbox.mapboxsdk.testapp.activity.maplayout.TextureRecyclerViewActivity import org.junit.Before +import org.junit.Rule import org.junit.Test import org.junit.runner.RunWith @@ -12,18 +16,16 @@ import org.junit.runner.RunWith @RunWith(AndroidJUnit4::class) class TextureViewReuseTest : BaseIntegrationTest() { - @Before - override fun beforeTest() { - super.beforeTest() - openFeature("RecyclerView TextureView") - } + @get:Rule + var activityRule: ActivityTestRule = ActivityTestRule(TextureRecyclerViewActivity::class.java) @Test @LargeTest fun scrollRecylerView() { - scrollRecyclerViewTo("Twenty-one") device.waitForIdle() - scrollRecyclerViewTo("One") + device.scrollRecyclerViewTo("Twenty-one") + device.waitForIdle() + device.scrollRecyclerViewTo("One") device.waitForIdle() } } \ No newline at end of file diff --git a/platform/android/MapboxGLAndroidSDKTestApp/src/androidTest/java/com/mapbox/mapboxsdk/integration/ViewPagerScrollTest.kt b/platform/android/MapboxGLAndroidSDKTestApp/src/androidTest/java/com/mapbox/mapboxsdk/integration/ViewPagerScrollTest.kt index 9f4b7591b6..074424ddaf 100644 --- a/platform/android/MapboxGLAndroidSDKTestApp/src/androidTest/java/com/mapbox/mapboxsdk/integration/ViewPagerScrollTest.kt +++ b/platform/android/MapboxGLAndroidSDKTestApp/src/androidTest/java/com/mapbox/mapboxsdk/integration/ViewPagerScrollTest.kt @@ -1,9 +1,13 @@ package com.mapbox.mapboxsdk.integration import android.support.test.filters.LargeTest +import android.support.test.rule.ActivityTestRule import android.support.test.runner.AndroidJUnit4 import android.support.test.uiautomator.UiSelector +import com.mapbox.mapboxsdk.testapp.activity.fragment.ViewPagerActivity +import com.mapbox.mapboxsdk.testapp.activity.maplayout.GLSurfaceRecyclerViewActivity import org.junit.Before +import org.junit.Rule import org.junit.Test import org.junit.runner.RunWith @@ -13,11 +17,8 @@ import org.junit.runner.RunWith @RunWith(AndroidJUnit4::class) class ViewPagerScrollTest : BaseIntegrationTest() { - @Before - override fun beforeTest() { - super.beforeTest() - openFeature("ViewPager") - } + @get:Rule + var activityRule: ActivityTestRule = ActivityTestRule(ViewPagerActivity::class.java) @Test @LargeTest diff --git a/platform/android/MapboxGLAndroidSDKTestApp/src/main/AndroidManifest.xml b/platform/android/MapboxGLAndroidSDKTestApp/src/main/AndroidManifest.xml index 4b3763d3e3..b4c7e82b71 100644 --- a/platform/android/MapboxGLAndroidSDKTestApp/src/main/AndroidManifest.xml +++ b/platform/android/MapboxGLAndroidSDKTestApp/src/main/AndroidManifest.xml @@ -173,7 +173,8 @@ + android:label="@string/activity_map_fragment_backstack" + android:launchMode="singleTask"> @@ -407,7 +408,8 @@ + android:label="@string/activity_simple_map" + android:launchMode="singleTask"> @@ -731,7 +733,8 @@ + android:label="@string/activity_textureview_debug" + android:launchMode="singleTask"> -- cgit v1.2.1