Skip to content

[Testing] Added Left/Right Cropping Support for Screenshot Verification in UI Tests#31715

Merged
PureWeen merged 2 commits into
dotnet:mainfrom
NafeelaNazhir:landscape_fix
Sep 22, 2025
Merged

[Testing] Added Left/Right Cropping Support for Screenshot Verification in UI Tests#31715
PureWeen merged 2 commits into
dotnet:mainfrom
NafeelaNazhir:landscape_fix

Conversation

@NafeelaNazhir
Copy link
Copy Markdown
Contributor

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 VerifyScreenshot and related methods, and Android-specific cropping is applied in several test cases to improve screenshot accuracy.

Screenshot cropping enhancements

  • Added cropLeft and cropRight parameters to the VerifyScreenshot and VerifyScreenshotOrSetException methods in UITest.cs to allow cropping from the left and right sides of screenshots. Updated method signatures and XML documentation accordingly. [1] [2] [3]
  • Modified the screenshot cropping logic to use the new cropLeft and cropRight parameters, enabling cropping from all four sides as needed.

Platform-specific test improvements

  • Updated test cases (Issue15154.cs, Issue22606.cs, Issue28523.cs) to use the new cropLeft parameter when running on Android, ensuring screenshots exclude the navigation bar area for more reliable comparisons. [1] [2] [3]

Issue Fixed

#31705

@NafeelaNazhir NafeelaNazhir added the area-testing Unit tests, device tests label Sep 22, 2025
@dotnet-policy-service dotnet-policy-service Bot added the community ✨ Community Contribution label Sep 22, 2025
@dotnet-policy-service
Copy link
Copy Markdown
Contributor

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.

@dotnet-policy-service dotnet-policy-service Bot added the partner/syncfusion Issues / PR's with Syncfusion collaboration label Sep 22, 2025
@NafeelaNazhir NafeelaNazhir marked this pull request as ready for review September 22, 2025 14:13
Copilot AI review requested due to automatic review settings September 22, 2025 14:13
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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 cropLeft and cropRight parameters 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

Comment on lines +332 to +333
cropFromLeft = cropLeft > 0 ? cropLeft : cropFromLeft;
cropFromRight = cropRight > 0 ? cropRight : cropFromRight;
Copy link

Copilot AI Sep 22, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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;.

Suggested change
cropFromLeft = cropLeft > 0 ? cropLeft : cropFromLeft;
cropFromRight = cropRight > 0 ? cropRight : cropFromRight;
cropFromLeft = cropLeft;
cropFromRight = cropRight;

Copilot uses AI. Check for mistakes.
Comment thread src/Controls/tests/TestCases.Shared.Tests/UITest.cs Outdated
App.SetOrientationLandscape();
App.WaitForElement("Baboon");
#if ANDROID
VerifyScreenshot(cropLeft: 125);
Copy link

Copilot AI Sep 22, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Copilot uses AI. Check for mistakes.
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
@PureWeen
Copy link
Copy Markdown
Member

/azp run

@azure-pipelines
Copy link
Copy Markdown

Azure Pipelines successfully started running 3 pipeline(s).

@PureWeen PureWeen merged commit 4d6515f into dotnet:main Sep 22, 2025
127 of 129 checks passed
@github-actions github-actions Bot locked and limited conversation to collaborators Oct 23, 2025
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

area-testing Unit tests, device tests community ✨ Community Contribution partner/syncfusion Issues / PR's with Syncfusion collaboration

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants