From ce0d5a1a2819e574bcf12f9dea5a5529377d5d74 Mon Sep 17 00:00:00 2001 From: ValentinTimisica Date: Wed, 10 Jun 2020 10:28:37 +0300 Subject: [PATCH] For #11365: Fixes UI tests for Settings --- .../mozilla/fenix/ui/SettingsBasicsTest.kt | 9 +-- .../mozilla/fenix/ui/robots/SettingsRobot.kt | 44 +++++++++--- .../SettingsSubMenuDefaultBrowserRobot.kt | 72 ------------------- 3 files changed, 37 insertions(+), 88 deletions(-) delete mode 100644 app/src/androidTest/java/org/mozilla/fenix/ui/robots/SettingsSubMenuDefaultBrowserRobot.kt diff --git a/app/src/androidTest/java/org/mozilla/fenix/ui/SettingsBasicsTest.kt b/app/src/androidTest/java/org/mozilla/fenix/ui/SettingsBasicsTest.kt index 92d86a45d..b97d938d8 100644 --- a/app/src/androidTest/java/org/mozilla/fenix/ui/SettingsBasicsTest.kt +++ b/app/src/androidTest/java/org/mozilla/fenix/ui/SettingsBasicsTest.kt @@ -68,6 +68,7 @@ class SettingsBasicsTest { }.openSettings { verifyBasicsHeading() verifySearchEngineButton() + verifyDefaultBrowserItem() // drill down to submenu }.openSearchSubMenu { verifyDefaultSearchEngineHeader() @@ -86,10 +87,6 @@ class SettingsBasicsTest { verifyAutomaticFontSizingMenuItems() }.goBack { // drill down to submenu - }.openDefaultBrowserSubMenu { - // verify item: set as default browser (duplicates, verify child of recyclerview) - // Verify label: Open links in private tab - }.goBack { } } @@ -213,11 +210,9 @@ class SettingsBasicsTest { homeScreen { }.openThreeDotMenu { }.openSettings { - }.openDefaultBrowserSubMenu { - verifyDefaultBrowserIsDisabled() + verifyDefaultBrowserIsDisaled() clickDefaultBrowserSwitch() verifyAndroidDefaultAppsMenuAppears() } - } } 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 7db6e059f..fe2db165c 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 @@ -14,6 +14,7 @@ import androidx.test.espresso.contrib.RecyclerViewActions import androidx.test.espresso.ViewInteraction import androidx.test.espresso.assertion.ViewAssertions.matches import androidx.test.espresso.intent.Intents.intended +import androidx.test.espresso.intent.matcher.IntentMatchers import androidx.test.espresso.intent.matcher.IntentMatchers.toPackage import androidx.test.espresso.matcher.ViewMatchers import androidx.test.espresso.matcher.ViewMatchers.Visibility @@ -34,6 +35,7 @@ import org.mozilla.fenix.helpers.TestAssetHelper.waitingTime import org.mozilla.fenix.helpers.TestHelper.scrollToElementByText import org.mozilla.fenix.helpers.assertIsEnabled import org.mozilla.fenix.helpers.click +import org.mozilla.fenix.ui.robots.SettingsRobot.Companion.DEFAULT_APPS_SETTINGS_ACTION /** * Implementation of Robot Pattern for the settings menu. @@ -48,6 +50,10 @@ class SettingsRobot { fun verifyThemeSelected() = assertThemeSelected() fun verifyAccessibilityButton() = assertAccessibilityButton() fun verifySetAsDefaultBrowserButton() = assertSetAsDefaultBrowserButton() + fun verifyDefaultBrowserItem() = assertDefaultBrowserItem() + fun verifyDefaultBrowserIsDisaled() = assertDefaultBrowserIsDisabled() + fun clickDefaultBrowserSwitch() = toggleDefaultBrowserSwitch() + fun verifyAndroidDefaultAppsMenuAppears() = assertAndroidDefaultAppsMenuAppears() // PRIVACY SECTION fun verifyPrivacyHeading() = assertPrivacyHeading() @@ -128,15 +134,6 @@ class SettingsRobot { return SettingsSubMenuAccessibilityRobot.Transition() } - fun openDefaultBrowserSubMenu(interact: SettingsSubMenuDefaultBrowserRobot.() -> Unit): SettingsSubMenuDefaultBrowserRobot.Transition { - - fun defaultBrowserButton() = onView(withText("Set as default browser")) - defaultBrowserButton().click() - - SettingsSubMenuDefaultBrowserRobot().interact() - return SettingsSubMenuDefaultBrowserRobot.Transition() - } - fun openEnhancedTrackingProtectionSubMenu(interact: SettingsSubMenuEnhancedTrackingProtectionRobot.() -> Unit): SettingsSubMenuEnhancedTrackingProtectionRobot.Transition { fun enhancedTrackingProtectionButton() = onView(withText("Enhanced Tracking Protection")) @@ -208,6 +205,10 @@ class SettingsRobot { return SettingsSubMenuDataCollectionRobot.Transition() } } + + companion object { + const val DEFAULT_APPS_SETTINGS_ACTION = "android.settings.MANAGE_DEFAULT_APPS_SETTINGS" + } } private fun assertSettingsView() { @@ -241,6 +242,31 @@ private fun assertSetAsDefaultBrowserButton() = onView(withText("Set as default browser")) .check(matches(withEffectiveVisibility(Visibility.VISIBLE))) +private fun assertDefaultBrowserIsDisabled() { + onView(withId(R.id.switch_widget)) + .check(matches(ViewMatchers.isNotChecked())) +} + +private fun toggleDefaultBrowserSwitch() { + onView( + CoreMatchers.allOf( + ViewMatchers.withParent(CoreMatchers.not(withId(R.id.navigationToolbar))), + withText("Set as default browser") + ) + ) + .perform(ViewActions.click()) +} + +private fun assertAndroidDefaultAppsMenuAppears() { + intended(IntentMatchers.hasAction(DEFAULT_APPS_SETTINGS_ACTION)) +} + +private fun assertDefaultBrowserItem() { + mDevice.wait(Until.findObject(By.text("Set as default browser")), waitingTime) + onView(withText("Set as default browser")) + .check(matches(withEffectiveVisibility(Visibility.VISIBLE))) +} + // PRIVACY SECTION private fun assertPrivacyHeading() { onView(withText("Privacy and security")) diff --git a/app/src/androidTest/java/org/mozilla/fenix/ui/robots/SettingsSubMenuDefaultBrowserRobot.kt b/app/src/androidTest/java/org/mozilla/fenix/ui/robots/SettingsSubMenuDefaultBrowserRobot.kt deleted file mode 100644 index 9ba16af96..000000000 --- a/app/src/androidTest/java/org/mozilla/fenix/ui/robots/SettingsSubMenuDefaultBrowserRobot.kt +++ /dev/null @@ -1,72 +0,0 @@ -/* This Source Code Form is subject to the terms of the Mozilla Public - * License, v. 2.0. If a copy of the MPL was not distributed with this - * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ - -@file:Suppress("TooManyFunctions") - -package org.mozilla.fenix.ui.robots - -import androidx.test.espresso.Espresso.onView -import androidx.test.espresso.action.ViewActions.click -import androidx.test.espresso.assertion.ViewAssertions.matches -import androidx.test.espresso.intent.Intents.intended -import androidx.test.espresso.intent.matcher.IntentMatchers.hasAction -import androidx.test.espresso.matcher.ViewMatchers.isNotChecked -import androidx.test.espresso.matcher.ViewMatchers.withContentDescription -import androidx.test.espresso.matcher.ViewMatchers.withId -import androidx.test.espresso.matcher.ViewMatchers.withParent -import androidx.test.espresso.matcher.ViewMatchers.withText -import androidx.test.platform.app.InstrumentationRegistry -import androidx.test.uiautomator.UiDevice -import org.hamcrest.CoreMatchers.allOf -import org.hamcrest.CoreMatchers.not -import org.mozilla.fenix.R -import org.mozilla.fenix.ui.robots.SettingsSubMenuDefaultBrowserRobot.Companion.DEFAULT_APPS_SETTINGS_ACTION - -/** - * Implementation of Robot Pattern for the settings DefaultBrowser sub menu. - */ -class SettingsSubMenuDefaultBrowserRobot { - - companion object { - const val DEFAULT_APPS_SETTINGS_ACTION = "android.settings.MANAGE_DEFAULT_APPS_SETTINGS" - } - - fun verifyDefaultBrowserIsDisabled() = assertDefaultBrowserIsDisabled() - fun clickDefaultBrowserSwitch() = toggleDefaultBrowserSwitch() - fun verifyAndroidDefaultAppsMenuAppears() = assertAndroidDefaultAppsMenuAppears() - - class Transition { - val mDevice = UiDevice.getInstance(InstrumentationRegistry.getInstrumentation()) - - fun goBack(interact: SettingsRobot.() -> Unit): SettingsRobot.Transition { - mDevice.waitForIdle() - goBackButton().perform(click()) - - SettingsRobot().interact() - return SettingsRobot.Transition() - } - } -} - -fun assertDefaultBrowserIsDisabled() { - onView(withId(R.id.switch_widget)) - .check(matches(isNotChecked())) -} - -fun toggleDefaultBrowserSwitch() { - onView( - allOf( - withParent(not(withId(R.id.navigationToolbar))), - withText("Set as default browser") - ) - ) - .perform(click()) -} - -private fun assertAndroidDefaultAppsMenuAppears() { - intended(hasAction(DEFAULT_APPS_SETTINGS_ACTION)) -} - -private fun goBackButton() = - onView(allOf(withContentDescription("Navigate up")))