For #112,#145: Verify Search engine can be changed temporarily using Search engine (#13259)
parent
5f5caa4720
commit
cd729b39e5
|
@ -16,6 +16,7 @@ import org.junit.Test
|
|||
import org.mozilla.fenix.helpers.AndroidAssetDispatcher
|
||||
import org.mozilla.fenix.helpers.HomeActivityTestRule
|
||||
import org.mozilla.fenix.helpers.TestAssetHelper
|
||||
import org.mozilla.fenix.ui.robots.clickUrlbar
|
||||
import org.mozilla.fenix.ui.robots.homeScreen
|
||||
import org.mozilla.fenix.ui.robots.navigationToolbar
|
||||
|
||||
|
@ -254,4 +255,69 @@ class SmokeTest {
|
|||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
fun verifySearchEngineCanBeChangedTemporarilyUsingShortcuts() {
|
||||
val defaultWebPage = TestAssetHelper.getGenericAsset(mockWebServer, 1)
|
||||
|
||||
homeScreen {
|
||||
}.openSearch {
|
||||
verifyKeyboardVisibility()
|
||||
clickSearchEngineButton()
|
||||
verifySearchEngineList()
|
||||
changeDefaultSearchEngine("Amazon.com")
|
||||
verifySearchEngineIcon("Amazon.com")
|
||||
}.goToSearchEngine {
|
||||
}.enterURLAndEnterToBrowser(defaultWebPage.url) {
|
||||
}.openTabDrawer {
|
||||
// Changing search engine to Bing
|
||||
}.openHomeScreen {
|
||||
}.openSearch {
|
||||
clickSearchEngineButton()
|
||||
mDevice.waitForIdle()
|
||||
changeDefaultSearchEngine("Bing")
|
||||
verifySearchEngineIcon("Bing")
|
||||
}.goToSearchEngine {
|
||||
}.enterURLAndEnterToBrowser(defaultWebPage.url) {
|
||||
}.openTabDrawer {
|
||||
// Changing search engine to DuckDuckGo
|
||||
}.openHomeScreen {
|
||||
}.openSearch {
|
||||
clickSearchEngineButton()
|
||||
mDevice.waitForIdle()
|
||||
changeDefaultSearchEngine("DuckDuckGo")
|
||||
verifySearchEngineIcon("DuckDuckGo")
|
||||
}.goToSearchEngine {
|
||||
}.enterURLAndEnterToBrowser(defaultWebPage.url) {
|
||||
}.openTabDrawer {
|
||||
// Changing search engine to Twitter
|
||||
}.openHomeScreen {
|
||||
}.openSearch {
|
||||
clickSearchEngineButton()
|
||||
mDevice.waitForIdle()
|
||||
changeDefaultSearchEngine("Twitter")
|
||||
verifySearchEngineIcon("Twitter")
|
||||
}.goToSearchEngine {
|
||||
}.enterURLAndEnterToBrowser(defaultWebPage.url) {
|
||||
}.openTabDrawer {
|
||||
// Changing search engine to Wikipedia
|
||||
}.openHomeScreen {
|
||||
}.openSearch {
|
||||
clickSearchEngineButton()
|
||||
changeDefaultSearchEngine("Wikipedia")
|
||||
verifySearchEngineIcon("Wikipedia")
|
||||
}.goToSearchEngine {
|
||||
}.enterURLAndEnterToBrowser(defaultWebPage.url) {
|
||||
}.openTabDrawer {
|
||||
// Checking whether the next search will be with default or not
|
||||
}.openHomeScreen {
|
||||
}.openSearch {
|
||||
}.goToSearchEngine {
|
||||
}.enterURLAndEnterToBrowser(defaultWebPage.url) {
|
||||
}.openNavigationToolbar {
|
||||
clickUrlbar {
|
||||
verifyDefaultSearchEngine("Google")
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -12,12 +12,14 @@ import android.net.Uri
|
|||
import androidx.test.espresso.Espresso.onView
|
||||
import androidx.test.espresso.Espresso.pressBack
|
||||
import androidx.test.espresso.action.ViewActions
|
||||
import androidx.test.espresso.action.ViewActions.click
|
||||
import androidx.test.espresso.assertion.ViewAssertions.matches
|
||||
import androidx.test.espresso.intent.Intents
|
||||
import androidx.test.espresso.intent.matcher.BundleMatchers
|
||||
import androidx.test.espresso.intent.matcher.IntentMatchers
|
||||
import androidx.test.espresso.matcher.RootMatchers.isDialog
|
||||
import androidx.test.espresso.matcher.ViewMatchers
|
||||
import androidx.test.espresso.matcher.ViewMatchers.withContentDescription
|
||||
import androidx.test.espresso.matcher.ViewMatchers.Visibility
|
||||
import androidx.test.espresso.matcher.ViewMatchers.isCompletelyDisplayed
|
||||
import androidx.test.espresso.matcher.ViewMatchers.isDisplayed
|
||||
|
|
|
@ -239,6 +239,12 @@ fun navigationToolbar(interact: NavigationToolbarRobot.() -> Unit): NavigationTo
|
|||
return NavigationToolbarRobot.Transition()
|
||||
}
|
||||
|
||||
fun clickUrlbar(interact: SearchRobot.() -> Unit): SearchRobot.Transition {
|
||||
urlBar().click()
|
||||
SearchRobot().interact()
|
||||
return SearchRobot.Transition()
|
||||
}
|
||||
|
||||
private fun assertSuggestionsAreEqualTo(suggestionSize: Int, searchTerm: String) {
|
||||
mDevice.waitForIdle()
|
||||
awesomeBar().perform(typeText(searchTerm))
|
||||
|
|
|
@ -6,6 +6,7 @@
|
|||
|
||||
package org.mozilla.fenix.ui.robots
|
||||
|
||||
import android.widget.ToggleButton
|
||||
import androidx.recyclerview.widget.RecyclerView
|
||||
import androidx.test.espresso.Espresso.onView
|
||||
import androidx.test.espresso.ViewInteraction
|
||||
|
@ -16,7 +17,9 @@ import androidx.test.espresso.action.ViewActions.typeText
|
|||
import androidx.test.espresso.assertion.ViewAssertions.matches
|
||||
import androidx.test.espresso.contrib.RecyclerViewActions
|
||||
import androidx.test.espresso.matcher.ViewMatchers
|
||||
import androidx.test.espresso.matcher.ViewMatchers.Visibility
|
||||
import androidx.test.espresso.matcher.ViewMatchers.withContentDescription
|
||||
import androidx.test.espresso.matcher.ViewMatchers.withEffectiveVisibility
|
||||
import androidx.test.espresso.matcher.ViewMatchers.withId
|
||||
import androidx.test.espresso.matcher.ViewMatchers.withText
|
||||
import androidx.test.platform.app.InstrumentationRegistry
|
||||
|
@ -28,8 +31,11 @@ import androidx.test.uiautomator.Until
|
|||
import org.hamcrest.CoreMatchers.allOf
|
||||
import org.hamcrest.CoreMatchers.startsWith
|
||||
import org.hamcrest.Matchers
|
||||
import org.junit.Assert.assertEquals
|
||||
import org.mozilla.fenix.R
|
||||
import org.mozilla.fenix.helpers.TestAssetHelper
|
||||
import org.mozilla.fenix.helpers.TestAssetHelper.waitingTime
|
||||
import org.mozilla.fenix.helpers.click
|
||||
import org.mozilla.fenix.helpers.ext.waitNotNull
|
||||
|
||||
/**
|
||||
|
@ -47,6 +53,24 @@ class SearchRobot {
|
|||
fun verifySearchSettings() = assertSearchSettings()
|
||||
fun verifySearchBarEmpty() = assertSearchBarEmpty()
|
||||
|
||||
fun verifyKeyboardVisibility() = assertKeyboardVisibility(isExpectedToBeVisible = true)
|
||||
fun verifySearchEngineList() = assertSearchEngineList()
|
||||
fun verifySearchEngineIcon(expectedText: String) {
|
||||
onView(withContentDescription(expectedText))
|
||||
}
|
||||
fun verifyDefaultSearchEngine(expectedText: String) = assertDefaultSearchEngine(expectedText)
|
||||
|
||||
fun changeDefaultSearchEngine(searchEngineName: String) =
|
||||
selectDefaultSearchEngine(searchEngineName)
|
||||
|
||||
fun clickSearchEngineButton() {
|
||||
val searchEngineButton = mDevice.findObject(UiSelector()
|
||||
.instance(1)
|
||||
.className(ToggleButton::class.java))
|
||||
searchEngineButton.waitForExists(waitingTime)
|
||||
searchEngineButton.click()
|
||||
}
|
||||
|
||||
fun clickScanButton() {
|
||||
scanButton().perform(click())
|
||||
}
|
||||
|
@ -106,6 +130,11 @@ class SearchRobot {
|
|||
BrowserRobot().interact()
|
||||
return BrowserRobot.Transition()
|
||||
}
|
||||
|
||||
fun goToSearchEngine(interact: NavigationToolbarRobot.() -> Unit): NavigationToolbarRobot.Transition {
|
||||
NavigationToolbarRobot().interact()
|
||||
return NavigationToolbarRobot.Transition()
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -178,4 +207,46 @@ fun searchScreen(interact: SearchRobot.() -> Unit): SearchRobot.Transition {
|
|||
return SearchRobot.Transition()
|
||||
}
|
||||
|
||||
private fun assertKeyboardVisibility(isExpectedToBeVisible: Boolean) = {
|
||||
mDevice.waitNotNull(
|
||||
Until.findObject(
|
||||
By.text("Search Engine")
|
||||
), waitingTime
|
||||
)
|
||||
assertEquals(
|
||||
isExpectedToBeVisible,
|
||||
UiDevice.getInstance(InstrumentationRegistry.getInstrumentation())
|
||||
.executeShellCommand("dumpsys input_method | grep mInputShown")
|
||||
.contains("mInputShown=true")
|
||||
)
|
||||
}
|
||||
|
||||
private fun assertSearchEngineList() {
|
||||
onView(withId(R.id.mozac_browser_toolbar_edit_icon)).click()
|
||||
onView(withText("Google"))
|
||||
.check(matches(withEffectiveVisibility(Visibility.VISIBLE)))
|
||||
onView(withText("Amazon.com"))
|
||||
.check(matches(withEffectiveVisibility(Visibility.VISIBLE)))
|
||||
onView(withText("Bing"))
|
||||
.check(matches(withEffectiveVisibility(Visibility.VISIBLE)))
|
||||
onView(withText("DuckDuckGo"))
|
||||
.check(matches(withEffectiveVisibility(Visibility.VISIBLE)))
|
||||
onView(withText("Twitter"))
|
||||
.check(matches(withEffectiveVisibility(Visibility.VISIBLE)))
|
||||
onView(withText("Wikipedia"))
|
||||
.check(matches(withEffectiveVisibility(Visibility.VISIBLE)))
|
||||
}
|
||||
|
||||
private fun selectDefaultSearchEngine(searchEngine: String) {
|
||||
onView(withId(R.id.mozac_browser_toolbar_edit_icon)).click()
|
||||
onView(withText(searchEngine))
|
||||
.check(matches(withEffectiveVisibility(Visibility.VISIBLE)))
|
||||
.perform(click())
|
||||
}
|
||||
|
||||
private fun assertDefaultSearchEngine(expectedText: String) {
|
||||
onView(allOf(withId(R.id.mozac_browser_toolbar_edit_icon), withContentDescription(expectedText)))
|
||||
.check(matches(withEffectiveVisibility(Visibility.VISIBLE)))
|
||||
}
|
||||
|
||||
private fun goBackButton() = onView(allOf(withContentDescription("Navigate up")))
|
||||
|
|
Loading…
Reference in New Issue