Closed atsiarenia closed 2 years ago
Espresso forces "human readable" output for views at https://github.com/android/android-test/blob/master/espresso/core/java/androidx/test/espresso/matcher/ViewMatchers.java#L535 instead of using Matcher<T>.describeMismatch(Object item, Description mismatchDescription)
Possible solution is parsing error message:
if message contains Expected: with text: is "bla bla"
, then print only part text=ops it's devops =)
if message contains Expected: view has effective visibility=VISIBLE
, then print visibility=GONE
and etc
Hi, @atsiarenia! Thank you for your submission and sorry for so delayed answer. Seems like your issue was resolved automatically with current version of espresso used in Kaspresso 1.4.2. Now it clearly states the expected and actual text, the rest of view details are printed in a separate line. See example below.
Expected: an instance of android.widget.TextView and view.getText() with or without transformation to match: is "R.string.simple_fragment_text_edittext"
Got: view.getText() was "Simple Fragment" transformed text was "Simple Fragment"
View Details: MaterialTextView{id=2131231221, res-name=text_view_title, visibility=VISIBLE, width=583, height=103, 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, layout-params=android.widget.RelativeLayout$LayoutParams@22facce, tag=null, root-is-layout-requested=false, has-input-connection=false, x=248.0, y=110.0, text=Simple Fragment, input-type=0, ime-target=false, has-links=false}
In my case using view.hasText()
was a mistake. In case view
contains empy text it always throws this exception:
junit.framework.AssertionFailedError: 'an instance of android.widget.TextView and view.getText() with or without transformation to match: is ""
Solution is to use containsText()
.
In case if we use in our tests checks like:
And this check will be failed. We'll get output like:
Will be great to have standard hamcrest output like: