Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,11 @@ public void ShouldFlyoutTextWrapsInLandscape()
App.WaitForElement("OpenFlyoutButton");
App.Tap("OpenFlyoutButton");
App.SetOrientationLandscape();
#if ANDROID
VerifyScreenshot(cropLeft: 125);
#else
VerifyScreenshot();
#endif
}
}
#endif
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,11 @@ public void BorderBackgroundSizeUpdatesWhenRotatingScreen()
App.WaitForElement("SetHeightTo200");
App.Tap("SetHeightTo200");
App.SetOrientationLandscape();
#if ANDROID
VerifyScreenshot(cropLeft: 125);
#else
VerifyScreenshot();
#endif
}
#endif
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,11 @@ public void CarouselViewItemShouldScaleProperly()
App.WaitForElement("Baboon");
App.SetOrientationLandscape();
App.WaitForElement("Baboon");
#if ANDROID
VerifyScreenshot(cropLeft: 125);

Copilot AI Sep 22, 2025

Copy link

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.
#else
VerifyScreenshot();
#endif
}

[TearDown]
Expand Down
20 changes: 17 additions & 3 deletions src/Controls/tests/TestCases.Shared.Tests/UITest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -124,6 +124,8 @@ public void VerifyScreenshotOrSetException(
ref Exception? exception,
string? name = null,
TimeSpan? retryDelay = null,
int cropLeft = 0,
int cropRight = 0,
int cropTop = 0,
int cropBottom = 0,
double tolerance = 0.0
Expand All @@ -134,7 +136,7 @@ public void VerifyScreenshotOrSetException(
{
try
{
VerifyScreenshot(name, retryDelay, cropTop, cropBottom, tolerance
VerifyScreenshot(name, retryDelay, cropLeft, cropRight, cropTop, cropBottom, tolerance
#if MACUITEST || WINTEST
, includeTitleBar
#endif
Expand All @@ -151,6 +153,8 @@ public void VerifyScreenshotOrSetException(
/// </summary>
/// <param name="name">Optional name for the screenshot. If not provided, a default name will be used.</param>
/// <param name="retryDelay">Optional delay between retry attempts when verification fails.</param>
/// <param name="cropLeft">Number of pixels to crop from the left of the screenshot.</param>
/// <param name="cropRight">Number of pixels to crop from the right of the screenshot.</param>
/// <param name="cropTop">Number of pixels to crop from the top of the screenshot.</param>
/// <param name="cropBottom">Number of pixels to crop from the bottom of the screenshot.</param>
/// <param name="tolerance">Tolerance level for image comparison as a percentage from 0 to 100.</param>
Expand Down Expand Up @@ -179,6 +183,8 @@ public void VerifyScreenshotOrSetException(
public void VerifyScreenshot(
string? name = null,
TimeSpan? retryDelay = null,
int cropLeft = 0,
int cropRight = 0,
int cropTop = 0,
int cropBottom = 0,
double tolerance = 0.0 // Add tolerance parameter (0.05 = 5%)
Expand Down Expand Up @@ -316,16 +322,24 @@ but both can happen.
TestDevice.iOS => 40,
_ => 0,
};

// For Android also crop the 3 button nav from the left or right, since it's not part of the
// app itself and the button color can vary (the buttons change clear briefly when tapped).
// For iOS, crop the home indicator at the bottom.
Comment thread
NafeelaNazhir marked this conversation as resolved.
Outdated
int cropFromLeft = 0;
int cropFromRight = 0;

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

Copilot AI Sep 22, 2025

Copy link

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.
cropFromTop = cropTop > 0 ? cropTop : cropFromTop;
cropFromBottom = cropBottom > 0 ? cropBottom : cropFromBottom;

if (cropFromTop > 0 || cropFromBottom > 0)
if (cropFromLeft > 0 || cropFromRight > 0 || cropFromTop > 0 || cropFromBottom > 0)
{
IImageEditor imageEditor = _imageEditorFactory.CreateImageEditor(actualImage);
(int width, int height) = imageEditor.GetSize();

imageEditor.Crop(0, cropFromTop, width, height - cropFromTop - cropFromBottom);
imageEditor.Crop(cropFromLeft, cropFromTop, width - cropFromLeft - cropFromRight, height - cropFromTop - cropFromBottom);

actualImage = imageEditor.GetUpdatedImage();
}
Expand Down