[Testing] Added Left/Right Cropping Support for Screenshot Verification in UI Tests#31715
Conversation
|
Hey there @@NafeelaNazhir! Thank you so much for your PR! Someone from the team will get assigned to your PR shortly and we'll get it reviewed. |
There was a problem hiding this comment.
Pull Request Overview
This pull request enhances the screenshot verification system in UI tests by adding support for cropping screenshots from the left and right sides, in addition to the existing top and bottom cropping. This addresses platform-specific UI artifacts, particularly Android's navigation buttons that can cause screenshot comparison failures.
- Added
cropLeftandcropRightparameters to screenshot verification methods - Updated the cropping logic to handle all four sides of screenshots
- Applied Android-specific left cropping to existing test cases to exclude navigation bar artifacts
Reviewed Changes
Copilot reviewed 4 out of 7 changed files in this pull request and generated 3 comments.
| File | Description |
|---|---|
| src/Controls/tests/TestCases.Shared.Tests/UITest.cs | Added cropLeft and cropRight parameters to VerifyScreenshot methods and updated cropping logic |
| src/Controls/tests/TestCases.Shared.Tests/Tests/Issues/Issue28523.cs | Applied Android-specific left cropping of 125 pixels |
| src/Controls/tests/TestCases.Shared.Tests/Tests/Issues/Issue22606.cs | Applied Android-specific left cropping of 125 pixels |
| src/Controls/tests/TestCases.Shared.Tests/Tests/Issues/Issue15154.cs | Applied Android-specific left cropping of 125 pixels |
| cropFromLeft = cropLeft > 0 ? cropLeft : cropFromLeft; | ||
| cropFromRight = cropRight > 0 ? cropRight : cropFromRight; |
There was a problem hiding this comment.
These conditional assignments are redundant since cropFromLeft and cropFromRight are initialized to 0 and the parameters default to 0. The assignments should be simplified to direct assignment: cropFromLeft = cropLeft; and cropFromRight = cropRight;.
| cropFromLeft = cropLeft > 0 ? cropLeft : cropFromLeft; | |
| cropFromRight = cropRight > 0 ? cropRight : cropFromRight; | |
| cropFromLeft = cropLeft; | |
| cropFromRight = cropRight; |
| App.SetOrientationLandscape(); | ||
| App.WaitForElement("Baboon"); | ||
| #if ANDROID | ||
| VerifyScreenshot(cropLeft: 125); |
There was a problem hiding this comment.
The magic number 125 for crop pixels should be defined as a named constant to improve maintainability and ensure consistency across test files. Consider defining private const int AndroidNavigationCropLeft = 125; at the class level.
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
|
/azp run |
|
Azure Pipelines successfully started running 3 pipeline(s). |
This pull request enhances screenshot verification in UI tests by adding support for cropping the left and right sides of screenshots, primarily to address platform-specific UI artifacts (such as Android's navigation buttons). The cropping parameters are now available in the
VerifyScreenshotand related methods, and Android-specific cropping is applied in several test cases to improve screenshot accuracy.Screenshot cropping enhancements
cropLeftandcropRightparameters to theVerifyScreenshotandVerifyScreenshotOrSetExceptionmethods inUITest.csto allow cropping from the left and right sides of screenshots. Updated method signatures and XML documentation accordingly. [1] [2] [3]cropLeftandcropRightparameters, enabling cropping from all four sides as needed.Platform-specific test improvements
Issue15154.cs,Issue22606.cs,Issue28523.cs) to use the newcropLeftparameter when running on Android, ensuring screenshots exclude the navigation bar area for more reliable comparisons. [1] [2] [3]Issue Fixed
#31705