This repository has been archived by the owner on Aug 8, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[android] - revert onDismiss workaround, refactor tests, adress review
comments
- Loading branch information
Showing
13 changed files
with
155 additions
and
153 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
59 changes: 15 additions & 44 deletions
59
...idSDKTestApp/src/androidTest/java/com/mapbox/mapboxsdk/integration/BaseIntegrationTest.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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)) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
18 changes: 10 additions & 8 deletions
18
...KTestApp/src/androidTest/java/com/mapbox/mapboxsdk/integration/GLSurfaceViewReopenTest.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.