From 0fb1d8ff97ce6b058ec105df114d4c219f128bf9 Mon Sep 17 00:00:00 2001 From: Michael Comella Date: Wed, 30 Sep 2020 08:56:42 -0700 Subject: [PATCH] [fenix] For https://github.com/mozilla-mobile/fenix/issues/13959: add HomeActivityTestRule.skipOnboarding. This is more correct, faster, and results in less copy-paste duplication than the current behavior: homeScreen { }.dismissOnboarding() Which opens settings to dismiss onboarding. --- .../org/mozilla/fenix/helpers/HomeActivityTestRule.kt | 19 +++++++++++++++++-- 1 file changed, 17 insertions(+), 2 deletions(-) diff --git a/mobile/android/fenix/app/src/androidTest/java/org/mozilla/fenix/helpers/HomeActivityTestRule.kt b/mobile/android/fenix/app/src/androidTest/java/org/mozilla/fenix/helpers/HomeActivityTestRule.kt index 2b47a32a09e6..10b8b5d33491 100644 --- a/mobile/android/fenix/app/src/androidTest/java/org/mozilla/fenix/helpers/HomeActivityTestRule.kt +++ b/mobile/android/fenix/app/src/androidTest/java/org/mozilla/fenix/helpers/HomeActivityTestRule.kt @@ -9,6 +9,8 @@ import androidx.test.platform.app.InstrumentationRegistry import androidx.test.rule.ActivityTestRule import androidx.test.uiautomator.UiDevice import org.mozilla.fenix.HomeActivity +import org.mozilla.fenix.onboarding.FenixOnboarding +import org.mozilla.fenix.ui.robots.appContext /** * A [org.junit.Rule] to handle shared test set up for tests on [HomeActivity]. @@ -17,11 +19,16 @@ import org.mozilla.fenix.HomeActivity * @param launchActivity See [ActivityTestRule] */ -class HomeActivityTestRule(initialTouchMode: Boolean = false, launchActivity: Boolean = true) : +class HomeActivityTestRule( + initialTouchMode: Boolean = false, + launchActivity: Boolean = true, + private val skipOnboarding: Boolean = false +) : ActivityTestRule(HomeActivity::class.java, initialTouchMode, launchActivity) { override fun beforeActivityLaunched() { super.beforeActivityLaunched() setLongTapTimeout() + if (skipOnboarding) { skipOnboardingBeforeLaunch() } } } @@ -35,12 +42,14 @@ class HomeActivityTestRule(initialTouchMode: Boolean = false, launchActivity: Bo class HomeActivityIntentTestRule( initialTouchMode: Boolean = false, - launchActivity: Boolean = true + launchActivity: Boolean = true, + private val skipOnboarding: Boolean = false ) : IntentsTestRule(HomeActivity::class.java, initialTouchMode, launchActivity) { override fun beforeActivityLaunched() { super.beforeActivityLaunched() setLongTapTimeout() + if (skipOnboarding) { skipOnboardingBeforeLaunch() } } } @@ -49,3 +58,9 @@ fun setLongTapTimeout() { val mDevice = UiDevice.getInstance(InstrumentationRegistry.getInstrumentation()) mDevice.executeShellCommand("settings put secure long_press_timeout 3000") } + +private fun skipOnboardingBeforeLaunch() { + // The production code isn't aware that we're using + // this API so it can be fragile. + FenixOnboarding(appContext).finish() +} -- 2.11.4.GIT