0

I am new to Espresso and Mobile Testing, and I am facing a challenge. I have to search for a contact in App and click on contact displayed at second position.

I checked many posts which were similar but however none of those worked for my example. Code to Search : onView(withId(R.id.textSearch)).perform(typeText("pa"));

Code to Select : onView(withText("Parth Vyas")).perform(click());

But here if I want to select any element which is displayed at position 2, how can I do that?

Parth Vyas
  • 23
  • 5
  • You can see https://stackoverflow.com/questions/28019843/android-espresso-listview-click-item and https://stackoverflow.com/questions/28476507/using-espresso-to-click-view-inside-recyclerview-item – punchman Oct 21 '18 at 06:21

1 Answers1

0

If you know the position after search, then you can try something like:

onData(anything()).inAdapterView(YOUR_ADAPTER_VIEW_MATCHER).atPosition(2).perform(click());
Aaron
  • 3,764
  • 2
  • 8
  • 25
  • Thanks, I tried this but I am not able to find adapter view matcher. In My app, there is cardview which contains text view. And all these are mapped to a class which extends, ArrayAdapter class. I know it may sound naive, but this is my first Android Project. – Parth Vyas Oct 22 '18 at 07:06
  • If you know there's only one adapter view on the screen, you can either do `.inAdapterView(isAssignableFrom(AdapterView.class))`, or simply drop it. – Aaron Oct 22 '18 at 07:53
  • Thanks Aaron. It worked for me. Sorry for bugging. Just an amateur to mobile world. – Parth Vyas Oct 22 '18 at 18:40