Screens and navigation
Define screens by extending Screen<YourApp> and declaring elements with locator delegates:
class ProductsScreen : Screen<MyAndroidApp>() {
private val title by accessibilityId("title")
private val products by xpaths(
"""//*[@resource-id="${MyAndroidApp.appPackage}:id/productList"]/android.view.ViewGroup""",
)
fun titleText(): String = title.text
}
class ProductDetailsScreen : Screen<MyAndroidApp>() {
private val cartButton by resourceId("cartBt")
fun addToCart() {
cartButton.click()
}
}
Navigate between screens using on:
on(::ProductsScreen) {
titleText() shouldBe "Products"
selectProduct("Backpack")
}.on(::ProductDetailsScreen) {
addToCart()
}
on is the single verb for all screen interactions. The first on call (on AppScope) creates the screen and returns a ScreenScope; subsequent .on(...) calls chain from ScreenScope. Use then to perform additional actions on the current screen without switching screens:
on(::ProductsScreen) {
selectProduct("Backpack")
}.on(::ProductDetailsScreen) {
addToCart()
}.then {
cartBadgeCount() shouldBe 1
proceedToCheckout()
}.on(::CheckoutScreen) {
placeOrder()
}