SkillAgentSearch skills...

Kaspresso

Android UI test framework

Install / Use

/learn @KasperskyLab/Kaspresso

README

Android Arsenal Android Weekly Android Weekly MavenCentral Build and Deploy Telegram Telegram Discord

Kaspresso

Kaspresso is a framework for Android UI testing. Based on Espresso and UI Automator, Kaspresso provides a wide range of additional features, such as:

  • Built-in protection against flaky tests
  • Jetpack Compose support
  • Screenshot testing with native approach (with dark mode support)
  • Declarative approach for writing tests
  • Ability to interact with other applications and system elements and interfaces
  • Human readability with Kotlin DSL wrappers over UiAutomator and Espresso
  • Detailed logs and reports (logs, view hierarchy, screenshots, video etc.)
  • ADB support
  • Allure support
  • Robolectric support
  • Easy migration from Espresso
  • Flexible configuration options
  • Automatic artifacts pulling after tests execution
  • Significantly faster execution of UI Automator commands. With Kaspresso, some UI Automator commands run 10 times faster!
  • Page object pattern from the box

And many more!

<img src="kaspresso.png" alt="Kaspresso"/> <details> <summary>

Integration

</summary>

To integrate Kaspresso into your project:

  1. If the mavenCentral repository does not exist, include it to your root build.gradle file:
allprojects {
    repositories {
        mavenCentral()
    }
}
  1. Add a dependency to build.gradle:
dependencies {
    androidTestImplementation 'com.kaspersky.android-components:kaspresso:<latest_version>'
    // Allure support
    androidTestImplementation "com.kaspersky.android-components:kaspresso-allure-support:<latest_version>"
    // Jetpack Compose support
    androidTestImplementation "com.kaspersky.android-components:kaspresso-compose-support:<latest_version>"
}

To try out the cutting edge kaspresso updates before an official release add a snapshot repository to your build.gradle

dependencyResolutionManagement {
    repositories {
        maven { url = uri("https://s01.oss.sonatype.org/content/repositories/snapshots") }
    }
}

To use a snapshot version of a Kaspresso add a "-SNAPHOT" postfix to the latest Kaspresso version e.g.

dependencies {
    androidTestImplementation 'com.kaspersky.android-components:kaspresso:<latest_version>-SNAPSHOT'
}

If you are still using the old Android Support libraries, we strongly recommend to migrate to AndroidX.

The last version with Android Support libraries is:

dependencies {
    androidTestImplementation 'com.kaspersky.android-components:kaspresso:1.5.3'
}
</details>

FAQ

See our website. You can also reach out to us on Discord.

Tutorial NEW

To make it easier to learn the framework, a step-by-step tutorial is available on our website.

<details> <summary>

Capabilities of Kaspresso

</summary> <details> <summary>

Readability

</summary>

We like the syntax that Kakao applies to write UI tests. This wrapper over Espresso uses the Kotlin DSL approach, that makes the code significantly shorter and more readable. See the difference:

Espresso:

@Test
fun testFirstFeature() {
    onView(withId(R.id.toFirstFeature))
        .check(ViewAssertions.matches(
               ViewMatchers.withEffectiveVisibility(
                       ViewMatchers.Visibility.VISIBLE)))
    onView(withId(R.id.toFirstFeature)).perform(click())
}

Kakao:

@Test
fun testFirstFeature() {
    mainScreen {
        toFirstFeatureButton {
            isVisible()
            click()
        }
    }
}

We used the same approach to develop our own wrapper over UI Automator, and we called it Kautomator. Take a look at the code below:

UI Automator:

val instrumentation: Instrumentation = InstrumentationRegistry.getInstrumentation()
val uiDevice = UiDevice.getInstance(instrumentation)
val uiObject = uiDevice.wait(
    Until.findObject(
        By.res(
            "com.kaspersky.kaspresso.sample_kautomator",
            "editText"
        )
    ),
    2_000
)
uiObject.text = "Kaspresso"
assertEquals(uiObject.text, "Kaspresso")

Kautomator:

MainScreen {
    simpleEditText {
        replaceText("Kaspresso")
        hasText("Kaspresso")
    }
}

Since Kakao and Kautomator provide almost identical APIs, you don’t have to care about what is under the hood of your tests, either Espresso or UI Automator. With Kaspresso, you write tests in the same style for both.

However, Kakao and Kautomator themselves don't help you to see the relation between the test and the corresponding test case. Also, a long test often becomes a giant piece of code that is impossible to split into smaller parts. That's why we have created an additional Kotlin DSL that allows you to read your test more easily.

See the example below:

@Test
fun shouldPassOnNoInternetScanTest() =
    beforeTest {
        activityTestRule.launchActivity(null)
        // some things with the state
    }.afterTest {
        // some things with the state
    }.run {
        step("Open Simple Screen") {
            MainScreen {
                nextButton {
                    isVisible()
                    click()
                }
            }
        }
        step("Click button_1 and check button_2") {
            SimpleScreen {
                button1 {
                    click()
                }
                button2 {
                    isVisible()
                }
            }
        }
        step("Click button_2 and check edit") {
            SimpleScreen {
                button2 {
                    click()
                }
                edit {
                    flakySafely(timeoutMs = 7000) { isVisible() }
                    hasText(R.string.text_edit_text)
                }
            }
        }
        step("Check all possibilities of edit") {
            scenario(
                CheckEditScenario()
            )
        }
    }
</details> <details> <summary>

Stability

</summary>

Sometimes your UI test passes ten times, then breaks on the eleventh attempt for some mysterious reason. It’s called flakiness.

The most popular reason for flakiness is the instability of the UI tests libraries, such as Espresso and UI Automator. To eliminate this instability, Kaspresso uses DSL wrappers and interceptors.

</details> <details> <summary>

UI test libraries acceleration

</summary>

Let’s watch some short video that shows the difference between the original UI Automator (on the right) and the accelerated one (on the left).

Here is a short explanation of why it is possible.

</details> <details> <summary>

Interceptors

</summary>

We developed Kaspresso behavior interceptors on the base of Kakao/Kautomator Interceptors to catch failures.

Thanks to interceptors, you can do a lot of useful things, such as:

  • add custom actions to each framework operation like writing a log or taking a screenshot;
  • overcome flaky operations by re-running failed actions, scrolling the parent layout or closing the android system dialog;

and many more (see the manual).

</details> <details> <summary>

Writing readable logs

</summary>

Kaspresso writes its own logs, detailed and readable:

<img src="https://habrastorage.org/webt/03/nn/qg/03nnqgupdqnwa_i4jwyz1uqq6r0.png" /> <img src="https://habrastorage.org/webt/tq/az/3v/tqaz3vjsgpw0-ivylrfbnuqyiqa.png" /> </details> <details> <summary>

Ability to call ADB commands

</summary>

Espresso and UI Automator don't allow to call ADB commands from inside a test. To fix this problem, we developed AdbServer (see the wiki).

</details> <details> <summary>

Ability to work with Android System

</summary>

You can use Kaspresso classes to work with Android System.

For example, with the Device class you can:

  • push/pull files,
  • enable/disable network,
  • give permissions like a user does,
  • emulate phone calls,
  • take screenshots,
  • enable/disable GPS,
  • set geolocation,
  • enable/disable accessibility,
  • change the app language,
  • collect and parse the logcat output.

(see more about the [Device class](https://kaspe

Related Skills

View on GitHub
GitHub Stars1.9k
CategoryDevelopment
Updated4d ago
Forks176

Languages

Kotlin

Security Score

100/100

Audited on Mar 21, 2026

No findings