From e94bc0b1e6affe872c3a505e4386b25c84541c68 Mon Sep 17 00:00:00 2001 From: AndiAJ Date: Mon, 13 Mar 2023 15:55:00 +0200 Subject: [PATCH] Bug 1822050 - Verify cookie banner reduction summary updates in UI tests --- .../mozilla/fenix/ui/CookieBannerReductionTest.kt | 13 ++++++++++--- .../org/mozilla/fenix/ui/robots/SettingsRobot.kt | 12 ++++++++++++ .../SettingsSubMenuCookieBannerReductionRobot.kt | 11 ++++++++++- 3 files changed, 32 insertions(+), 4 deletions(-) diff --git a/app/src/androidTest/java/org/mozilla/fenix/ui/CookieBannerReductionTest.kt b/app/src/androidTest/java/org/mozilla/fenix/ui/CookieBannerReductionTest.kt index 46b6d46542..5bc862e3fb 100644 --- a/app/src/androidTest/java/org/mozilla/fenix/ui/CookieBannerReductionTest.kt +++ b/app/src/androidTest/java/org/mozilla/fenix/ui/CookieBannerReductionTest.kt @@ -5,7 +5,6 @@ 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 import org.mozilla.fenix.helpers.TestHelper.exitMenu import org.mozilla.fenix.helpers.TestHelper.restartApp import org.mozilla.fenix.ui.robots.browserScreen @@ -28,10 +27,13 @@ class CookieBannerReductionTest { verifyCookieBannerExists(exists = true) }.openThreeDotMenu { }.openSettings { + verifyCookieBannerReductionSummary("Off") }.openCookieBannerReductionSubMenu { verifyCookieBannerView(isCookieBannerReductionChecked = false) clickCookieBannerReductionToggle() verifyCheckedCookieBannerReductionToggle(isCookieBannerReductionChecked = true) + }.goBack { + verifyCookieBannerReductionSummary("On") } exitMenu() @@ -40,7 +42,7 @@ class CookieBannerReductionTest { verifyCookieBannerExists(exists = false) } - TestHelper.restartApp(activityTestRule) + restartApp(activityTestRule) browserScreen { verifyCookieBannerExists(exists = false) @@ -74,12 +76,17 @@ class CookieBannerReductionTest { verifyCookieBannerExists(exists = true) }.openThreeDotMenu { }.openSettings { + verifyCookieBannerReductionSummary("Off") }.openCookieBannerReductionSubMenu { verifyCookieBannerView(isCookieBannerReductionChecked = false) clickCookieBannerReductionToggle() verifyCheckedCookieBannerReductionToggle(isCookieBannerReductionChecked = true) - exitMenu() + }.goBack { + verifyCookieBannerReductionSummary("On") } + + exitMenu() + browserScreen { verifyCookieBannerExists(exists = false) } 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 26738dc86e..dd9f3cecfa 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 @@ -94,6 +94,18 @@ class SettingsRobot { hasSibling(withText(HTTPSOnlyModeSummary)), ), ).check(matches(withEffectiveVisibility(Visibility.VISIBLE))) + + fun verifyCookieBannerReductionSummary(cookieBannerReductionSummary: String) { + scrollToElementByText(getStringResource(R.string.preferences_cookie_banner_reduction)) + + onView( + allOf( + withText(R.string.preferences_cookie_banner_reduction), + hasSibling(withText(cookieBannerReductionSummary)), + ), + ).check(matches(withEffectiveVisibility(Visibility.VISIBLE))) + } + fun verifyEnhancedTrackingProtectionButton() = assertEnhancedTrackingProtectionButton() fun verifyLoginsAndPasswordsButton() = assertLoginsAndPasswordsButton() fun verifyEnhancedTrackingProtectionState(option: String) = diff --git a/app/src/androidTest/java/org/mozilla/fenix/ui/robots/SettingsSubMenuCookieBannerReductionRobot.kt b/app/src/androidTest/java/org/mozilla/fenix/ui/robots/SettingsSubMenuCookieBannerReductionRobot.kt index d7272fdf27..482050fb79 100644 --- a/app/src/androidTest/java/org/mozilla/fenix/ui/robots/SettingsSubMenuCookieBannerReductionRobot.kt +++ b/app/src/androidTest/java/org/mozilla/fenix/ui/robots/SettingsSubMenuCookieBannerReductionRobot.kt @@ -11,7 +11,9 @@ import org.mozilla.fenix.helpers.MatcherHelper.checkedItemWithResId import org.mozilla.fenix.helpers.MatcherHelper.itemContainingText import org.mozilla.fenix.helpers.MatcherHelper.itemWithResId import org.mozilla.fenix.helpers.TestHelper.getStringResource +import org.mozilla.fenix.helpers.TestHelper.mDevice import org.mozilla.fenix.helpers.TestHelper.packageName +import org.mozilla.fenix.helpers.click /** * Implementation of Robot Pattern for the settings Cookie Banner Reduction sub menu. @@ -25,7 +27,14 @@ class SettingsSubMenuCookieBannerReductionRobot { fun verifyCheckedCookieBannerReductionToggle(isCookieBannerReductionChecked: Boolean) = assertCheckedItemWithResIdExists(checkedCookieBannerOptionToggle(isCookieBannerReductionChecked)) - class Transition + class Transition { + fun goBack(interact: SettingsRobot.() -> Unit): SettingsRobot.Transition { + mDevice.pressBack() + + SettingsRobot().interact() + return SettingsRobot.Transition() + } + } } private val cookieBannerOptionTitle =