From be8ed7b50c6889c6f8e9c50c32683fb7e94407ec Mon Sep 17 00:00:00 2001 From: AndiAJ Date: Wed, 23 Nov 2022 15:38:17 +0200 Subject: [PATCH] [fenix] For https://github.com/mozilla-mobile/fenix/issues/26286 refactor homeScreenItemsTest UI test --- .../java/org/mozilla/fenix/ui/HomeScreenTest.kt | 47 ++++++++------- .../java/org/mozilla/fenix/ui/SmokeTest.kt | 2 +- .../org/mozilla/fenix/ui/TabbedBrowsingTest.kt | 4 +- .../org/mozilla/fenix/ui/robots/HomeScreenRobot.kt | 69 +++++++++++++++++++--- 4 files changed, 91 insertions(+), 31 deletions(-) diff --git a/mobile/android/fenix/app/src/androidTest/java/org/mozilla/fenix/ui/HomeScreenTest.kt b/mobile/android/fenix/app/src/androidTest/java/org/mozilla/fenix/ui/HomeScreenTest.kt index 024398ac5294..45afd1884361 100644 --- a/mobile/android/fenix/app/src/androidTest/java/org/mozilla/fenix/ui/HomeScreenTest.kt +++ b/mobile/android/fenix/app/src/androidTest/java/org/mozilla/fenix/ui/HomeScreenTest.kt @@ -4,6 +4,7 @@ package org.mozilla.fenix.ui +import androidx.compose.ui.test.junit4.AndroidComposeTestRule import androidx.test.platform.app.InstrumentationRegistry import androidx.test.uiautomator.By import androidx.test.uiautomator.UiDevice @@ -35,10 +36,11 @@ class HomeScreenTest { private lateinit var mDevice: UiDevice private lateinit var mockWebServer: MockWebServer - @get:Rule - val activityTestRule = HomeActivityTestRule.withDefaultSettingsOverrides() + @get:Rule(order = 0) + val activityTestRule = + AndroidComposeTestRule(HomeActivityTestRule.withDefaultSettingsOverrides()) { it.activity } - @Rule + @Rule(order = 1) @JvmField val retryTestRule = RetryTestRule(3) @@ -62,21 +64,26 @@ class HomeScreenTest { homeScreen { }.dismissOnboarding() homeScreen { - verifyHomeScreen() - verifyNavigationToolbar() - verifyHomePrivateBrowsingButton() - verifyHomeMenu() verifyHomeWordmark() - verifyTabButton() - verifyCollectionsHeader() - verifyHomeToolbar() - verifyHomeComponent() - - // Verify Top Sites - verifyExistingTopSitesList() + verifyHomePrivateBrowsingButton() verifyExistingTopSitesTabs("Wikipedia") verifyExistingTopSitesTabs("Top Articles") verifyExistingTopSitesTabs("Google") + verifyCollectionsHeader() + verifyNoCollectionsText() + scrollToPocketProvokingStories() + swipePocketProvokingStories() + verifyPocketRecommendedStoriesItems(activityTestRule, 1, 3, 4, 5, 6, 7) + verifyPocketSponsoredStoriesItems(activityTestRule, 2, 8) + verifyDiscoverMoreStoriesButton(activityTestRule, 9) + verifyStoriesByTopicItems() + verifyPoweredByPocket(activityTestRule) + verifyCustomizeHomepageButton(true) + verifyNavigationToolbar() + verifyDefaultSearchEngine("Google") + verifyHomeMenuButton() + verifyTabButton() + verifyNoTabsOpened() } } @@ -89,11 +96,11 @@ class HomeScreenTest { verifyHomeScreen() verifyNavigationToolbar() verifyHomePrivateBrowsingButton() - verifyHomeMenu() + verifyHomeMenuButton() verifyHomeWordmark() verifyTabButton() verifyPrivateSessionMessage() - verifyHomeToolbar() + verifyNavigationToolbar() verifyHomeComponent() }.openCommonMythsLink { verifyUrl("common-myths-about-private-browsing") @@ -107,11 +114,11 @@ class HomeScreenTest { verifyHomeScreen() verifyNavigationToolbar() verifyHomePrivateBrowsingButton() - verifyHomeMenu() + verifyHomeMenuButton() verifyHomeWordmark() verifyTabButton() verifyPrivateSessionMessage() - verifyHomeToolbar() + verifyNavigationToolbar() verifyHomeComponent() } } @@ -144,7 +151,7 @@ class HomeScreenTest { @Test fun dismissOnboardingUsingHelpTest() { - activityTestRule.applySettingsExceptions { + activityTestRule.activityRule.applySettingsExceptions { it.isJumpBackInCFREnabled = false it.isWallpaperOnboardingEnabled = false } @@ -174,7 +181,7 @@ class HomeScreenTest { @Test fun verifyPocketHomepageStoriesTest() { - activityTestRule.applySettingsExceptions { + activityTestRule.activityRule.applySettingsExceptions { it.isRecentTabsFeatureEnabled = false it.isRecentlyVisitedFeatureEnabled = false } diff --git a/mobile/android/fenix/app/src/androidTest/java/org/mozilla/fenix/ui/SmokeTest.kt b/mobile/android/fenix/app/src/androidTest/java/org/mozilla/fenix/ui/SmokeTest.kt index d0a85e27a2d6..c0be137641af 100644 --- a/mobile/android/fenix/app/src/androidTest/java/org/mozilla/fenix/ui/SmokeTest.kt +++ b/mobile/android/fenix/app/src/androidTest/java/org/mozilla/fenix/ui/SmokeTest.kt @@ -115,7 +115,7 @@ class SmokeTest { verifyHomeScreen() verifyNavigationToolbar() verifyHomePrivateBrowsingButton() - verifyHomeMenu() + verifyHomeMenuButton() verifyHomeWordmark() verifyWelcomeHeader() diff --git a/mobile/android/fenix/app/src/androidTest/java/org/mozilla/fenix/ui/TabbedBrowsingTest.kt b/mobile/android/fenix/app/src/androidTest/java/org/mozilla/fenix/ui/TabbedBrowsingTest.kt index 1be55514115a..ed882ffcfd25 100644 --- a/mobile/android/fenix/app/src/androidTest/java/org/mozilla/fenix/ui/TabbedBrowsingTest.kt +++ b/mobile/android/fenix/app/src/androidTest/java/org/mozilla/fenix/ui/TabbedBrowsingTest.kt @@ -354,7 +354,7 @@ class TabbedBrowsingTest { // dismiss search dialog homeScreen { }.pressBack() verifyPrivateSessionMessage() - verifyHomeToolbar() + verifyNavigationToolbar() } navigationToolbar { }.enterURLAndEnterToBrowser(defaultWebPage.url) { @@ -365,7 +365,7 @@ class TabbedBrowsingTest { // dismiss search dialog homeScreen { }.pressBack() verifyHomeWordmark() - verifyHomeToolbar() + verifyNavigationToolbar() } } } diff --git a/mobile/android/fenix/app/src/androidTest/java/org/mozilla/fenix/ui/robots/HomeScreenRobot.kt b/mobile/android/fenix/app/src/androidTest/java/org/mozilla/fenix/ui/robots/HomeScreenRobot.kt index c3d6bf43729e..f8a6d6197dd6 100644 --- a/mobile/android/fenix/app/src/androidTest/java/org/mozilla/fenix/ui/robots/HomeScreenRobot.kt +++ b/mobile/android/fenix/app/src/androidTest/java/org/mozilla/fenix/ui/robots/HomeScreenRobot.kt @@ -8,9 +8,13 @@ package org.mozilla.fenix.ui.robots import android.graphics.Bitmap import android.widget.EditText +import androidx.compose.ui.test.assert import androidx.compose.ui.test.assertIsDisplayed +import androidx.compose.ui.test.hasTestTag import androidx.compose.ui.test.hasText import androidx.compose.ui.test.junit4.ComposeTestRule +import androidx.compose.ui.test.onChildAt +import androidx.compose.ui.test.onNodeWithTag import androidx.compose.ui.test.onNodeWithText import androidx.compose.ui.test.performClick import androidx.recyclerview.widget.RecyclerView @@ -75,12 +79,11 @@ class HomeScreenRobot { fun verifyFocusedNavigationToolbar() = assertFocusedNavigationToolbar() fun verifyHomeScreen() = assertHomeScreen() fun verifyHomePrivateBrowsingButton() = assertHomePrivateBrowsingButton() - fun verifyHomeMenu() = assertHomeMenu() + fun verifyHomeMenuButton() = assertHomeMenuButton() fun verifyTabButton() = assertTabButton() fun verifyCollectionsHeader() = assertCollectionsHeader() fun verifyNoCollectionsText() = assertNoCollectionsText() fun verifyHomeWordmark() = assertHomeWordmark() - fun verifyHomeToolbar() = assertHomeToolbar() fun verifyHomeComponent() = assertHomeComponent() fun verifyDefaultSearchEngine(searchEngine: String) = verifySearchEngineIcon(searchEngine) fun verifyNoTabsOpened() = assertNoTabsOpened() @@ -267,6 +270,39 @@ class HomeScreenRobot { } } + fun scrollToPocketProvokingStories() = + scrollToElementByText(getStringResource(R.string.pocket_stories_categories_header)) + + fun swipePocketProvokingStories() { + UiScrollable(UiSelector().resourceId("pocket.stories")).setAsHorizontalList() + .swipeLeft(3) + } + + fun verifyPocketRecommendedStoriesItems(composeTestRule: ComposeTestRule, vararg positions: Int) { + composeTestRule.onNodeWithTag("pocket.stories").assertIsDisplayed() + positions.forEach { + composeTestRule.onNodeWithTag("pocket.stories") + .onChildAt(it - 1) + .assert(hasTestTag("pocket.recommended.story")) + } + } + + fun verifyPocketSponsoredStoriesItems(composeTestRule: ComposeTestRule, vararg positions: Int) { + composeTestRule.onNodeWithTag("pocket.stories").assertIsDisplayed() + positions.forEach { + composeTestRule.onNodeWithTag("pocket.stories") + .onChildAt(it - 1) + .assert(hasTestTag("pocket.sponsored.story")) + } + } + + fun verifyDiscoverMoreStoriesButton(composeTestRule: ComposeTestRule, position: Int) { + composeTestRule.onNodeWithTag("pocket.stories") + .assertIsDisplayed() + .onChildAt(position - 1) + .assert(hasTestTag("pocket.discover.more.story")) + } + fun verifyStoriesByTopic(enabled: Boolean) { if (enabled) { scrollToElementByText(getStringResource(R.string.pocket_stories_categories_header)) @@ -291,6 +327,15 @@ class HomeScreenRobot { } } + fun verifyStoriesByTopicItems() = + assertTrue(mDevice.findObject(UiSelector().resourceId("pocket.categories")).childCount > 1) + + fun verifyPoweredByPocket(rule: ComposeTestRule) { + homeScreenList().scrollIntoView(mDevice.findObject(UiSelector().resourceId("pocket.header"))) + rule.onNodeWithTag("pocket.header.title", true).assertIsDisplayed() + rule.onNodeWithTag("pocket.header.subtitle", true).assertIsDisplayed() + } + fun verifyCustomizeHomepageButton(enabled: Boolean) { if (enabled) { scrollToElementByText(getStringResource(R.string.browser_menu_customize_home_1)) @@ -619,7 +664,7 @@ private fun assertHomeScreen() { .check(matches(withEffectiveVisibility(Visibility.VISIBLE))) } -private fun assertHomeMenu() = onView(ViewMatchers.withResourceName("menuButton")) +private fun assertHomeMenuButton() = onView(ViewMatchers.withResourceName("menuButton")) .check(matches(withEffectiveVisibility(Visibility.VISIBLE))) private fun assertHomePrivateBrowsingButton() = @@ -630,9 +675,6 @@ private val homepageWordmark = onView(ViewMatchers.withResourceName("wordmark")) private fun assertHomeWordmark() = homepageWordmark.check(matches(withEffectiveVisibility(Visibility.VISIBLE))) -private fun assertHomeToolbar() = onView(ViewMatchers.withResourceName("toolbar")) - .check(matches(withEffectiveVisibility(Visibility.VISIBLE))) - private fun assertTabButton() = onView(allOf(withId(R.id.tab_button), isDisplayed())) .check(matches(withEffectiveVisibility(Visibility.VISIBLE))) @@ -668,9 +710,9 @@ private fun getSearchEngine(searchEngineName: String) = appContext.components.core.store.state.search.searchEngines.find { it.name == searchEngineName } private fun verifySearchEngineIcon(searchEngineName: String) { - val ddgSearchEngine = getSearchEngine(searchEngineName) + val defaultSearchEngine = getSearchEngine(searchEngineName) ?: throw AssertionError("No search engine with name $searchEngineName") - verifySearchEngineIcon(ddgSearchEngine.icon, ddgSearchEngine.name) + verifySearchEngineIcon(defaultSearchEngine.icon, defaultSearchEngine.name) } // First Run elements @@ -949,6 +991,17 @@ private fun sponsoredShortcut(sponsoredShortcutTitle: String) = .textContains(sponsoredShortcutTitle), ) +private fun discoverMoreStoriesButton(position: Int) = + mDevice + .findObject( + UiSelector() + .resourceId("pocket.stories"), + ).getChild( + UiSelector() + .resourceId("pocket.discover.more.story") + .index(position - 1), + ) + val deleteFromHistory = onView( allOf( -- 2.11.4.GIT