https://github.com/sczerwinski/android-xpresso
Kotlin extensions for Android Espresso testing library
https://github.com/sczerwinski/android-xpresso
android espresso kotlin kotlin-android
Last synced: about 1 month ago
JSON representation
Kotlin extensions for Android Espresso testing library
- Host: GitHub
- URL: https://github.com/sczerwinski/android-xpresso
- Owner: sczerwinski
- License: apache-2.0
- Created: 2018-04-06T08:49:38.000Z (about 7 years ago)
- Default Branch: develop
- Last Pushed: 2020-11-28T20:10:53.000Z (over 4 years ago)
- Last Synced: 2025-03-24T03:34:38.781Z (2 months ago)
- Topics: android, espresso, kotlin, kotlin-android
- Language: Kotlin
- Homepage: https://czerwinski.it/projects/android-xpresso/
- Size: 168 KB
- Stars: 5
- Watchers: 2
- Forks: 0
- Open Issues: 1
-
Metadata Files:
- Readme: README.md
- Changelog: CHANGELOG.md
- License: LICENSE
Awesome Lists containing this project
README
[](https://github.com/sczerwinski/android-xpresso/actions?query=workflow%3ABuild)
[](https://github.com/sczerwinski/android-xpresso/actions?query=workflow%3A%22Release%22)
[](https://github.com/sczerwinski/android-xpresso/actions?query=workflow%3A%22Snapshot+Release%22)# Xpresso: Kotlin Extensions for Android Espresso
## Core
[](https://repo1.maven.org/maven2/it/czerwinski/android/xpresso-core/)
[](https://oss.sonatype.org/content/repositories/snapshots/it/czerwinski/android/xpresso-core/)### Build Configuration
```groovy
dependencies {
androidTestImplementation 'it.czerwinski.android:xpresso-core:1.0'
}
```### Examples
#### Launching `ActivityScenario`
```kotlin
@Test
fun myTestMethod() {
val scenario = launchTestActivity()
// […]
}
```#### Type-Aware View Interactions
```kotlin
on(withText(R.string.hello_world))
.check(isDisplayed())on()
.check(isDisplayed(), isEnabled())
.perform(click())
```Custom checks:
```kotlin
on(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:
```kotlin
on()
.perform(description = "set date") {
date = Date().time
}
```#### Bulk Checks
Perform check on all views in a bulk check:
```kotlin
bulkCheck {
onView(withId(R.id.my_layout))
on()
on(withText("OK"))
}.all(isDisplayed())
```Assert that any of the views passes the check:
```kotlin
bulkCheckFor {
onView(withText("OK"))
onView(withText("Cancel"))
}.any(isEnabled())
```## `RecyclerView`
[](https://repo1.maven.org/maven2/it/czerwinski/android/xpresso-recyclerview/)
[](https://oss.sonatype.org/content/repositories/snapshots/it/czerwinski/android/xpresso-recyclerview/)### Build Configuration
```groovy
dependencies {
androidTestImplementation 'it.czerwinski.android:xpresso-recyclerview:1.0'
}
```### Examples
#### Interactions With Items Of `RecyclerView`
```kotlin
onRecyclerView(withId(R.id.list))
.check(isDisplayed())
.onItem(position = 0) {
// Interaction with ViewHolder.itemView
check(hasDescendant(withText("Actions")))
perform(click())
}
.onItem(position = 1) {
// Interaction with a descendant of ViewHolder.itemView:
on(withText("Actions"))
.check(isDisplayed())
.perform(click())
}
```