pedrovgs / Shot

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

Failing landscape tests due to screen dimensions #337

Open AbdelrahmanTalat opened 1 year ago

AbdelrahmanTalat commented 1 year ago

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

Version of the library

5.14.1

sergio-sastre commented 1 year ago

@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