[fenix] Bug 1808282 - Fix flaky toggleSearchBookmarksAndHistoryTest UI test

pull/600/head
AndiAJ 1 year ago committed by mergify[bot]
parent 318c6035fc
commit 863e8df3c9

@ -98,53 +98,81 @@ class SettingsSearchTest {
@Test
fun toggleSearchBookmarksAndHistoryTest() {
// Bookmarks 2 websites, toggles the bookmarks and history search settings off,
// then verifies if the websites do not show in the suggestions.
val page1 = getGenericAsset(mockWebServer, 1)
val page2 = getGenericAsset(mockWebServer, 2)
navigationToolbar {
}.enterURLAndEnterToBrowser(page1.url) {
}.openTabDrawer {
closeTab()
}
homeScreen {
}.openSearch {
typeSearch("test")
verifyFirefoxSuggestResults(
activityTestRule,
"test",
"Firefox Suggest",
"Test_Page_1",
)
}.clickSearchSuggestion("Test_Page_1") {
verifyUrl(page1.url.toString())
}.openThreeDotMenu {
}.bookmarkPage {
}.openTabDrawer {
closeTab()
}
navigationToolbar {
}.enterURLAndEnterToBrowser(page2.url) {
verifyUrl(page2.url.toString())
}.openThreeDotMenu {
}.bookmarkPage {
}.openTabDrawer {
closeTab()
}
// Verifies that bookmarks & history suggestions are shown
homeScreen {
}.openThreeDotMenu {
}.openHistory {
verifyHistoryListExists()
clickDeleteHistoryButton("Test_Page_2")
}
exitMenu()
homeScreen {
}.openSearch {
typeSearch("test")
expandSearchSuggestionsList()
verifyFirefoxSuggestResults(activityTestRule, "Firefox Suggest")
verifyFirefoxSuggestResults(activityTestRule, "Test_Page_1")
verifyFirefoxSuggestResults(activityTestRule, "Test_Page_2")
}.dismissSearchBar {
verifyFirefoxSuggestResults(
activityTestRule,
"test",
"Firefox Suggest",
"Test_Page_2",
)
}.clickSearchSuggestion("Test_Page_2") {
verifyUrl(page2.url.toString())
}.openTabDrawer {
closeTab()
}
homeScreen {
}.openThreeDotMenu {
}.openSettings {
}.openSearchSubMenu {
// Disables the search bookmarks & history settings
verifySearchBookmarks()
switchSearchBookmarksToggle()
switchSearchHistoryToggle()
exitMenu()
switchSearchBookmarksToggle()
}
// Verifies that bookmarks and history suggestions are not shown
exitMenu()
homeScreen {
}.openSearch {
typeSearch("test")
expandSearchSuggestionsList()
verifyNoSuggestionsAreDisplayed(activityTestRule, "Firefox Suggest")
verifyNoSuggestionsAreDisplayed(activityTestRule, "Test_Page_1")
verifyNoSuggestionsAreDisplayed(activityTestRule, "Test_Page_2")
verifyNoSuggestionsAreDisplayed(
activityTestRule,
"Firefox Suggest",
"Test_Page_1",
"Test_Page_2",
)
}
}

@ -46,6 +46,7 @@ import org.mozilla.fenix.helpers.TestHelper.getStringResource
import org.mozilla.fenix.helpers.TestHelper.isPackageInstalled
import org.mozilla.fenix.helpers.TestHelper.mDevice
import org.mozilla.fenix.helpers.TestHelper.packageName
import org.mozilla.fenix.helpers.TestHelper.waitForObjects
import org.mozilla.fenix.helpers.click
/**
@ -110,31 +111,40 @@ class SearchRobot {
}
}
fun verifyFirefoxSuggestResults(rule: ComposeTestRule, searchSuggestion: String) {
fun verifyFirefoxSuggestResults(rule: ComposeTestRule, searchTerm: String, vararg searchSuggestions: String) {
rule.waitForIdle()
for (i in 1..RETRY_COUNT) {
try {
rule.onNodeWithTag("mozac.awesomebar.suggestions")
.performScrollToNode(hasText(searchSuggestion))
.assertExists()
for (searchSuggestion in searchSuggestions) {
mDevice.waitForObjects(mDevice.findObject(UiSelector().textContains(searchSuggestion)))
rule.onNodeWithTag("mozac.awesomebar.suggestions")
.performScrollToNode(hasText(searchSuggestion))
.assertExists()
}
break
} catch (e: AssertionError) {
if (i == RETRY_COUNT) {
throw e
} else {
expandSearchSuggestionsList()
mDevice.pressBack()
homeScreen {
}.openSearch {
typeSearch(searchTerm)
}
}
}
}
}
fun verifyNoSuggestionsAreDisplayed(rule: ComposeTestRule, searchSuggestion: String) {
fun verifyNoSuggestionsAreDisplayed(rule: ComposeTestRule, vararg searchSuggestions: String) {
rule.waitForIdle()
assertFalse(
mDevice.findObject(UiSelector().textContains(searchSuggestion))
.waitForExists(waitingTime),
)
for (searchSuggestion in searchSuggestions) {
assertFalse(
mDevice.findObject(UiSelector().textContains(searchSuggestion))
.waitForExists(waitingTime),
)
}
}
fun verifyAllowSuggestionsInPrivateModeDialog() {
@ -366,6 +376,16 @@ class SearchRobot {
SettingsSubMenuSearchRobot().interact()
return SettingsSubMenuSearchRobot.Transition()
}
fun clickSearchSuggestion(searchSuggestion: String, interact: BrowserRobot.() -> Unit): BrowserRobot.Transition {
mDevice.findObject(UiSelector().textContains(searchSuggestion)).also {
it.waitForExists(waitingTime)
it.clickAndWaitForNewWindow(waitingTimeShort)
}
BrowserRobot().interact()
return BrowserRobot.Transition()
}
}
}

Loading…
Cancel
Save