Skip to content

sczerwinski/android-xpresso

develop
Switch branches/tags

Name already in use

A tag already exists with the provided branch name. Many Git commands accept both tag and branch names, so creating this branch may cause unexpected behavior. Are you sure you want to create this branch?
Code

Latest commit

 

Git stats

Files

Permalink
Failed to load latest commit information.
Type
Name
Latest commit message
Commit time
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Build Release Snapshot Release

Xpresso: Kotlin Extensions for Android Espresso

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