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

Failing landscape tests due to screen dimensions #337

Open
AbdelrahmanTalat opened this issue Apr 17, 2023 · 1 comment
Open

Failing landscape tests due to screen dimensions #337

AbdelrahmanTalat opened this issue Apr 17, 2023 · 1 comment

Comments

@AbdelrahmanTalat
Copy link

Expected behaviour

When comparing 2 screenshots in landscape mode the test should pass.

Actual behaviour

When comparing 2 screenshots in landscape mode the test fails with the following response.

 The size of the screenshot taken has changed for test:  [name of the screenshot]
 Original screenshot dimension: 2392x1440.
 New recorded screenshot dimension: 1440x2392.

Steps to reproduce

  • I am using API 30 for my screenshots
  • I have a tests rule to set the landscape mode using the following code
requestedOrientation = if (BaseCustomViewTestRule.forceLandscape) {
            ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE
        } else {
            ActivityInfo.SCREEN_ORIENTATION_PORTRAIT
        }

Version of the library

5.14.1

@sergio-sastre
Copy link

sergio-sastre commented May 31, 2023

@AbdelrahmanTalat
This is completely unrelated to Shot.
The rotation happens, but asynchronously. Therefore, at the moment you take the screenshot, the rotation has not always finished.

The ugly fix for this is to add a Thread.sleep() before taking the screenshot.
The cleanest way is to implement a testRule that waits for the recreated Activity in the correpsonding orientation to resume.

I provided such a function in this library, which works with Shot and other on-device screenshot testing libraries:
https://github.com/sergio-sastre/AndroidUiTestingUtils

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

No branches or pull requests

2 participants