From 74c551336e7dab710e2f634f86a61a1927029c6b Mon Sep 17 00:00:00 2001 From: "oana.horvath" Date: Tue, 1 Nov 2022 17:56:37 +0200 Subject: [PATCH] [fenix] Issue https://github.com/mozilla-mobile/fenix/issues/27522: Search groups tests refactoring --- .../java/org/mozilla/fenix/ui/SearchTest.kt | 79 ++++++------------- .../fenix/ui/robots/HomeScreenRobot.kt | 5 +- .../mozilla/fenix/ui/robots/TabDrawerRobot.kt | 22 +++--- 3 files changed, 35 insertions(+), 71 deletions(-) diff --git a/app/src/androidTest/java/org/mozilla/fenix/ui/SearchTest.kt b/app/src/androidTest/java/org/mozilla/fenix/ui/SearchTest.kt index 2ceda28595..654336b01a 100644 --- a/app/src/androidTest/java/org/mozilla/fenix/ui/SearchTest.kt +++ b/app/src/androidTest/java/org/mozilla/fenix/ui/SearchTest.kt @@ -7,7 +7,6 @@ package org.mozilla.fenix.ui import android.content.Context import android.hardware.camera2.CameraManager import androidx.compose.ui.test.junit4.AndroidComposeTestRule -import androidx.core.net.toUri import androidx.test.espresso.Espresso.openActionBarOverflowOrOptionsMenu import mozilla.components.browser.icons.IconRequest import mozilla.components.browser.icons.generator.DefaultIconGenerator @@ -23,6 +22,7 @@ import org.mozilla.fenix.customannotations.SmokeTest import org.mozilla.fenix.helpers.Constants.PackageName.ANDROID_SETTINGS import org.mozilla.fenix.helpers.HomeActivityTestRule import org.mozilla.fenix.helpers.SearchDispatcher +import org.mozilla.fenix.helpers.TestAssetHelper.getGenericAsset import org.mozilla.fenix.helpers.TestHelper.appContext import org.mozilla.fenix.helpers.TestHelper.assertNativeAppOpens import org.mozilla.fenix.helpers.TestHelper.denyPermission @@ -153,10 +153,11 @@ class SearchTest { @SmokeTest @Test fun searchGroupShowsInRecentlyVisitedTest() { - val firstPage = searchMockServer.url("generic1.html").toString() - val secondPage = searchMockServer.url("generic2.html").toString() + val firstPage = getGenericAsset(searchMockServer, 1) + val secondPage = getGenericAsset(searchMockServer, 2) // setting our custom mockWebServer search URL - val searchString = "http://localhost:${searchMockServer.port}/searchResults.html?search={searchTerms}" + val searchString = + "http://localhost:${searchMockServer.port}/searchResults.html?search={searchTerms}" val customSearchEngine = createSearchEngine( name = "TestSearchEngine", url = searchString, @@ -172,14 +173,10 @@ class SearchTest { clickContextOpenLinkInNewTab() longClickLink("Link 2") clickContextOpenLinkInNewTab() - }.goToHomescreen { - verifyJumpBackInSectionIsDisplayed() - verifyCurrentSearchGroupIsDisplayed(true, "test search", 3) - verifyRecentlyVisitedSearchGroupDisplayed(false, "test search", 3) }.openTabDrawer { - }.openTabFromGroup(firstPage) { + }.openTab(firstPage.title) { }.openTabDrawer { - }.openTabFromGroup(secondPage) { + }.openTab(secondPage.title) { }.openTabDrawer { }.openTabsListThreeDotMenu { }.closeAllTabs { @@ -189,7 +186,7 @@ class SearchTest { @SmokeTest @Test - fun noCurrentSearchGroupFromPrivateBrowsingTest() { + fun noSearchGroupFromPrivateBrowsingTest() { // setting our custom mockWebServer search URL val searchString = "http://localhost:${searchMockServer.port}/searchResults.html?search={searchTerms}" val customSearchEngine = createSearchEngine( @@ -207,7 +204,15 @@ class SearchTest { clickContextOpenLinkInPrivateTab() longClickLink("Link 2") clickContextOpenLinkInPrivateTab() - }.goToHomescreen { + }.openTabDrawer { + }.toggleToPrivateTabs { + }.openTabWithIndex(0) { + }.openTabDrawer { + }.openTabWithIndex(1) { + }.openTabDrawer { + }.openTabsListThreeDotMenu { + }.closeAllTabs { + togglePrivateBrowsingModeOnOff() verifyCurrentSearchGroupIsDisplayed(false, "test search", 3) }.openThreeDotMenu { }.openHistory { @@ -215,50 +220,12 @@ class SearchTest { } } - @SmokeTest - @Test - @Ignore("Failing after compose migration. See: https://github.com/mozilla-mobile/fenix/issues/26087") - fun noRecentlyVisitedSearchGroupInPrivateBrowsingTest() { - val firstPage = searchMockServer.url("generic1.html").toString() - val secondPage = searchMockServer.url("generic2.html").toString() - // setting our custom mockWebServer search URL - val searchString = "http://localhost:${searchMockServer.port}/searchResults.html?search={searchTerms}" - val customSearchEngine = createSearchEngine( - name = "TestSearchEngine", - url = searchString, - icon = DefaultIconGenerator().generate(appContext, IconRequest(searchString)).bitmap, - ) - setCustomSearchEngine(customSearchEngine) - - // Performs a search and opens 2 dummy search results links to create a search group - homeScreen { - }.togglePrivateBrowsingMode() - homeScreen { - }.openSearch { - }.submitQuery("test search") { - longClickLink("Link 1") - clickContextOpenLinkInPrivateTab() - longClickLink("Link 2") - clickContextOpenLinkInPrivateTab() - }.openTabDrawer { - }.openTab(firstPage) { - }.openTabDrawer { - }.openTab(secondPage) { - }.openTabDrawer { - }.openTabsListThreeDotMenu { - }.closeAllTabs { - homeScreen { - }.togglePrivateBrowsingMode() - verifyRecentlyVisitedSearchGroupDisplayed(false, "test search", 3) - } - } - @Ignore("Failure caused by bugs: https://github.com/mozilla-mobile/fenix/issues/23818") @SmokeTest @Test fun deleteItemsFromSearchGroupsHistoryTest() { - val firstPage = searchMockServer.url("generic1.html").toString() - val secondPage = searchMockServer.url("generic2.html").toString() + val firstPage = getGenericAsset(searchMockServer, 1) + val secondPage = getGenericAsset(searchMockServer, 2) // setting our custom mockWebServer search URL val searchString = "http://localhost:${searchMockServer.port}/searchResults.html?search={searchTerms}" val customSearchEngine = createSearchEngine( @@ -277,16 +244,16 @@ class SearchTest { longClickLink("Link 2") clickContextOpenLinkInNewTab() }.openTabDrawer { - }.openTabFromGroup(firstPage) { + }.openTab(firstPage.title) { }.openTabDrawer { - }.openTabFromGroup(secondPage) { + }.openTab(secondPage.title) { }.openTabDrawer { }.openTabsListThreeDotMenu { }.closeAllTabs { verifyRecentlyVisitedSearchGroupDisplayed(true, "test search", 3) }.openRecentlyVisitedSearchGroupHistoryList("test search") { - clickDeleteHistoryButton(firstPage) - longTapSelectItem(secondPage.toUri()) + clickDeleteHistoryButton(firstPage.url.toString()) + longTapSelectItem(secondPage.url) multipleSelectionToolbar { openActionBarOverflowOrOptionsMenu(activityTestRule.activity) clickMultiSelectionDelete() diff --git a/app/src/androidTest/java/org/mozilla/fenix/ui/robots/HomeScreenRobot.kt b/app/src/androidTest/java/org/mozilla/fenix/ui/robots/HomeScreenRobot.kt index bd9e7817d5..20d97d2aa9 100644 --- a/app/src/androidTest/java/org/mozilla/fenix/ui/robots/HomeScreenRobot.kt +++ b/app/src/androidTest/java/org/mozilla/fenix/ui/robots/HomeScreenRobot.kt @@ -192,10 +192,7 @@ class HomeScreenRobot { fun verifyRecentlyVisitedSearchGroupDisplayed(shouldBeDisplayed: Boolean, searchTerm: String, groupSize: Int) { // checks if the search group exists in the Recently visited section if (shouldBeDisplayed) { - recentlyVisitedList.waitForExists(waitingTime) scrollToElementByText("Recently visited") - recentlyVisitedList.getChildByText(UiSelector().text(searchTerm), searchTerm, true) - .waitForExists(waitingTimeShort) assertTrue( mDevice.findObject(UiSelector().text(searchTerm)) .getFromParent(UiSelector().text("$groupSize sites")) @@ -580,7 +577,7 @@ class HomeScreenRobot { } fun openRecentlyVisitedSearchGroupHistoryList(title: String, interact: HistoryRobot.() -> Unit): HistoryRobot.Transition { - val searchGroup = recentlyVisitedList.getChildByText(UiSelector().text(title), title, true) + val searchGroup = mDevice.findObject(UiSelector().text(title)) searchGroup.waitForExists(waitingTimeShort) searchGroup.click() diff --git a/app/src/androidTest/java/org/mozilla/fenix/ui/robots/TabDrawerRobot.kt b/app/src/androidTest/java/org/mozilla/fenix/ui/robots/TabDrawerRobot.kt index c0488b4c9c..89088f6a9e 100644 --- a/app/src/androidTest/java/org/mozilla/fenix/ui/robots/TabDrawerRobot.kt +++ b/app/src/androidTest/java/org/mozilla/fenix/ui/robots/TabDrawerRobot.kt @@ -340,19 +340,19 @@ class TabDrawerRobot { return BrowserRobot.Transition() } - fun openTabFromGroup( - title: String, + // Temporary method to use indexes instead of tab titles, until the compose migration is complete + fun openTabWithIndex( + tabPosition: Int, interact: BrowserRobot.() -> Unit, ): BrowserRobot.Transition { - val tab = UiScrollable(UiSelector().resourceId("$packageName:id/tab_group_list")) - .setAsHorizontalList() - .getChildByText( - UiSelector() - .resourceId("$packageName:id/mozac_browser_tabstray_title") - .textContains(title), - title, - true, - ) + val tab = mDevice.findObject( + UiSelector() + .className("androidx.compose.ui.platform.ComposeView") + .index(tabPosition), + ) + + UiScrollable(UiSelector().resourceId("$packageName:id/tray_list_item")).scrollIntoView(tab) + tab.waitForExists(waitingTime) tab.click() BrowserRobot().interact()