【问题标题】:Check that the browser was open (uiautomator/espresso test)检查浏览器是否打开(uiautomator/espresso 测试)
【发布时间】:2020-03-02 13:33:15
【问题描述】:

我使用 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
  }
}

点击链接后如何查看浏览器是否打开?我可以在这里使用哪个断言?

【问题讨论】:

    标签: android kotlin android-espresso android-uiautomator


    【解决方案1】:

    找到了这个解决方案:

    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()
        ...
      }
    }
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2013-12-28
      • 2023-03-14
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2013-03-20
      • 2015-04-02
      • 1970-01-01
      相关资源
      最近更新 更多