Kakao

Kakao is a library built on top of Espresso. Agoda, which has created more than a thousand automated tests for their codebase, developed it when they realized the code readability of their tests was quite low when using Espresso. They developed this library pursuing the following benefits:
• Readability
• Reusability
• Extensible DSL
Screen: this is a class we create for the screen under test, and where we define the views from that screen that will be interacted during the tests.
Screen examples
class FormScreen : Screen<FormScreen>()
KView: this as expected represents your screen view components, the ones that will be interacted with during the tests.
KView types:
- KView
- KEditText
- KTextView
- KButton
- KImageView
- KWebView
- KCheckbox
- KViewPager
- KSeekBar
- KSwitch
and more…
Implementations
Open your app’s build.gradle file. This is usually not the top-level build.gradle file but app/build.gradle.
Add the following lines inside dependencies:
androidTestImplementation 'com.agoda.kakao:kakao:1.4.0'
androidTestImplementation 'com.android.support.test:rules:1.0.2'
Advanced
Kakao offers an easy way to interact with your RecyclerView and ListView
For KListView:
val list = KListView { builder = { withId(R.id.list) } }
For KRecyclerView:
val recycler = KRecyclerView { builder = { withId(R.id.recycler_view) } }
You can combine different matchers to retrieve your view.
Create KAdapterItem/KRecyclerItem
Every adapter contains different Items, Kakao provides an easy way to define the different items of your adapter with KAdapterItem and KRecyclerItem. If your adapter contains multiple Items but your interactions in your tests only work with one are not required to create all of them.
KAdapterItem
class Item(i: DataInteraction) : KAdapterItem<Item>(i) {
val title = KTextView(i) { withId(R.id.title) }
val subtitle = KTextView(i) { withId(R.id.subtitle) }
val button = KButton(i) { withId(R.id.button) }
}
KRecyclerItem
class Item(parent: Matcher<View>) : KRecyclerItem<Item>(parent) {
val title: KTextView = KTextView(parent) { withId(R.id.title) }
val subtitle: KTextView = KTextView(parent) { withId(R.id.subtitle) }
}
The KView defined in the Item corresponds to views used on the Item. You can assign the KItems to the KListView/ KRecyclerView like:
val recycler: KRecyclerView = KRecyclerView({
withId(R.id.recycler_view)
}, itemTypeBuilder = {
itemType(::Item)
})
And finally, your final interaction will be:
onScreen<RecyclerScreen> {
recycler {
firstChild<TestRecyclerScreen.Item> {
isVisible()
title { hasText("Title 1") }
}
}
}