Skip to content

Instantly share code, notes, and snippets.

@AaronMT
Created June 27, 2019 16:37
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save AaronMT/1ecf15564e8ac5f899493ccd2272e654 to your computer and use it in GitHub Desktop.
Save AaronMT/1ecf15564e8ac5f899493ccd2272e654 to your computer and use it in GitHub Desktop.
* 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.*
import androidx.test.espresso.matcher.ViewMatchers
import androidx.test.platform.app.InstrumentationRegistry
import androidx.test.uiautomator.UiDevice
import org.mozilla.fenix.R
/**
* Implementation of Robot Pattern for the URL toolbar.
*/
class URLBarRobot {
class Transition {
val mDevice = UiDevice.getInstance(InstrumentationRegistry.getInstrumentation())
fun enterURL(url: Uri, interact: BrowserRobot.() -> Unit): BrowserRobot.Transition {
mDevice.waitForIdle()
urlBar().perform(click())
awesomeBar().perform(replaceText(url.toString()), pressImeActionButton())
BrowserRobot().interact()
return BrowserRobot.Transition()
}
}
}
fun URLBar(interact: URLBarRobot.() -> Unit): URLBarRobot.Transition {
URLBarRobot.interact()
return URLBarRobot.Transition()
}
private fun urlBar() = onView(ViewMatchers.withId(R.id.toolbar))
private fun awesomeBar() = onView(ViewMatchers.withId(R.id.mozac_browser_toolbar_edit_url_view))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment