Issue
I use the automator/espresso test to check the follow the web link and returning back to the application:
@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
}
}
How to check that the browser was open after clicking on the link? Which assertion can I use here?
Solution
Found this solution:
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()
...
}
}
Answered By - alexrnov
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.