Skip to content
This repository has been archived by the owner on Aug 8, 2023. It is now read-only.

Commit

Permalink
[android] - revert onDismiss workaround, refactor tests, adress review
Browse files Browse the repository at this point in the history
comments
  • Loading branch information
tobrun committed Mar 25, 2019
1 parent e7c9d3c commit 7dea381
Show file tree
Hide file tree
Showing 13 changed files with 155 additions and 153 deletions.
4 changes: 2 additions & 2 deletions circle.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,8 @@ workflows:
- android-arm-template:
name: android-gnustl-arm-v7
stl: gnustl_shared
firebase_device_id: "m0"
firebase_device_os: "18"
firebase_device_id: "cheryl"
firebase_device_os: "25"
image: android-ndk-r17c:1d5db0eb34
abi: arm-v7
- android-release:
Expand Down
Original file line number Diff line number Diff line change
@@ -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))
}
Original file line number Diff line number Diff line change
@@ -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

Expand All @@ -13,21 +17,19 @@ 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<FragmentBackStackActivity> = 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(){
Expand Down
Original file line number Diff line number Diff line change
@@ -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<SimpleMapActivity> = ActivityTestRule(SimpleMapActivity::class.java)

@Test
@LargeTest
fun reopenSimpleMapActivity() {
pressHomeReturnWithRecentApps()
device.waitForIdle()
device.pressHome()
device.waitForIdle()
device.launchActivity(activityRule.activity.applicationContext, SimpleMapActivity::class.java)
}
}
}
Original file line number Diff line number Diff line change
@@ -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

Expand All @@ -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<GLSurfaceRecyclerViewActivity> = ActivityTestRule(GLSurfaceRecyclerViewActivity::class.java)

@Test
@LargeTest
fun scrollRecylerView() {
fun scrollRecyclerView() {
device.waitForIdle()
scrollRecyclerViewTo("Twenty-one")
device.scrollRecyclerViewTo("Twenty-one")
device.waitForIdle()
scrollRecyclerViewTo("One")
device.scrollRecyclerViewTo("One")
device.waitForIdle()
}
}
Original file line number Diff line number Diff line change
@@ -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<SimpleMapActivity> = ActivityTestRule(SimpleMapActivity::class.java)

@Test
@LargeTest
Expand All @@ -25,5 +26,9 @@ class OrientationChangeTest : BaseIntegrationTest() {
device.setOrientationRight()
device.waitForIdle()
device.setOrientationNatural()
device.setOrientationLeft()
device.setOrientationNatural()
device.setOrientationRight()
device.setOrientationNatural()
}
}
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -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<TextureViewDebugModeActivity> = 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)
}
}
Original file line number Diff line number Diff line change
@@ -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

Expand All @@ -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<TextureRecyclerViewActivity> = ActivityTestRule(TextureRecyclerViewActivity::class.java)

@Test
@LargeTest
fun scrollRecylerView() {
scrollRecyclerViewTo("Twenty-one")
fun scrollRecyclerView() {
device.waitForIdle()
device.scrollRecyclerViewTo("Twenty-one")
device.waitForIdle()
scrollRecyclerViewTo("One")
device.scrollRecyclerViewTo("One")
device.waitForIdle()
}
}
Original file line number Diff line number Diff line change
@@ -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

Expand All @@ -13,20 +17,17 @@ import org.junit.runner.RunWith
@RunWith(AndroidJUnit4::class)
class ViewPagerScrollTest : BaseIntegrationTest() {

@Before
override fun beforeTest() {
super.beforeTest()
openFeature("ViewPager")
}
@get:Rule
var activityRule: ActivityTestRule<ViewPagerActivity> = ActivityTestRule(ViewPagerActivity::class.java)

@Test
@LargeTest
fun scrollViewPager() {
for (i in 1..5) {
for (i in 1..4) {
clickTab(i)
}

for (i in 4 downTo 0) {
for (i in 3 downTo 0) {
clickTab(i)
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import android.support.test.runner.AndroidJUnit4
import com.mapbox.mapboxsdk.testapp.R
import com.mapbox.mapboxsdk.testapp.action.WaitAction
import com.mapbox.mapboxsdk.testapp.activity.maplayout.MapInDialogActivity
import org.junit.Ignore
import org.junit.Rule
import org.junit.Test
import org.junit.runner.RunWith
Expand All @@ -25,9 +26,10 @@ class MapDialogFragmentTest {
var activityRule: ActivityTestRule<MapInDialogActivity> = ActivityTestRule(MapInDialogActivity::class.java)

@Test
@Ignore
fun openCloseDialog() {
onView(withId(R.id.button_open_dialog)).perform(click())
onView(withId(R.id.mapView)).perform(WaitAction(2500))
Thread.sleep(2500)
Espresso.pressBack()
}
}
Loading

0 comments on commit 7dea381

Please sign in to comment.