Is there a way to verify a Google Chrome tab URL by using UI-Automator Android?

Viewed 170

I have tried a couple of options but I am unable to test the Google Chrome tab url's by android ui-automator. Could someone please help me out here?

1 Answers

Let's assume on click of a button you're trying to navigate to "https://www.abcd.com/xyz".
(This URL is not valid. This is just a sample)

Steps to follow:

  1. Initialise UiSelector and UiDevice in your test class :
    private val select = UiSelector()
    private val device = UiDevice.getInstance(InstrumentationRegistry.getInstrumentation())

  2. Click on the button : onView(withId(id)).perform(click())

  3. Find the resource id :
    val urlBar = device.findObject(select.resourceId("com.android.chrome:id/url_bar"))

  4. Assert the Navigation : assert(urlBar.text.contains("xyz"))

Related