我使用自动程序/浓缩咖啡测试来检查以下Web链接并返回到应用程序:
@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 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()
...
}
}