Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: Disable view hierarchy dumping on failures completely #896

Closed
wants to merge 7 commits into from

Conversation

idyatlov
Copy link
Contributor

@idyatlov idyatlov commented Aug 8, 2023

Issue

In #895 @mykola-mokhnach disabled screenshots and hierarchy snapshots on failures, but looks like it wasn't enough.

In Espresso 3.5.0-alpha1 Google introduced the "Save view hierarchy to a file on failures" feature, which basically dumps whole view hierarchy on failure.

It was added here and later modified here.

The issue is that even if it won't save the view hierarchy to the file by default, it would still dump it beforehand. And to dump the view hierarchy it would need to access the views - and this would cause issues on Appium, as it's running on a different thread other than main.

Here is the stack trace sample
08-07 18:38:37.298 E/AndroidRuntime( 6140): android.view.ViewRootImpl$CalledFromWrongThreadException: Only the original thread that created a view hierarchy can touch its views.
          08-07 18:38:37.298 E/AndroidRuntime( 6140):   at android.view.ViewRootImpl.checkThread(ViewRootImpl.java:9321) android.view.ViewRootImpl.focusableViewAvailable(ViewRootImpl.java:4938)
          08-07 18:38:37.298 E/AndroidRuntime( 6140):   at android.view.ViewGroup.focusableViewAvailable(ViewGroup.java:967)
          08-07 18:38:37.298 E/AndroidRuntime( 6140):   at android.view.View.layout(View.java:23161)
          08-07 18:38:37.298 E/AndroidRuntime( 6140):   at android.view.ViewGroup.layout(ViewGroup.java:6412)
          08-07 18:38:37.298 E/AndroidRuntime( 6140):   at androidx.recyclerview.widget.RecyclerView.focusSearch(RecyclerView.java:2937)
          08-07 18:38:37.298 E/AndroidRuntime( 6140):   at android.view.ViewGroup.focusSearch(ViewGroup.java:1079)
          08-07 18:38:37.298 E/AndroidRuntime( 6140):   at android.view.View.focusSearch(View.java:12825)
          08-07 18:38:37.298 E/AndroidRuntime( 6140):   at android.widget.TextView.onCreateInputConnection(TextView.java:8755)
          08-07 18:38:37.298 E/AndroidRuntime( 6140):   at androidx.appcompat.widget.AppCompatEditText.onCreateInputConnection(AppCompatEditText.java:265)
          08-07 18:38:37.298 E/AndroidRuntime( 6140):   at androidx.test.espresso.util.HumanReadables.describe(HumanReadables.java:247)
          08-07 18:38:37.298 E/AndroidRuntime( 6140):   at androidx.test.espresso.util.HumanReadables.lambda$getViewHierarchyErrorMessage$0(HumanReadables.java:120)
          08-07 18:38:37.298 E/AndroidRuntime( 6140):   at androidx.test.espresso.util.HumanReadables.getViewHierarchyErrorMessage(HumanReadables.java:74)
          08-07 18:38:37.298 E/AndroidRuntime( 6140):   at androidx.test.espresso.base.ViewHierarchyExceptionHandler.dumpFullViewHierarchyToFile(ViewHierarchyExceptionHandler.java:98)
          08-07 18:38:37.298 E/AndroidRuntime( 6140):   at androidx.test.espresso.base.ViewHierarchyExceptionHandler.handleSafely(ViewHierarchyExceptionHandler.java:68)
          08-07 18:38:37.298 E/AndroidRuntime( 6140):   at androidx.test.espresso.base.ViewHierarchyExceptionHandler.handleSafely(ViewHierarchyExceptionHandler.java:38)
          08-07 18:38:37.298 E/AndroidRuntime( 6140):   at androidx.test.espresso.base.DefaultFailureHandler$TypedFailureHandler.handle(DefaultFailureHandler.java:167)
          08-07 18:38:37.298 E/AndroidRuntime( 6140):   at io.appium.espressoserver.lib.helpers.CustomFailureHandler.handle(CustomFailureHandler.java:38)
          08-07 18:38:37.298 E/AndroidRuntime( 6140):   at androidx.test.espresso.ViewInteraction.waitForAndHandleInteractionResults(ViewInteraction.java:386)
          08-07 18:38:37.298 E/AndroidRuntime( 6140):   at androidx.test.espresso.ViewInteraction.desugaredPerform(ViewInteraction.java:213)
          08-07 18:38:37.298 E/AndroidRuntime( 6140):   at androidx.test.espresso.ViewInteraction.perform(ViewInteraction.java:140)
          08-07 18:38:37.298 E/AndroidRuntime( 6140):   at io.appium.espressoserver.lib.viewaction.ViewGetter.getView(ViewGetter.java:71)
          08-07 18:38:37.298 E/AndroidRuntime( 6140):   at io.appium.espressoserver.lib.helpers.ViewFinder.getViews(ViewFinder.java:305)
          08-07 18:38:37.298 E/AndroidRuntime( 6140):   at io.appium.espressoserver.lib.helpers.ViewFinder.getViews$default(ViewFinder.java:245)
          08-07 18:38:37.298 E/AndroidRuntime( 6140):   at io.appium.espressoserver.lib.helpers.ViewFinder.findAllBy(ViewFinder.java:170)
          08-07 18:38:37.298 E/AndroidRuntime( 6140):   at io.appium.espressoserver.lib.helpers.ViewFinder.findAllBy(ViewFinder.java:96)
          08-07 18:38:37.298 E/AndroidRuntime( 6140):   at io.appium.espressoserver.lib.handlers.FindElements.handleEspresso(FindElements.java:36)
          08-07 18:38:37.298 E/AndroidRuntime( 6140):   at io.appium.espressoserver.lib.handlers.FindElements.handleEspresso(FindElements.java:28)
          08-07 18:38:37.298 E/AndroidRuntime( 6140):   at io.appium.espressoserver.lib.handlers.RequestHandler$DefaultImpls.invokeStrategy(RequestHandler.java:35)
          08-07 18:38:37.298 E/AndroidRuntime( 6140):   at io.appium.espressoserver.lib.handlers.FindElements.invokeStrategy(FindElements.java:28)
          08-07 18:38:37.298 E/AndroidRuntime( 6140):   at io.appium.espressoserver.lib.handlers.FindElements.invokeStrategy(FindElements.java:28)
          08-07 18:38:37.298 E/AndroidRuntime( 6140):   at io.appium.espressoserver.lib.handlers.RequestHandler$DefaultImpls.handleInternal(RequestHandler.java:29)
          08-07 18:38:37.298 E/AndroidRuntime( 6140):   at io.appium.espressoserver.lib.handlers.FindElements.handleInternal(FindElements.java:28)
          08-07 18:38:37.298 E/AndroidRuntime( 6140):   at io.appium.espressoserver.lib.handlers.FindElements.handleInternal(FindElements.java:28)
          08-07 18:38:37.298 E/AndroidRuntime( 6140):   at io.appium.espressoserver.lib.handlers.RequestHandler$DefaultImpls.handle(RequestHandler.java:57)
          08-07 18:38:37.298 E/AndroidRuntime( 6140):   at io.appium.espressoserver.lib.handlers.FindElements.handle(FindElements.java:28)
          08-07 18:38:37.298 E/AndroidRuntime( 6140):   at io.appium.espressoserver.lib.handlers.FindElements.handle(FindElements.java:28)
          08-07 18:38:37.298 E/AndroidRuntime( 6140):   at io.appium.espressoserver.lib.http.Router.route(Router.java:231)
          08-07 18:38:37.298 E/AndroidRuntime( 6140):   at io.appium.espressoserver.lib.http.Server.serve(Server.java:54)
          08-07 18:38:37.298 E/AndroidRuntime( 6140):   at fi.iki.elonen.NanoHTTPD$HTTPSession.execute(NanoHTTPD.java:945)
          08-07 18:38:37.298 E/AndroidRuntime( 6140):   at fi.iki.elonen.NanoHTTPD$ClientHandler.run(NanoHTTPD.java:192)
          08-07 18:38:37.298 E/AndroidRuntime( 6140):   at java.lang.Thread.run(Thread.java:920)

Solution

Immediately remove all ViewHierarchyExceptionHandler handlers that have been added in the constructor - it would mean that Espresso wouldn't do any hierarchy dump by itself as it was before Espresso 3.5 (it's also compatible with 3.6). We've checked this with @pr4bh4sh and this eliminated all exceptions mentioned above.

@linux-foundation-easycla
Copy link

linux-foundation-easycla bot commented Aug 8, 2023

CLA Missing ID CLA Not Signed

@idyatlov idyatlov closed this Aug 8, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant