2
0
mirror of https://github.com/fork-maintainers/iceraven-browser synced 2024-11-15 18:12:54 +00:00

[fenix] Issue https://github.com/mozilla-mobile/fenix/issues/27522: Search groups tests refactoring

This commit is contained in:
oana.horvath 2022-11-01 17:56:37 +02:00 committed by mergify[bot]
parent 4daa618db6
commit 74c551336e
3 changed files with 35 additions and 71 deletions

View File

@ -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()

View File

@ -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()

View File

@ -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(
val tab = mDevice.findObject(
UiSelector()
.resourceId("$packageName:id/mozac_browser_tabstray_title")
.textContains(title),
title,
true,
.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()