Убедитесь, что браузер был открыт (тест uiautomator / espresso) - PullRequest
0 голосов
/ 02 марта 2020

Я использую тест 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
  }
}

Как проверить, что браузер был открыт после нажатия на ссылку? Какое утверждение я могу использовать здесь?

1 Ответ

0 голосов
/ 02 марта 2020

Нашел это решение:

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