3

My app's Reyclerview is "android.support.v7.widget.RecyclerView" And I use androidx's espresso.

I added dependencies to my gradle like below:

androidTestImplementation 'androidx.annotation:annotation:' + rootProject.androidxLibVersion;
androidTestImplementation 'androidx.recyclerview:recyclerview:' + rootProject.androidxLibVersion;
androidTestImplementation 'androidx.test:core:' + rootProject.coreVersion
androidTestImplementation 'androidx.test.ext:junit:' + rootProject.extJUnitVersion
androidTestImplementation 'androidx.test:runner:' + rootProject.runnerVersion
androidTestImplementation 'androidx.test.espresso:espresso-core:' + rootProject.espressoVersion
androidTestImplementation 'androidx.test.espresso:espresso-contrib:' + rootProject.espressoVersion
androidTestImplementation 'androidx.test.espresso:espresso-intents:' + rootProject.espressoVersion

However, when I am trying to use

import androidx.recyclerview.widget.RecyclerView
import androidx.test.espresso.contrib.RecyclerViewActions

    ...

RecyclerViewActions.scrollToPosition<RecyclerView.ViewHolder>(position)

It says

Caused by: java.lang.RuntimeException: Action will not be performed because the target view does not match one or more of the following constraints: (is assignable from class: class androidx.recyclerview.widget.RecyclerView and is displayed on the screen to the user) Target view: "RecyclerView{id=2131296674, res-name=media_content_recyclerview, visibility=VISIBLE, width=1440, height=2384, has-focus=false, has-focusable=true, has-window-focus=true, is-clickable=false, is-enabled=true, is-focused=false, is-focusable=true, is-layout-requested=false, is-selected=false, layout-params=android.widget.RelativeLayout$LayoutParams@e32b046, tag=null, root-is-layout-requested=false, has-input-connection=false, x=0.0, y=192.0, child-count=15}"

Is there something wrong in my code?

John
  • 1,139
  • 3
  • 16
  • 33
  • 2
    If you're certain that you're using `android.support.v7.widget.RecyclerView` in the app and not `androidx.recyclerview.widget.RecyclerView`, then you need to change the dependencies not to use androidx to test in your gradle. – Aaron Nov 09 '18 at 09:39
  • @Aaron It works, thank you. – John Nov 13 '18 at 01:47
  • @John - I am facing the same issue. Can you help me with the solution? I did not get what Aaron is trying to say. I am using import android.support.v7.widget.RecyclerView; and androidTestImplementation 'androidx.test.espresso:espresso-core:3.1.1' – Vikash Apr 01 '19 at 08:47
  • @Vikash, As far as I remember, I excluded dependencies. Please refer to https://stackoverflow.com/questions/36103299/in-an-android-gradle-build-how-to-exclude-dependencies-from-an-included-jar-fil – John May 02 '19 at 06:27

0 Answers0