KasperskyLab / Kaspresso

Android UI test framework
https://kasperskylab.github.io/Kaspresso/
Apache License 2.0
1.81k stars 153 forks source link

Impossible to find some texts with RecyclerView #583

Closed Pirokar closed 1 year ago

Pirokar commented 1 year ago

Describe the bug I have RecyclerView with several holders.

It's impossible to find the text here (see screenshot section) with

childAt<ChatMainScreen.ChatRecyclerItem>(3) {
    hasDescendant { containsText("Добро пожаловать в наш чат") }
}

or with:

childAt<ChatMainScreen.ChatRecyclerItem>(3) {
    itemText.containsText("Добро пожаловать в наш чат")
}

My screen is:

object ChatMainScreen : KScreen<ChatMainScreen>() {
    override val layoutId: Int = R.layout.ecc_fragment_chat
    override val viewClass: Class<*> = ChatFragment::class.java

  // ...

    val recyclerView = KRecyclerView(
        builder = { withId(R.id.chatItemsRecycler) },
        itemTypeBuilder = { itemType(ChatMainScreen::ChatRecyclerItem) }
    )

    class ChatRecyclerItem(matcher: Matcher<View>) : KRecyclerItem<ChatRecyclerItem>(matcher) {
        val itemText = KTextView(matcher) { withId(R.id.text) }
        val itemTime = KTextView(matcher) { withId(R.id.timeStamp) }
    }
}

Layout also has this TextView with "text" id.

Expected behavior This text is possible to find.

Screenshots image

Smartphone (please complete the following information):

Kaspresso version 1.5.3

alekseyp555 commented 1 year ago

Approve this issue with recycler and child

Nikitae57 commented 1 year ago

Hi, @Pirokar! Please, try this code:

childAt<ChatMainScreen.ChatRecyclerItem>(3) { // make sure, you use the right index
    itemText { 
        hasText("Добро пожаловать в наш чат!") 
    }
}

If this doesn't work, please, reopen the issue and attach test artifacts, the more - the better: exception, logs, views dump etc