Issue
Trying to verify my snack bar been shown
Calling
onView(withText(R.string.checkout_device_error))
.check(matches(withEffectiveVisibility(ViewMatchers.Visibility.VISIBLE)))
Due to the debugger everything goes fine and method make it visible but test fail
'view has effective visibility=VISIBLE' doesn't match the selected view.
Expected: view has effective visibility=VISIBLE
Got: "MaterialTextView{id=2131362495, res-name=ribbon_text, visibility=VISIBLE, width=0, height=0, 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=true, is-selected=false, layout-params=android.widget.FrameLayout$LayoutParams@7c97dc7f, tag=null, root-is-layout-requested=false, has-input-connection=false, x=0.0, y=0.0, text=Invalid username and or password., input-type=0, ime-target=false, has-links=false}"
Solution
I'm not sure what's the exact failure you're getting as you mentioned that the failure logs you received in the Debugging State. However if this the error that you're getting, then the catch is the container View
of checkout_device_error
string is not yet visible when you're trying to assert it's visibility. Let's take a look at your log -
visibility=VISIBLE, width=0, height=0, x=0.0, y=0.0
If you see, the MaterialTextView
has visibility VISIBLE
but it's height
and width
is 0
and also the x
y
coordinates are also 0
. This mean that in the parent container, the MaterialTextView
has visibility VISIBLE
. However, the parent container might not be visible.
I had faced the same issue where I had a RatingBar
with visibility VISIBLE
inside a ConstraintLayout
which has initial visibility GONE
. When I tried to validate the visibility of the RatingBar
, it failed giving the same error. This won't happen if your parent view remains in INVISIBLE
/ GONE
state during your validation but if the Parent View is transitioning the Visibility state and your Validation call happens simultaneously, then this issue arises. I fixed this issue by giving a delay to properly finish the Parent View's transition and then initiating the Visibility validation. I will recommend you to do the same and give some delay in order to make the Snackbar
appear completely.
Answered By - Abhishek
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.