[fenix] Bug 1808282 - Fix flaky toggleSearchBookmarksAndHistoryTest UI test

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

@ -98,53 +98,81 @@ class SettingsSearchTest {
@Test @Test
fun toggleSearchBookmarksAndHistoryTest() { 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 page1 = getGenericAsset(mockWebServer, 1)
val page2 = getGenericAsset(mockWebServer, 2) val page2 = getGenericAsset(mockWebServer, 2)
navigationToolbar { navigationToolbar {
}.enterURLAndEnterToBrowser(page1.url) { }.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()) verifyUrl(page1.url.toString())
}.openThreeDotMenu {
}.bookmarkPage {
}.openTabDrawer { }.openTabDrawer {
closeTab() closeTab()
} }
navigationToolbar { navigationToolbar {
}.enterURLAndEnterToBrowser(page2.url) { }.enterURLAndEnterToBrowser(page2.url) {
verifyUrl(page2.url.toString())
}.openThreeDotMenu { }.openThreeDotMenu {
}.bookmarkPage { }.bookmarkPage {
}.openTabDrawer { }.openTabDrawer {
closeTab() closeTab()
} }
// Verifies that bookmarks & history suggestions are shown
homeScreen {
}.openThreeDotMenu {
}.openHistory {
verifyHistoryListExists()
clickDeleteHistoryButton("Test_Page_2")
}
exitMenu()
homeScreen { homeScreen {
}.openSearch { }.openSearch {
typeSearch("test") typeSearch("test")
expandSearchSuggestionsList() verifyFirefoxSuggestResults(
verifyFirefoxSuggestResults(activityTestRule, "Firefox Suggest") activityTestRule,
verifyFirefoxSuggestResults(activityTestRule, "Test_Page_1") "test",
verifyFirefoxSuggestResults(activityTestRule, "Test_Page_2") "Firefox Suggest",
}.dismissSearchBar { "Test_Page_2",
)
}.clickSearchSuggestion("Test_Page_2") {
verifyUrl(page2.url.toString())
}.openTabDrawer {
closeTab()
}
homeScreen {
}.openThreeDotMenu { }.openThreeDotMenu {
}.openSettings { }.openSettings {
}.openSearchSubMenu { }.openSearchSubMenu {
// Disables the search bookmarks & history settings
verifySearchBookmarks()
switchSearchBookmarksToggle()
switchSearchHistoryToggle() switchSearchHistoryToggle()
exitMenu() switchSearchBookmarksToggle()
} }
// Verifies that bookmarks and history suggestions are not shown
exitMenu()
homeScreen { homeScreen {
}.openSearch { }.openSearch {
typeSearch("test") typeSearch("test")
expandSearchSuggestionsList() verifyNoSuggestionsAreDisplayed(
verifyNoSuggestionsAreDisplayed(activityTestRule, "Firefox Suggest") activityTestRule,
verifyNoSuggestionsAreDisplayed(activityTestRule, "Test_Page_1") "Firefox Suggest",
verifyNoSuggestionsAreDisplayed(activityTestRule, "Test_Page_2") "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.isPackageInstalled
import org.mozilla.fenix.helpers.TestHelper.mDevice import org.mozilla.fenix.helpers.TestHelper.mDevice
import org.mozilla.fenix.helpers.TestHelper.packageName import org.mozilla.fenix.helpers.TestHelper.packageName
import org.mozilla.fenix.helpers.TestHelper.waitForObjects
import org.mozilla.fenix.helpers.click 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() rule.waitForIdle()
for (i in 1..RETRY_COUNT) { for (i in 1..RETRY_COUNT) {
try { try {
rule.onNodeWithTag("mozac.awesomebar.suggestions") for (searchSuggestion in searchSuggestions) {
.performScrollToNode(hasText(searchSuggestion)) mDevice.waitForObjects(mDevice.findObject(UiSelector().textContains(searchSuggestion)))
.assertExists() rule.onNodeWithTag("mozac.awesomebar.suggestions")
.performScrollToNode(hasText(searchSuggestion))
.assertExists()
}
break break
} catch (e: AssertionError) { } catch (e: AssertionError) {
if (i == RETRY_COUNT) { if (i == RETRY_COUNT) {
throw e throw e
} else { } else {
expandSearchSuggestionsList() mDevice.pressBack()
homeScreen {
}.openSearch {
typeSearch(searchTerm)
}
} }
} }
} }
} }
fun verifyNoSuggestionsAreDisplayed(rule: ComposeTestRule, searchSuggestion: String) { fun verifyNoSuggestionsAreDisplayed(rule: ComposeTestRule, vararg searchSuggestions: String) {
rule.waitForIdle() rule.waitForIdle()
for (searchSuggestion in searchSuggestions) {
assertFalse( assertFalse(
mDevice.findObject(UiSelector().textContains(searchSuggestion)) mDevice.findObject(UiSelector().textContains(searchSuggestion))
.waitForExists(waitingTime), .waitForExists(waitingTime),
) )
}
} }
fun verifyAllowSuggestionsInPrivateModeDialog() { fun verifyAllowSuggestionsInPrivateModeDialog() {
@ -366,6 +376,16 @@ class SearchRobot {
SettingsSubMenuSearchRobot().interact() SettingsSubMenuSearchRobot().interact()
return SettingsSubMenuSearchRobot.Transition() 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