Android 检查浏览器是否已打开(uiautomator/espresso测试)

Android 检查浏览器是否已打开(uiautomator/espresso测试),android,kotlin,android-espresso,android-uiautomator,Android,Kotlin,Android Espresso,Android Uiautomator,我使用automator/espresso测试来检查以下链接并返回到应用程序: @RunWith(AndroidJUnit4::class) @SdkSuppress(minSdkVersion = 18) class AboutApplicationActivityTest { private lateinit var device: UiDevice @Before fun startMainActivityFromHomeScreen() { device = UiD

我使用automator/espresso测试来检查以下链接并返回到应用程序:

@RunWith(AndroidJUnit4::class)
@SdkSuppress(minSdkVersion = 18)
class AboutApplicationActivityTest {
  private lateinit var device: UiDevice

  @Before
  fun startMainActivityFromHomeScreen() {
    device = UiDevice.getInstance(InstrumentationRegistry.getInstrumentation())
    ...
  }

  @Test
  fun checkLink() {
    val link: UiObject = device.findObject(UiSelector().resourceId("${BASIC_SAMPLE_PACKAGE}:id/link"))
    link.click() // follow the link
    /*
     * How to check that the browser was open after 
     * clicking on the link? Which assertion can I use here? 
     */
    device.pressBack() // back to application
    onView(withId(R.id.link))
      .check(matches(isDisplayed())) // check return to application
  }
}
如何在单击链接后检查浏览器是否已打开?我可以在这里使用哪种断言?

找到了此解决方案:

import com.google.common.truth.Truth.assertThat

@RunWith(AndroidJUnit4::class)
@SdkSuppress(minSdkVersion = 18)
class AboutApplicationActivityTest {    
  ...
  @Test
  fun checkLink() {
    ...
    link.click()
    var currentPackage: String = device.currentPackageName
    assertThat(currentPackage).isEqualTo("com.android.chrome")
    device.pressBack()
    ...
  }
}