diff --git a/app/src/androidTest/java/org/mozilla/fenix/helpers/TestHelper.kt b/app/src/androidTest/java/org/mozilla/fenix/helpers/TestHelper.kt index af0528849..16c42103f 100644 --- a/app/src/androidTest/java/org/mozilla/fenix/helpers/TestHelper.kt +++ b/app/src/androidTest/java/org/mozilla/fenix/helpers/TestHelper.kt @@ -28,6 +28,8 @@ import android.util.Log import android.view.View import androidx.annotation.RequiresApi import androidx.browser.customtabs.CustomTabsIntent +import androidx.compose.ui.test.junit4.AndroidComposeTestRule +import androidx.test.core.app.launchActivity import androidx.test.espresso.Espresso import androidx.test.espresso.Espresso.onView import androidx.test.espresso.IdlingRegistry @@ -483,6 +485,26 @@ object TestHelper { } } + /** + * Wrapper to launch the app using the launcher intent. + */ + fun runWithLauncherIntent( + activityTestRule: AndroidComposeTestRule, + testBlock: () -> Unit, + ) { + val launcherIntent = Intent(Intent.ACTION_MAIN).apply { + addCategory(Intent.CATEGORY_LAUNCHER) + } + + activityTestRule.activityRule.withIntent(launcherIntent).launchActivity(launcherIntent) + + try { + testBlock() + } catch (e: Exception) { + e.printStackTrace() + } + } + fun putAppToBackground() { mDevice.pressRecentApps() mDevice.findObject(UiSelector().resourceId("$packageName:id/container")).waitUntilGone(waitingTime) diff --git a/app/src/androidTest/java/org/mozilla/fenix/ui/OnboardingTest.kt b/app/src/androidTest/java/org/mozilla/fenix/ui/OnboardingTest.kt new file mode 100644 index 000000000..b552a68c1 --- /dev/null +++ b/app/src/androidTest/java/org/mozilla/fenix/ui/OnboardingTest.kt @@ -0,0 +1,70 @@ +package org.mozilla.fenix.ui + +import androidx.compose.ui.test.junit4.AndroidComposeTestRule +import org.junit.Rule +import org.junit.Test +import org.mozilla.fenix.customannotations.SmokeTest +import org.mozilla.fenix.helpers.HomeActivityIntentTestRule +import org.mozilla.fenix.helpers.TestHelper.runWithLauncherIntent +import org.mozilla.fenix.ui.robots.homeScreen + +class OnboardingTest { + + @get:Rule + val activityTestRule = + AndroidComposeTestRule( + HomeActivityIntentTestRule.withDefaultSettingsOverrides(launchActivity = false), + ) { it.activity } + + // TestRail link: https://testrail.stage.mozaws.net/index.php?/cases/view/2122321 + @Test + fun verifyFirstOnboardingCardItemsTest() { + runWithLauncherIntent(activityTestRule) { + homeScreen { + verifyFirstOnboardingCard(activityTestRule) + } + } + } + + // TestRail link: https://testrail.stage.mozaws.net/index.php?/cases/view/2122334 + @SmokeTest + @Test + fun verifyFirstOnboardingCardItemsFunctionalityTest() { + runWithLauncherIntent(activityTestRule) { + homeScreen { + clickNotNowOnboardingButton(activityTestRule) + verifySecondOnboardingCard(activityTestRule) + swipeSecondOnboardingCardToRight() + }.clickSetAsDefaultBrowserOnboardingButton(activityTestRule) { + verifyAndroidDefaultAppsMenuAppears() + }.goBackToOnboardingScreen { + verifySecondOnboardingCard(activityTestRule) + } + } + } + + // TestRail link: https://testrail.stage.mozaws.net/index.php?/cases/view/2122343 + @Test + fun verifySecondOnboardingCardItemsTest() { + runWithLauncherIntent(activityTestRule) { + homeScreen { + clickNotNowOnboardingButton(activityTestRule) + verifySecondOnboardingCard(activityTestRule) + } + } + } + + // TestRail link: https://testrail.stage.mozaws.net/index.php?/cases/view/2122344 + @SmokeTest + @Test + fun verifySecondOnboardingCardSignInFunctionalityTest() { + runWithLauncherIntent(activityTestRule) { + homeScreen { + clickNotNowOnboardingButton(activityTestRule) + verifySecondOnboardingCard(activityTestRule) + }.clickSignInOnboardingButton(activityTestRule) { + verifyTurnOnSyncMenu() + } + } + } +} diff --git a/app/src/androidTest/java/org/mozilla/fenix/ui/robots/HomeScreenRobot.kt b/app/src/androidTest/java/org/mozilla/fenix/ui/robots/HomeScreenRobot.kt index 0b26c69f6..ee2a500b7 100644 --- a/app/src/androidTest/java/org/mozilla/fenix/ui/robots/HomeScreenRobot.kt +++ b/app/src/androidTest/java/org/mozilla/fenix/ui/robots/HomeScreenRobot.kt @@ -147,6 +147,58 @@ class HomeScreenRobot { } } + fun verifyFirstOnboardingCard(composeTestRule: ComposeTestRule) { + composeTestRule.also { + it.onNodeWithText( + getStringResource(R.string.juno_onboarding_default_browser_title_nimbus_2), + ).assertExists() + + it.onNodeWithText( + getStringResource(R.string.juno_onboarding_default_browser_description_nimbus_2), + ).assertExists() + + it.onNodeWithText( + getStringResource(R.string.juno_onboarding_default_browser_positive_button), + ).assertExists() + + it.onNodeWithText( + getStringResource(R.string.juno_onboarding_default_browser_negative_button), + ).assertExists() + } + } + + fun verifySecondOnboardingCard(composeTestRule: ComposeTestRule) { + composeTestRule.also { + it.onNodeWithText( + getStringResource(R.string.juno_onboarding_sign_in_title_2), + ).assertExists() + + it.onNodeWithText( + getStringResource(R.string.juno_onboarding_sign_in_description_2), + ).assertExists() + + it.onNodeWithText( + getStringResource(R.string.juno_onboarding_sign_in_positive_button), + ).assertExists() + + it.onNodeWithText( + getStringResource(R.string.juno_onboarding_sign_in_negative_button), + ).assertExists() + } + } + + fun clickNotNowOnboardingButton(composeTestRule: ComposeTestRule) = + composeTestRule.onNodeWithText( + getStringResource(R.string.juno_onboarding_default_browser_negative_button), + ).performClick() + + fun swipeSecondOnboardingCardToRight() = + mDevice.findObject( + UiSelector().textContains( + getStringResource(R.string.juno_onboarding_sign_in_title_2), + ), + ).swipeRight(3) + fun clickGetStartedButton(testRule: ComposeTestRule) = testRule.onNodeWithText(getStringResource(R.string.onboarding_home_get_started_button)).performClick() @@ -772,6 +824,30 @@ class HomeScreenRobot { BrowserRobot().interact() return BrowserRobot.Transition() } + + fun clickSetAsDefaultBrowserOnboardingButton( + composeTestRule: ComposeTestRule, + interact: SettingsRobot.() -> Unit, + ): SettingsRobot.Transition { + composeTestRule.onNodeWithText( + getStringResource(R.string.juno_onboarding_default_browser_positive_button), + ).performClick() + + SettingsRobot().interact() + return SettingsRobot.Transition() + } + + fun clickSignInOnboardingButton( + composeTestRule: ComposeTestRule, + interact: SyncSignInRobot.() -> Unit, + ): SyncSignInRobot.Transition { + composeTestRule.onNodeWithText( + getStringResource(R.string.juno_onboarding_sign_in_positive_button), + ).performClick() + + SyncSignInRobot().interact() + return SyncSignInRobot.Transition() + } } } diff --git a/app/src/androidTest/java/org/mozilla/fenix/ui/robots/SettingsRobot.kt b/app/src/androidTest/java/org/mozilla/fenix/ui/robots/SettingsRobot.kt index ad773e363..daf7ae2df 100644 --- a/app/src/androidTest/java/org/mozilla/fenix/ui/robots/SettingsRobot.kt +++ b/app/src/androidTest/java/org/mozilla/fenix/ui/robots/SettingsRobot.kt @@ -210,6 +210,14 @@ class SettingsRobot { return HomeScreenRobot.Transition() } + fun goBackToOnboardingScreen(interact: HomeScreenRobot.() -> Unit): HomeScreenRobot.Transition { + mDevice.pressBack() + mDevice.waitForIdle(waitingTimeShort) + + HomeScreenRobot().interact() + return HomeScreenRobot.Transition() + } + fun goBackToBrowser(interact: BrowserRobot.() -> Unit): BrowserRobot.Transition { goBackButton().click()