0

Update: So I left out that this view is inside a ViewPager. It turns out my issue was the interpretation of "swipeLeft" and "swipeRight". The reason I missed this for so long is because I would manually run through the steps by hand, and what I thought of as "swipeRight" didn't match what Espresso thinks of as swiping right. So I didn't see the issue happening until I threw in a bunch of sleeps around my code so I could see it go in slow motion. That's when I realized it was going the wrong direction. So really, this whole issue is because of that. Oops. Not sure what to do with this question, since I technically can answer it myself but it's so far from being related to what the post is about because I left out the ViewPager bits.

Original:

I'm doing a pretty straightforward check for text and it doesn't want to pass.

onView(withText("My text")).check(matches(isDisplayed()));

android.support.test.espresso.base.DefaultFailureHandler$AssertionFailedWithCauseError: 'is displayed on the screen to the user' doesn't match the selected view.

Expected: is displayed on the screen to the user

Got: "CustomTextView{id=2131756070, res-name=label_name, visibility=VISIBLE, width=506, height=53, has-focus=false, has-focusable=false, has-window-focus=true, is-clickable=false, is-enabled=true, is-focused=false, is-focusable=false, is-layout-requested=false, is-selected=false, root-is-layout-requested=false, has-input-connection=false, x=220.0, y=375.0, text=My text, input-type=0, ime-target=false, has-links=false}"

And here's the layout code:

<snip.snip.CustomTextView
                    android:id="@+id/label_name"
                    style="@style/typographyH4Subheading"
                    android:layout_centerHorizontal="true"
                    android:gravity="center"
                    android:paddingLeft="30dp"
                    android:paddingRight="30dp"
                    android:text="@{viewModel.nameLabel}"
                    android:ellipsize="end"
                    android:singleLine="true"/>

Any idea what could cause this to not match?

Zeek Aran
  • 523
  • 4
  • 18
  • Can you show the layout xml with this `textview` where this case is failing? – Vishu Mar 01 '18 at 16:13
  • @Vishu Updated with the layout code – Zeek Aran Mar 01 '18 at 16:21
  • I think is problem with data binding can you see https://stackoverflow.com/questions/40703567/how-do-i-make-espresso-wait-until-data-binding-has-updated-the-view-with-the-dat – Vishu Mar 01 '18 at 16:28

2 Answers2

0

Is the view actually visible on the disaplay? If it's out of viewport and you need to scroll for example isDisplayed() will fail. Another problem might be that some parent of the given view has invisible or gone visibility.

You can try .check(matches(withEffectiveVisibility(ViewMatchers.Visibility.VISIBLE))); to cover the first case and isVisible from this samples to cover the second.

And do you have only one view with given text?

TpoM6oH
  • 8,385
  • 3
  • 40
  • 72
  • It's definitely visible on the display. Without scrolling, it's about dead center of my device. – Zeek Aran Mar 01 '18 at 17:03
  • try to change to `android:text="My text"`, will it work? – TpoM6oH Mar 01 '18 at 17:21
  • It appears I was mistaken. I was seeing it when I did it manually, but my tests were not doing what I expected and it just happened too fast for me to notice. – Zeek Aran Mar 01 '18 at 20:35
0

Saw your update but if you still want to swipe you should try ViewPagerActions.scrollRight() it looks very similar to swipeRight() but it is what I was able to get my viewpager to swipe correctly