Bug 1861364 - New onboarding UI tests

fenix/121.0
AndiAJ 7 months ago committed by mergify[bot]
parent 458caede01
commit 802a4c3def

@ -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<HomeActivityIntentTestRule, HomeActivity>,
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)

@ -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()
}
}
}
}

@ -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()
}
}
}

@ -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()

Loading…
Cancel
Save