Skip to content
This repository has been archived by the owner on May 26, 2021. It is now read-only.

Cannot click items in nested RecyclerViews #87

Closed
Cotel opened this issue Mar 11, 2018 · 10 comments
Closed

Cannot click items in nested RecyclerViews #87

Cotel opened this issue Mar 11, 2018 · 10 comments

Comments

@Cotel
Copy link

Cotel commented Mar 11, 2018

Steps to reproduce:

This is my Screen definition:

  class DetailsScreen : Screen<DetailsScreen>() {
    val categoryList = KRecyclerView(
      { withId(R.id.menuCategoriesRecyclerView) },
      { itemType(::CategoryItem) }
    )
  }

  class CategoryItem(parent: Matcher<View>) : KRecyclerItem<CategoryItem>(parent) {
    val platesList = KRecyclerView(
      { withId(R.id.categoryRecyclerView) },
      { itemType(::PlateItem) }
    )
  }

  class PlateItem(parent: Matcher<View>) : KRecyclerItem<PlateItem>(parent) {
    val incrementButton = KButton(parent) { withId(R.id.plateIncrementImageButton) }
    val decrementButton = KButton(parent) { withId(R.id.plateDecrementImageButton) }
    val quantityLabel = KTextView(parent) { withId(R.id.plateQuantityTextView) }
  }

And this is the assertion I am trying to do:

  val screen = DetailsScreen()
    screen {
      categoryList {
        firstChild<CategoryItem> {
          platesList {
            isVisible()

            firstChild<PlateItem> {
              quantityLabel { hasText("0") }

              perform { incrementButton { click() } }

              quantityLabel { hasText("1") }

              perform { decrementButton { click() } }

              quantityLabel { hasText("0") }
            }
          }
        }
      }
    }

Observed Results:

The following exception is thrown:

java.lang.NoSuchMethodError: No direct method <init>(Landroid/support/test/espresso/action/Tapper;Landroid/support/test/espresso/action/CoordinatesProvider;Landroid/support/test/espresso/action/PrecisionDescriber;II)V in class Landroid/support/test/espresso/action/GeneralClickAction; or its super classes (declaration of 'android.support.test.espresso.action.GeneralClickAction' appears in /data/app/com.myapp.example-xxx==/base.apk)

Could this be because I cannot set parent to the nested KRecyclerView at CategoryItem?

@Unlimity
Copy link
Member

Hmmm... not sure, but this should work fine, since internally Kakao only generates matchers.
But I see that you use perform function. Please remember, that this one is infix, thus requires both left and right operands. It probably breaks your flow of test. perform is used when you match some view dynamically and want to perform some actions on it right away. Example:

  KView { withId(R.id.view) } perform { click() }

Here's on left side is instance of KView created by invoking it's constructor and on right side is lambda which will be applied to given instance.

Please try removing perform from your test and write back with the results. Cheers!

@Cotel
Copy link
Author

Cotel commented Mar 12, 2018

Removing perform results in the same exception NoSuchMethod 😅

@Unlimity
Copy link
Member

Ok. Then we need to investigate. I will return later with the results.

@Unlimity
Copy link
Member

Maybe I found a problem here.
Your platesList is a RecyclerView inside an item of another RecyclerView, right?
But you do not match this recycler with parent recycler matcher.
Try to replace your declaration with this:

  class CategoryItem(parent: Matcher<View>) : KRecyclerItem<CategoryItem>(parent) {
    val platesList = KRecyclerView({
      withId(R.id.categoryRecyclerView) 
      isDescendantOfA { withMatcher(parent) }
    }, { 
      itemType(::PlateItem)
    })
  }

If this works, I'll prepare PR and add additional constructor that will allow to pass parent matcher as argument when building KRecyclerView and KListView.
Actually I did not consider the fact that there are nested recyclers in the wild when designing the library.

@Cotel
Copy link
Author

Cotel commented Mar 15, 2018

I've added isDescendantOfA but still isn't working with the same exception.

@Unlimity
Copy link
Member

Ok, keep investigating

@Unlimity
Copy link
Member

So, I made a PR with testing of nested recycler views #89 and the test works.
My final guess is that in nested recycler view is actually a root view of it's parent recycler view.
If so, parent: Matcher<View> that is passed inside the item constructor is actually a matcher of the item's root view.
I might suggest you to match it like that:

  class CategoryItem(parent: Matcher<View>) : KRecyclerItem<CategoryItem>(parent) {
    val platesList = KRecyclerView({
      withMatcher(parent)
    }, { 
      itemType(::PlateItem)
    })
  }

Please report back with the results

@Unlimity
Copy link
Member

Also, as the error is NoSuchMethodException in Espresso class, please verify that your project do not override Espresso version. Kakao is using 3.0.1. You can check your dependency tree by executing ./gradlew :your_module:dependencies

@Cotel
Copy link
Author

Cotel commented Mar 15, 2018

It was the Espresso version, I was using an outdated one. Thank you very much and keep up the good work 👍

@Unlimity
Copy link
Member

Great! Closing the issue then

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

2 participants