From f91285881d0b316daa7a360c6bab0d43224bb5b3 Mon Sep 17 00:00:00 2001 From: AndiAJ Date: Mon, 8 Nov 2021 15:05:53 +0200 Subject: [PATCH] Improve homeThreeDotMenuItemsTest UI test coverage --- .../mozilla/fenix/ui/ThreeDotMenuMainTest.kt | 5 ++ .../ui/robots/SettingsSubMenuHomepageRobot.kt | 79 ++++++++++++++++++- .../fenix/ui/robots/ThreeDotMenuMainRobot.kt | 32 ++++++++ .../taskcluster/androidTest/flank-x86.yml | 1 + 4 files changed, 114 insertions(+), 3 deletions(-) diff --git a/app/src/androidTest/java/org/mozilla/fenix/ui/ThreeDotMenuMainTest.kt b/app/src/androidTest/java/org/mozilla/fenix/ui/ThreeDotMenuMainTest.kt index ac0d9e7da..45d1b41f5 100644 --- a/app/src/androidTest/java/org/mozilla/fenix/ui/ThreeDotMenuMainTest.kt +++ b/app/src/androidTest/java/org/mozilla/fenix/ui/ThreeDotMenuMainTest.kt @@ -54,11 +54,16 @@ class ThreeDotMenuMainTest { verifyDesktopSite() verifyWhatsNewButton() verifyHelpButton() + verifyCustomizeHomeButton() verifySettingsButton() }.openSettings { verifySettingsView() }.goBack { }.openThreeDotMenu { + }.openCustomizeHome { + verifyHomePageView() + }.goBack { + }.openThreeDotMenu { }.openHelp { verifyHelpUrl() }.openTabDrawer { diff --git a/app/src/androidTest/java/org/mozilla/fenix/ui/robots/SettingsSubMenuHomepageRobot.kt b/app/src/androidTest/java/org/mozilla/fenix/ui/robots/SettingsSubMenuHomepageRobot.kt index df9ab6036..fd6502d37 100644 --- a/app/src/androidTest/java/org/mozilla/fenix/ui/robots/SettingsSubMenuHomepageRobot.kt +++ b/app/src/androidTest/java/org/mozilla/fenix/ui/robots/SettingsSubMenuHomepageRobot.kt @@ -1,7 +1,11 @@ package org.mozilla.fenix.ui.robots import androidx.test.espresso.Espresso.onView +import androidx.test.espresso.assertion.ViewAssertions.matches +import androidx.test.espresso.matcher.ViewMatchers.Visibility import androidx.test.espresso.matcher.ViewMatchers.hasSibling +import androidx.test.espresso.matcher.ViewMatchers.withContentDescription +import androidx.test.espresso.matcher.ViewMatchers.withEffectiveVisibility import androidx.test.espresso.matcher.ViewMatchers.withId import androidx.test.espresso.matcher.ViewMatchers.withText import org.hamcrest.CoreMatchers.allOf @@ -13,11 +17,46 @@ import org.mozilla.fenix.helpers.click */ class SettingsSubMenuHomepageRobot { + fun verifyHomePageView() { + assertMostVisitedTopSitesButton() + assertJumpBackInButton() + assertRecentBookmarksButton() + assertRecentSearchesButton() + assertPocketButton() + assertOpeningScreenHeading() + assertHomepageButton() + assertLastTabButton() + assertHomepageAfterFourHoursButton() + } + fun clickStartOnHomepageButton() = homepageButton().click() - class Transition + class Transition { + + fun goBack(interact: HomeScreenRobot.() -> Unit): HomeScreenRobot.Transition { + goBackButton().click() + + HomeScreenRobot().interact() + return HomeScreenRobot.Transition() + } + } } +private fun mostVisitedTopSitesButton() = + onView(allOf(withText(R.string.top_sites_toggle_top_recent_sites_3))) + +private fun jumpBackInButton() = + onView(allOf(withText(R.string.customize_toggle_jump_back_in))) + +private fun recentBookmarksButton() = + onView(allOf(withText(R.string.customize_toggle_recent_bookmarks))) + +private fun recentSearchesButton() = + onView(allOf(withText(R.string.customize_toggle_recent_searches))) + +private fun pocketButton() = + onView(allOf(withText(R.string.customize_toggle_pocket))) + private fun openingScreenHeading() = onView(withText(R.string.preferences_opening_screen)) private fun homepageButton() = @@ -29,7 +68,41 @@ private fun homepageButton() = ) ) -private fun lastTabButton() = onView(withText(R.string.opening_screen_last_tab)) +private fun lastTabButton() = + onView( + allOf( + withId(R.id.title), + withText(R.string.opening_screen_last_tab), + hasSibling(withId(R.id.radio_button)) + ) + ) private fun homepageAfterFourHoursButton() = - onView(withText(R.string.opening_screen_after_four_hours_of_inactivity)) + onView( + allOf( + withId(R.id.title), + withText(R.string.opening_screen_after_four_hours_of_inactivity), + hasSibling(withId(R.id.radio_button)) + ) + ) + +private fun goBackButton() = onView(allOf(withContentDescription(R.string.action_bar_up_description))) + +private fun assertMostVisitedTopSitesButton() = + mostVisitedTopSitesButton().check(matches(withEffectiveVisibility(Visibility.VISIBLE))) +private fun assertJumpBackInButton() = + jumpBackInButton().check(matches(withEffectiveVisibility(Visibility.VISIBLE))) +private fun assertRecentBookmarksButton() = + recentBookmarksButton().check(matches(withEffectiveVisibility(Visibility.VISIBLE))) +private fun assertRecentSearchesButton() = + recentSearchesButton().check(matches(withEffectiveVisibility(Visibility.VISIBLE))) +private fun assertPocketButton() = + pocketButton().check(matches(withEffectiveVisibility(Visibility.VISIBLE))) +private fun assertOpeningScreenHeading() = + openingScreenHeading().check(matches(withEffectiveVisibility(Visibility.VISIBLE))) +private fun assertHomepageButton() = + homepageButton().check(matches(withEffectiveVisibility(Visibility.VISIBLE))) +private fun assertLastTabButton() = + lastTabButton().check(matches(withEffectiveVisibility(Visibility.VISIBLE))) +private fun assertHomepageAfterFourHoursButton() = + homepageAfterFourHoursButton().check(matches(withEffectiveVisibility(Visibility.VISIBLE))) diff --git a/app/src/androidTest/java/org/mozilla/fenix/ui/robots/ThreeDotMenuMainRobot.kt b/app/src/androidTest/java/org/mozilla/fenix/ui/robots/ThreeDotMenuMainRobot.kt index ec2e70dfb..a30ea040f 100644 --- a/app/src/androidTest/java/org/mozilla/fenix/ui/robots/ThreeDotMenuMainRobot.kt +++ b/app/src/androidTest/java/org/mozilla/fenix/ui/robots/ThreeDotMenuMainRobot.kt @@ -49,6 +49,7 @@ class ThreeDotMenuMainRobot { fun verifyShareAllTabsButton() = assertShareAllTabsButton() fun clickShareAllTabsButton() = shareAllTabsButton().click() fun verifySettingsButton() = assertSettingsButton() + fun verifyCustomizeHomeButton() = assertCustomizeHomeButton() fun verifyAddOnsButton() = assertAddOnsButton() fun verifyHistoryButton() = assertHistoryButton() fun verifyBookmarksButton() = assertBookmarksButton() @@ -202,6 +203,26 @@ class ThreeDotMenuMainRobot { return BrowserRobot.Transition() } + fun openCustomizeHome(interact: SettingsSubMenuHomepageRobot.() -> Unit): SettingsSubMenuHomepageRobot.Transition { + + mDevice.wait( + Until + .findObject( + By.textContains("$packageName:id/browser_menu_customize_home") + ), + waitingTime + ) + + customizeHomeButton().click() + + mDevice.findObject( + UiSelector().resourceId("$packageName:id/recycler_view") + ).waitForExists(waitingTime) + + SettingsSubMenuHomepageRobot().interact() + return SettingsSubMenuHomepageRobot.Transition() + } + fun goForward(interact: BrowserRobot.() -> Unit): BrowserRobot.Transition { forwardButton().click() @@ -357,6 +378,17 @@ private fun threeDotMenuRecyclerViewExists() { private fun settingsButton() = mDevice.findObject(UiSelector().text("Settings")) private fun assertSettingsButton() = assertTrue(settingsButton().waitForExists(waitingTime)) +private fun customizeHomeButton() = + onView( + allOf( + withId(R.id.text), + withText(R.string.browser_menu_customize_home) + ) + ) + +private fun assertCustomizeHomeButton() = + customizeHomeButton().check(matches(withEffectiveVisibility(Visibility.VISIBLE))) + private fun addOnsButton() = onView(allOf(withText("Add-ons"))) private fun assertAddOnsButton() { onView(withId(R.id.mozac_browser_menu_menuView)).perform(swipeDown()) diff --git a/automation/taskcluster/androidTest/flank-x86.yml b/automation/taskcluster/androidTest/flank-x86.yml index 5c3761aed..8ea8f47f5 100644 --- a/automation/taskcluster/androidTest/flank-x86.yml +++ b/automation/taskcluster/androidTest/flank-x86.yml @@ -44,6 +44,7 @@ gcloud: device: - model: Pixel2 version: 28 + locale: en_US flank: project: GOOGLE_PROJECT