Re-write toggleSearchBookmarksAndHistoryTest

upstream-sync
Oana Horvath 2 years ago committed by mergify[bot]
parent 143df5251f
commit f45c5876dc

@ -1,8 +1,6 @@
package org.mozilla.fenix.ui
import androidx.compose.ui.test.junit4.AndroidComposeTestRule
import androidx.test.platform.app.InstrumentationRegistry
import androidx.test.uiautomator.UiDevice
import okhttp3.mockwebserver.MockWebServer
import org.junit.After
import org.junit.Before
@ -19,7 +17,6 @@ import org.mozilla.fenix.ui.robots.homeScreen
import org.mozilla.fenix.ui.robots.navigationToolbar
class SettingsSearchTest {
private val mDevice = UiDevice.getInstance(InstrumentationRegistry.getInstrumentation())
private lateinit var mockWebServer: MockWebServer
private val featureSettingsHelper = FeatureSettingsHelper()
@ -72,31 +69,52 @@ class SettingsSearchTest {
}
@Test
fun toggleShowVisitedSitesAndBookmarks() {
// Bookmarks a few websites, toggles the history and bookmarks setting to off, then verifies if the visited and bookmarked websites do not show in the suggestions.
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)
val page3 = getGenericAsset(mockWebServer, 3)
homeScreen {
}.openNavigationToolbar {
navigationToolbar {
}.enterURLAndEnterToBrowser(page1.url) {
verifyUrl(page1.url.toString())
}.openThreeDotMenu {
}.bookmarkPage { }
}.bookmarkPage {
}.openTabDrawer {
closeTab()
}
navigationToolbar {
}.enterURLAndEnterToBrowser(page2.url) {
verifyUrl(page2.url.toString())
}.openThreeDotMenu {
}.bookmarkPage { }
navigationToolbar {
}.enterURLAndEnterToBrowser(page3.url) {
mDevice.waitForIdle()
}.bookmarkPage {
}.openTabDrawer {
closeTab()
}
navigationToolbar {
verifyNoHistoryBookmarks()
// Verifies that bookmarks & history suggestions are shown
homeScreen {
}.openSearch {
typeSearch("test")
expandSearchSuggestionsList()
verifySearchEngineSuggestionResults(activityTestRule, "Test_Page_1")
verifySearchEngineSuggestionResults(activityTestRule, "Test_Page_2")
}.dismissSearchBar {
}.openThreeDotMenu {
}.openSettings {
}.openSearchSubMenu {
// Disables the search bookmarks & history settings
verifySearchBookmarks()
switchSearchBookmarksToggle()
switchSearchHistoryToggle()
exitMenu()
}
// Verifies that bookmarks and history suggestions are not shown
homeScreen {
}.openSearch {
typeSearch("test")
expandSearchSuggestionsList()
verifyNoSuggestionsAreDisplayed(activityTestRule, "Test_Page_1")
verifyNoSuggestionsAreDisplayed(activityTestRule, "Test_Page_2")
}
}

@ -200,6 +200,10 @@ class SearchRobot {
pasteText.click()
}
fun expandSearchSuggestionsList() {
awesomeBar.swipeUp(2)
}
fun verifyPastedToolbarText(expectedText: String) = assertPastedToolbarText(expectedText)
class Transition {
@ -284,7 +288,7 @@ private fun assertSearchEngineURL(searchEngineName: String) {
TestAssetHelper.waitingTime
)
onView(allOf(withText(startsWith("${searchEngineName.lowercase()}.com"))))
.check(matches(ViewMatchers.withEffectiveVisibility(ViewMatchers.Visibility.VISIBLE)))
.check(matches(withEffectiveVisibility(ViewMatchers.Visibility.VISIBLE)))
}
private fun assertSearchEngineResults(rule: ComposeTestRule, searchEngineName: String, count: Int) {
@ -303,21 +307,19 @@ private fun assertSearchEngineResults(rule: ComposeTestRule, searchEngineName: S
private fun assertSearchEngineSuggestionResults(rule: ComposeTestRule, searchResult: String) {
rule.waitForIdle()
mDevice.waitForObjects(
mDevice.findObject(
UiSelector().textContains(searchResult)
)
assertTrue(
mDevice.findObject(UiSelector().textContains(searchResult))
.waitForExists(waitingTime)
)
rule.onNodeWithText(searchResult)
.assertExists()
}
private fun assertNoSuggestionsAreDisplayed(rule: ComposeTestRule, searchTerm: String) {
rule.waitForIdle()
rule.onNodeWithText(searchTerm)
.assertDoesNotExist()
assertFalse(
mDevice.findObject(UiSelector().textContains(searchTerm))
.waitForExists(waitingTime)
)
}
private fun assertSearchView() =
@ -350,11 +352,11 @@ private fun assertSearchButton() =
private fun assertSearchWithText() =
onView(allOf(withText("THIS TIME, SEARCH WITH:")))
.check(matches(ViewMatchers.withEffectiveVisibility(ViewMatchers.Visibility.VISIBLE)))
.check(matches(withEffectiveVisibility(ViewMatchers.Visibility.VISIBLE)))
private fun assertSearchSettings() =
onView(allOf(withText("Default search engine")))
.check(matches(ViewMatchers.withEffectiveVisibility(ViewMatchers.Visibility.VISIBLE)))
.check(matches(withEffectiveVisibility(ViewMatchers.Visibility.VISIBLE)))
private fun assertSearchBarEmpty() =
assertTrue(
@ -466,4 +468,7 @@ private fun assertPastedToolbarText(expectedText: String) {
).check(matches(withEffectiveVisibility(ViewMatchers.Visibility.VISIBLE)))
}
private val awesomeBar =
mDevice.findObject(UiSelector().resourceId("$packageName:id/mozac_browser_toolbar_edit_url_view"))
private val voiceSearchButton = mDevice.findObject(UiSelector().description("Voice search"))

@ -49,6 +49,7 @@ class SettingsSubMenuSearchRobot {
selectSearchEngine(searchEngineName)
fun disableShowSearchSuggestions() = toggleShowSearchSuggestions()
fun enableShowSearchShortcuts() = toggleShowSearchShortcuts()
fun toggleVoiceSearch() {
@ -60,6 +61,24 @@ class SettingsSubMenuSearchRobot {
onView(withText("Show voice search")).perform(click())
}
fun switchSearchHistoryToggle() {
onView(withId(androidx.preference.R.id.recycler_view)).perform(
RecyclerViewActions.scrollTo<RecyclerView.ViewHolder>(
hasDescendant(withText("Search browsing history"))
)
)
searchHistoryToggle.click()
}
fun switchSearchBookmarksToggle() {
onView(withId(androidx.preference.R.id.recycler_view)).perform(
RecyclerViewActions.scrollTo<RecyclerView.ViewHolder>(
hasDescendant(withText("Search bookmarks"))
)
)
searchBookmarksToggle.click()
}
fun openAddSearchEngineMenu() = addSearchEngineButton().click()
fun verifyAddSearchEngineList() = assertAddSearchEngineList()
@ -230,20 +249,24 @@ private fun assertSearchBrowsingHistory() {
hasDescendant(withText("Search browsing history"))
)
)
onView(withText("Search browsing history"))
searchHistoryToggle
.check(matches(withEffectiveVisibility(ViewMatchers.Visibility.VISIBLE)))
}
private val searchHistoryToggle = onView(withText("Search browsing history"))
private fun assertSearchBookmarks() {
onView(withId(androidx.preference.R.id.recycler_view)).perform(
RecyclerViewActions.scrollTo<RecyclerView.ViewHolder>(
hasDescendant(withText("Search bookmarks"))
)
)
onView(withText("Search bookmarks"))
searchBookmarksToggle
.check(matches(withEffectiveVisibility(ViewMatchers.Visibility.VISIBLE)))
}
private val searchBookmarksToggle = onView(withText("Search bookmarks"))
private fun selectSearchEngine(searchEngine: String) {
onView(withText(searchEngine))
.check(matches(withEffectiveVisibility(ViewMatchers.Visibility.VISIBLE)))

Loading…
Cancel
Save