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

Enable taking screenshots from dialogs #176

Closed
5 tasks
jdeebee opened this issue Sep 27, 2023 · 4 comments
Closed
5 tasks

Enable taking screenshots from dialogs #176

jdeebee opened this issue Sep 27, 2023 · 4 comments
Labels

Comments

@jdeebee
Copy link

jdeebee commented Sep 27, 2023

Is your feature request related to a problem? Please describe.
I was surprised to find out that Testify cannot verify/take a screenshot of dialogs. I believe this should be a core functionality of a snapshot testing library as dialogs are used in many apps and SDKs. I came across this old issue from another library and this Testify issue and now I understand why it's currently not possible, but it would be lovely if you could add a mechanism to take and verify a screenshot of a provided Window or View outside the activity view hierarchy.

This feedback relates to:

  • The Kotlin library
  • The Gradle plugin
  • The IntelliJ Platform plugin
  • The sample code
  • The documentation

Describe the solution you'd like
Introduce a way to take and verify a screenshot of a provided Window or View outside the activity view hierarchy

Describe alternatives you've considered
(Potentially) introduce an Espresso/AndroidX test rule for dialogs specifically

Additional context
N/A

@DanielJette
Copy link
Contributor

@jdeebee Testify does not capture dialogs by default due to the way that Testify only captures a bitmap from the current Window. As Dialogs are rendered as separate windows, they require a use of a different capture method.

Fortunately, Testify does support capturing the entire screen, including Dialogs, through the user of the FullscreenCapture method.

To capture dialogs with Testify:

  1. Add the testify-fullscreen extension library to your project
  2. Use the captureFullscreen() modifier on your ScreenshotRule.
  3. Exclude the System UI from the screenshot comparison using excludeSystemUi
  4. Set the exactness to a value of 0.95f or lower
  5. Record & run your tests as usual

For more information, see the example here.

@jdeebee
Copy link
Author

jdeebee commented Sep 28, 2023

@DanielJette Great to hear this is already possible. Will try it today. Thanks for your quick answer!

@jdeebee
Copy link
Author

jdeebee commented Oct 10, 2023

@DanielJette I tried your suggested approach, however no system UI exclusion method is found in ScreenshotRule despite being mentioned in the documentation as well (none of excludeStatusBar, excludeNavigationBar, or excludeSystemUi exist or can be invoked). I tried the latest beta version (beta4) as well as beta2. Are these methods omitted by accident?

These are the versions I tried:

androidTestImplementation "dev.testify:testify-fullscreen:2.0.0-beta04"
androidTestImplementation "dev.testify:testify-fullscreen:2.0.0-beta02"

I use the same version for the gradle plugin classpath as well (so that they can be matched correctly):

classpath "dev.testify:plugin:2.0.0-beta04"
classpath "dev.testify:plugin:2.0.0-beta02"

And this is how I configure the test rule:

ScreenshotRule(activityClass)
        .configure { exactness = 0.94f }
        .setCaptureMethod(::fullscreenCapture)
        .excludeStatusBar()
        .withExperimentalFeatureEnabled(TestifyFeatures.GenerateDiffs)

@DanielJette
Copy link
Contributor

DanielJette commented Oct 14, 2023

@jdeebee It does look like the documentation was not correctly updated for beta04
The exclusion extension methods were relocated to support on the new TestifyConfiguration class, but it seems like we missed updating the CHANGELOG and the Recipes. Sorry about this. I've logged a bug to address this here #181

In the meantime, you can use the excludeStatusBar(), excludeNavigationBar() or excludeSystemUi() via the configure {} closure.

import dev.testify.capture.fullscreen.provider.excludeStatusBar

@get:Rule val rule = ScreenshotRule(MainActivity::class.java)
rule
    .configure {
        exactness = 0.94f
        captureMethod = ::fullscreenCapture
        excludeStatusBar()
    }
    .withExperimentalFeatureEnabled(TestifyFeatures.GenerateDiffs)
    .assertSame()

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants