Build Release Snapshot Release

Aggregate Library (Deprecated)

Aggregate library it.czerwinski.android:xpresso has been provided for compatibility reasons. However, its use is strongly discouraged.

Core

Maven Central Sonatype Nexus (Snapshots)

Build Configuration

dependencies {
    androidTestImplementation 'it.czerwinski.android:xpresso-core:1.0'
}

Examples

Launching ActivityScenario

@Test
fun myTestMethod() {
    val scenario = launchTestActivity<MyTestActivity>()
    // […]
}

Type-Aware View Interactions

on<TextView>(withText(R.string.hello_world))
    .check(isDisplayed())

on<Button>()
    .check(isDisplayed(), isEnabled())
    .perform(click())

Custom checks:

on<CheckBox>(withId(R.id.terms_and_conditions))
    .check {
        when (it) {
            is Success -> assertFalse(it.value.isChecked)
            is Failure -> assertTrue(it.exception is NoMatchingViewException)
        }
    }

Perform custom actions:

on<CalendarView>()
    .perform(description = "set date") {
        date = Date().time
    }

Bulk Checks

Perform check on all views in a bulk check:

bulkCheck {
    onView(withId(R.id.my_layout))
    on<CheckBox>()
    on<Button>(withText("OK"))
}.all(isDisplayed())

Assert that any of the views passes the check:

bulkCheckFor<Button> {
    onView(withText("OK"))
    onView(withText("Cancel"))
}.any(isEnabled())

RecyclerView

Maven Central Sonatype Nexus (Snapshots)

Build Configuration

dependencies {
    androidTestImplementation 'it.czerwinski.android:xpresso-recyclerview:1.0'
}

Examples

Interactions With Items Of RecyclerView

onRecyclerView(withId(R.id.list))
    .check(isDisplayed())
    .onItem<MyAdapter.ViewHolder>(position = 0) {
        // Interaction with ViewHolder.itemView
        check(hasDescendant(withText("Actions")))
        perform(click())
    }
    .onItem<MyAdapter.ViewHolder>(position = 1) {
        // Interaction with a descendant of ViewHolder.itemView:
        on<Button>(withText("Actions"))
            .check(isDisplayed())
            .perform(click())
    }