pedrovgs / Shot

Screenshot testing library for Android
Apache License 2.0
1.19k stars 116 forks source link

[Compose] Unable to capture a screenshot when there is more than 1 root node. #275

Closed alexanderbezverhni closed 2 years ago

alexanderbezverhni commented 2 years ago

What

This is more of a feature request - allow capturing screenshot with multiple root nodes. Multiple root nodes would typically mean there's a Popup being shown on the screen.

Steps to reproduce

Resulting in the following error:

java.lang.AssertionError: Failed to capture a node to bitmap.
Reason: Expected exactly '1' node but found '2' nodes that satisfy: (isRoot)
Nodes found:
1) Node #597 at (l=0.0, t=66.0, r=1080.0, b=1532.0)px
Has 2 children
2) Node #608 at (l=0.0, t=0.0, r=706.0, b=389.0)px
Has 1 child

Proposal

Introduce ScreenshotTest.compareScreenshot(nodeCollection: SemanticsNodeInteractionCollection, name: String? = null) to allow passing in multiple nodes. First node in collection should likely define output screenshot dimensions, the rest nodes can be applied upon the result of previous application. Here's the example where 1 is the first node, 2 is applied upon 1, 3 is applied upon 1+2:


 ┌───────────────┬────────┬──────────────────────┐
 │               │        │                      │
 │               │        │                      │
 │               │        │                      │
 │               │        │                      │
 │               │        │                      │
 │               │        │                      │
 │        2      │        │                      │
 │               │        │                      │
 │               │        │                      │
 │               │        │                      │
 │               │        │      3               │
 │               │        │                      │
 │               │        │                      │
 ├───────────────┼────────┘                      │
 │               │                               │
 │               │                               │
 │               │                               │
 │               │                               │
 │               │                               │
 │        1      │                               │
 │               │                               │
 │               └───────────────────────────────┤
 │                                               │
 │                                               │
 │                                               │
 │                                               │
 │                                               │
 └───────────────────────────────────────────────┘

Version of the library

5.11.2

@pedrovgs I'm wondering if you'd be interested in me making such contribution to the library?

alexanderbezverhni commented 2 years ago

Nevermind, popup cannot currently be captured by SemanticsNodeInteraction.captureToImage() :-\