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