agoda-com / Kakao

This repo is no longer supported. Please visit a https://github.com/KakaoCup/Kakao
Apache License 2.0
1.11k stars 102 forks source link

If RecyclerView item has some text then do action #202

Closed Kotlinpin closed 4 years ago

Kotlinpin commented 4 years ago

Hey guys! help me please to resolve next question using Kakao methods: I have a recyclerView of buttons' list:

val buttonsList: KRecyclerView = KRecyclerView({
    withId(R.id.buttonsList)
}, itemTypeBuilder = {
    itemType(::ButtonItem)
})

class ButtonItem(parent: Matcher<View>) : KRecyclerItem<ButtonItem>(parent) {
    val actionButton = KButton(parent) { withId(R.id.action_button) }
}

The third button sometimes might have different string titles depending on app codition and i need to press on that third button when it has a string "delete". How to do that correctly? I resolved this problem in the following way

fun isItDeleteButton(): Boolean{
        return try{
            buttonsList.childAt<ButtonItem>(2) {
                actionButton.hasText(R.string.delete)
            }
            true
        } catch (e: AssertionFailedError) {
            false
        }
    }

and then using that boolean i perform action, but i'm not sure whether it's a clean solution. Perhaps you could advise something better using Kakao methods.

Thank you!

Unlimity commented 4 years ago

Hi there! Generally, this is not how a UI test, and to that end, any test, should be designed and executed. It is expected that with the same environment and same user actions you are getting the same response/result. So in that perspective nor Espresso nor Kakao was designed to do state-based actions/assertions. I suggest you revisit your approaches to test design. However, your solution seems the only working one to me. Can't think of any other approach. It is not clean and doesn't solve the actual issue (test design flaw), but it should work. Cheers!

Kotlinpin commented 4 years ago

Thanks, Ilya!