有没有办法通过使用 UI-Automator Android 来验证 Google Chrome 选项卡 URL?

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

我尝试了几个选项,但我无法通过 android ui-automator 测试 Google Chrome 选项卡 url .有人可以帮我吗?

让我们假设您在单击按钮时尝试导航至“https://www.abcd.com/xyz”。
(此URL无效。这只是一个示例)

要遵循的步骤:

  1. 在测试中初始化 UiSelector 和 UiDevice class :
    私有 val select = UiSelector()
    私人价值设备= UiDevice.getInstance(InstrumentationRegistry.getInstrumentation())

  2. 点击按钮 : onView(withId(id)).perform(click())

  3. 查找资源 id :
    val urlBar = device.findObject(select.resourceId("com.android.chrome:id/url_bar"))

  4. 断言导航 : assert(urlBar.text.contains("xyz"))