Issue
I have written an Espresso test that fails (matching view not found).
Example:
onView((allOf(withText("OK"), hasSibling(withText("Text"))))).perform(click());
The error I get is:
androidx.test.espresso.NoMatchingViewException: No views in hierarchy found
matching: (with text: is "OK" and has sibling: with text: is "Text")
If the target view is not part of the view hierarchy, you may need to use
Espresso.onData to load it from one of the following
AdapterViews:androidx.appcompat.widget.AppCompatSpinner{da0caf9 VFED..CL.
........ 273,0-505,48 #7f0901c1 app:id/structure_formation_spinner}
View Hierarchy:
....
Then the view hierarchy is displayed. The problem is that in Android Studio, the hierarchy is truncated to 32K characters.
I know how to fix the returned error, this is not my problem.
My question is: How can I see the full view hierarchy ? Is it possible in Android Studio? If not, is it possible from the command line?
Solution
Since the test is executed on the Device/Emulator, exception with the full message (view hierarchy is just a message, attached to NoMatchingViewException
) can be obtained from Logcat (i.e. Logcat window in the Android Studio). Filter E/TestRunner
simplifies the search.
Logcat itself is not unlimited though. Default size is 1024KB. It can be changed via Settings | Editor | General | Console
TL;DR;
Android Studio and Android Device/Emulator communicate via protobuf messages. Data from the device arrives to com.android.ddmlib.testrunner.InstrumentationProtoResultParser#updateState
in the form of key-value map (collection of InstrumentationData.ResultsBundleEntry
).
Instrumented Test Results view in Android Studio only displays stackTrace
. You can convince yourself by adding println("hello")
anywhere in the instrumented test. The line will only appear in the Logcat, and not in the Test Result view.
stackTrace
is obtained from the map by key StatusKeys.STACK
(see ln 239). Unfortunately, data already arrives truncated at this point. There is STREAM
key which contains the full text, but it is not used. So the problem is on device side which failed to send complete stacktrace, IMO.
Other runners (e.g., gradle, when running from console) may use different values from that map. This explains why you see full message when running from console.
Answered By - Kuzneц
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.