2019-07-16 22:02:12 +02:00
|
|
|
/* This Source Code Form is subject to the terms of the Mozilla Public
|
|
|
|
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
|
|
|
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
|
|
|
|
|
|
|
|
@file:Suppress("TooManyFunctions")
|
|
|
|
|
|
|
|
package org.mozilla.fenix.ui.robots
|
|
|
|
|
|
|
|
import android.net.Uri
|
|
|
|
import androidx.test.espresso.Espresso.onView
|
|
|
|
import androidx.test.espresso.action.ViewActions.pressImeActionButton
|
|
|
|
import androidx.test.espresso.action.ViewActions.replaceText
|
2020-02-06 21:58:47 +01:00
|
|
|
import androidx.test.espresso.action.ViewActions.typeText
|
|
|
|
import androidx.test.espresso.assertion.ViewAssertions.matches
|
|
|
|
import androidx.test.espresso.matcher.ViewMatchers.withId
|
|
|
|
import androidx.test.espresso.matcher.ViewMatchers.hasDescendant
|
|
|
|
import androidx.test.espresso.matcher.ViewMatchers.withText
|
|
|
|
import androidx.test.espresso.matcher.ViewMatchers.withContentDescription
|
2019-07-16 22:02:12 +02:00
|
|
|
import androidx.test.platform.app.InstrumentationRegistry
|
|
|
|
import androidx.test.uiautomator.By
|
|
|
|
import androidx.test.uiautomator.UiDevice
|
|
|
|
import androidx.test.uiautomator.Until
|
2020-02-06 21:58:47 +01:00
|
|
|
import org.hamcrest.CoreMatchers.not
|
2019-07-16 22:02:12 +02:00
|
|
|
import org.mozilla.fenix.R
|
|
|
|
import org.mozilla.fenix.helpers.TestAssetHelper.waitingTime
|
|
|
|
import org.mozilla.fenix.helpers.click
|
2019-10-23 23:40:28 +02:00
|
|
|
import org.mozilla.fenix.helpers.ext.waitNotNull
|
2020-02-06 21:58:47 +01:00
|
|
|
import org.mozilla.fenix.helpers.assertions.AwesomeBarAssertion.Companion.suggestionsAreEqualTo
|
|
|
|
import org.mozilla.fenix.helpers.assertions.AwesomeBarAssertion.Companion.suggestionsAreGreaterThan
|
2019-07-16 22:02:12 +02:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Implementation of Robot Pattern for the URL toolbar.
|
|
|
|
*/
|
|
|
|
class NavigationToolbarRobot {
|
2020-02-06 21:58:47 +01:00
|
|
|
|
|
|
|
fun verifySearchSuggestionsAreMoreThan(suggestionSize: Int, searchTerm: String) =
|
|
|
|
assertSuggestionsAreMoreThan(suggestionSize, searchTerm)
|
|
|
|
|
|
|
|
fun verifySearchSuggestionsAreEqualTo(suggestionSize: Int, searchTerm: String) =
|
|
|
|
assertSuggestionsAreEqualTo(suggestionSize, searchTerm)
|
|
|
|
|
|
|
|
fun verifyNoHistoryBookmarks() = assertNoHistoryBookmarks()
|
|
|
|
|
2019-07-16 22:02:12 +02:00
|
|
|
class Transition {
|
|
|
|
|
|
|
|
val mDevice = UiDevice.getInstance(InstrumentationRegistry.getInstrumentation())
|
|
|
|
|
2020-02-06 21:58:47 +01:00
|
|
|
fun enterURLAndEnterToBrowser(
|
|
|
|
url: Uri,
|
|
|
|
interact: BrowserRobot.() -> Unit
|
|
|
|
): BrowserRobot.Transition {
|
|
|
|
mDevice.waitNotNull(
|
|
|
|
Until.findObject(By.res("org.mozilla.fenix.debug:id/toolbar")),
|
|
|
|
waitingTime
|
|
|
|
)
|
2019-07-16 22:02:12 +02:00
|
|
|
urlBar().click()
|
|
|
|
awesomeBar().perform(replaceText(url.toString()), pressImeActionButton())
|
|
|
|
|
|
|
|
BrowserRobot().interact()
|
|
|
|
return BrowserRobot.Transition()
|
|
|
|
}
|
|
|
|
|
2019-10-03 18:30:55 +02:00
|
|
|
fun openThreeDotMenu(interact: ThreeDotMenuMainRobot.() -> Unit): ThreeDotMenuMainRobot.Transition {
|
2019-10-23 23:40:28 +02:00
|
|
|
mDevice.waitNotNull(Until.findObject(By.descContains("Menu")), waitingTime)
|
2019-07-16 22:02:12 +02:00
|
|
|
threeDotButton().click()
|
|
|
|
|
2019-10-03 18:30:55 +02:00
|
|
|
ThreeDotMenuMainRobot().interact()
|
|
|
|
return ThreeDotMenuMainRobot.Transition()
|
2019-07-16 22:02:12 +02:00
|
|
|
}
|
2019-08-27 19:56:12 +02:00
|
|
|
|
2020-02-06 21:58:47 +01:00
|
|
|
fun openNewTabAndEnterToBrowser(
|
|
|
|
url: Uri,
|
|
|
|
interact: BrowserRobot.() -> Unit
|
|
|
|
): BrowserRobot.Transition {
|
2019-10-23 23:40:28 +02:00
|
|
|
mDevice.waitNotNull(Until.findObject(By.descContains("Add tab")), waitingTime)
|
2019-08-27 19:56:12 +02:00
|
|
|
newTab().click()
|
|
|
|
awesomeBar().perform(replaceText(url.toString()), pressImeActionButton())
|
|
|
|
|
|
|
|
BrowserRobot().interact()
|
|
|
|
return BrowserRobot.Transition()
|
|
|
|
}
|
2020-01-13 18:24:23 +01:00
|
|
|
|
2020-01-31 20:58:02 +01:00
|
|
|
fun visitLinkFromClipboard(interact: BrowserRobot.() -> Unit): BrowserRobot.Transition {
|
2020-01-13 18:24:23 +01:00
|
|
|
mDevice.waitNotNull(
|
|
|
|
Until.findObject(By.res("org.mozilla.fenix.debug:id/mozac_browser_toolbar_clear_view")),
|
|
|
|
waitingTime
|
|
|
|
)
|
|
|
|
clearAddressBar().click()
|
|
|
|
|
|
|
|
mDevice.waitNotNull(
|
2020-01-31 20:58:02 +01:00
|
|
|
Until.findObject(By.res("org.mozilla.fenix.debug:id/clipboard_title")),
|
|
|
|
waitingTime
|
2020-01-13 18:24:23 +01:00
|
|
|
)
|
|
|
|
|
|
|
|
mDevice.waitNotNull(
|
2020-01-31 20:58:02 +01:00
|
|
|
Until.findObject(By.res("org.mozilla.fenix.debug:id/clipboard_url")),
|
2020-01-13 18:24:23 +01:00
|
|
|
waitingTime
|
|
|
|
)
|
|
|
|
fillLinkButton().click()
|
|
|
|
|
|
|
|
BrowserRobot().interact()
|
|
|
|
return BrowserRobot.Transition()
|
|
|
|
}
|
2020-02-06 21:58:47 +01:00
|
|
|
|
|
|
|
fun goBack(interact: HomeScreenRobot.() -> Unit): HomeScreenRobot.Transition {
|
|
|
|
goBackButton()
|
|
|
|
|
|
|
|
HomeScreenRobot().interact()
|
|
|
|
return HomeScreenRobot.Transition()
|
|
|
|
}
|
2019-07-16 22:02:12 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
fun navigationToolbar(interact: NavigationToolbarRobot.() -> Unit): NavigationToolbarRobot.Transition {
|
|
|
|
NavigationToolbarRobot().interact()
|
|
|
|
return NavigationToolbarRobot.Transition()
|
|
|
|
}
|
|
|
|
|
2020-02-06 21:58:47 +01:00
|
|
|
private fun assertSuggestionsAreEqualTo(suggestionSize: Int, searchTerm: String) {
|
|
|
|
mDevice.waitForIdle()
|
|
|
|
awesomeBar().perform(typeText(searchTerm))
|
|
|
|
|
|
|
|
mDevice.waitForIdle()
|
|
|
|
onView(withId(R.id.awesomeBar)).check(suggestionsAreEqualTo(suggestionSize))
|
|
|
|
}
|
|
|
|
|
|
|
|
private fun assertSuggestionsAreMoreThan(suggestionSize: Int, searchTerm: String) {
|
|
|
|
mDevice.waitForIdle()
|
|
|
|
awesomeBar().perform(typeText(searchTerm))
|
|
|
|
|
|
|
|
mDevice.waitForIdle()
|
|
|
|
onView(withId(R.id.awesomeBar)).check(suggestionsAreGreaterThan(suggestionSize))
|
|
|
|
}
|
|
|
|
|
|
|
|
private fun assertNoHistoryBookmarks() {
|
|
|
|
onView(withId(R.id.container))
|
|
|
|
.check(matches(not(hasDescendant(withText("Test_Page_1")))))
|
|
|
|
.check(matches(not(hasDescendant(withText("Test_Page_2")))))
|
|
|
|
.check(matches(not(hasDescendant(withText("Test_Page_3")))))
|
|
|
|
}
|
|
|
|
|
|
|
|
private fun dismissOnboardingButton() = onView(withId(R.id.close_onboarding))
|
|
|
|
private fun urlBar() = onView(withId(R.id.toolbar))
|
|
|
|
private fun awesomeBar() = onView(withId(R.id.mozac_browser_toolbar_edit_url_view))
|
|
|
|
private fun threeDotButton() = onView(withContentDescription("Menu"))
|
|
|
|
private fun newTab() = onView(withContentDescription("Add tab"))
|
|
|
|
private fun fillLinkButton() = onView(withId(R.id.fill_link_from_clipboard))
|
|
|
|
private fun clearAddressBar() = onView(withId(R.id.mozac_browser_toolbar_clear_view))
|
|
|
|
private fun goBackButton() = mDevice.pressBack()
|