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

Feature/layout check improvement #314

Merged
merged 5 commits into from
Mar 21, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
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
11 changes: 9 additions & 2 deletions docs/src/docs/modules/layout-check.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -12,15 +12,22 @@ Although, manual inspection can never be pixel-accurate. An inspection of perhap

At this point an automatic comparison of reference screenshots can help. This test is to be seen in addition to the functional tests, but cannot replace them. In a test case, it would also be conceivable to combine the check of function and layout.

== Description
== How it works

A layout test with the Testerra utilities is actually a comparison between a reference and the actual state. This is done via the screenshot functionality of Selenium, in which both screenshots (reference and actual) are compared pixel by pixel from top to bottom. In this comparison, a third image is created in which differences (ReferencePixel != ActualPixel) are marked in red.

martingrossmann marked this conversation as resolved.
Show resolved Hide resolved
image::layoutcheck_comparison.png[alt="Visualization of a layout check",width=920,height=233]

In case that one image has a different size than the other Testerra reports this as an <<#_optional_assertions, Optional assertion>>. Testerra considers only the common pixels of both images as 100%. Pixels that are outside of one or the other image are not included in the error calculation. In the comparison, those Pixels are marked in blue.

image::layoutcheck_diffsize_comparison.png[alt="Visualization of a layout check with different sized images",width=920,height=233]


martingrossmann marked this conversation as resolved.
Show resolved Hide resolved
=== Prerequisites
The following prerequisites must be met

. Concrete execution environment: Layout tests should run in a concrete browser environment to ensure the comparability of the screenshots.
** Size of browser window: Define fixed size to exclude different sizes of the images at different VM resolutions
** Size of browser window: Define fixed size to exclude different sizes of the images at different screen resolutions
** Screen resolution and scaling: Make sure you have the same screen resolution and scaling on each presentation device.

== Configuration
Expand Down
Binary file added docs/src/images/layoutcheck_comparison.png
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 @@ -271,7 +271,7 @@ private static double generateDistanceImage(
int pixelsInError = 0;
int noOfIgnoredPixels = 0;
// calculate the size of the distance image and create an empty image
final Dimension distanceImageSize = calculateMaxImageSize(expectedImage, actualImage);
final Dimension distanceImageSize = calculateMinImageSize(expectedImage, actualImage);
final BufferedImage distanceImage = new BufferedImage(
distanceImageSize.width, distanceImageSize.height,
expectedImage.getType());
Expand Down Expand Up @@ -317,10 +317,8 @@ private static double generateDistanceImage(
distanceImage.setRGB(currentX, currentY, Color.RED.getRGB());
pixelsInError++;
}
}

// count the ignored pixels for calculating
if (useIgnoreColor && expectedRgb == ignoreColor) {
} else {
// count the ignored pixels for calculating
noOfIgnoredPixels++;
}
} else {
Expand Down Expand Up @@ -380,19 +378,19 @@ private static boolean doRGBsMatch(int expectedRgb, int actualImageRGB) {
}

/**
* Calculates the sizes that result from the maximum sizes of both pictures.
* Calculates the sizes that result from the minimum sizes of both pictures.
*
* @param expectedImage The expected image
* @param actualImage The actual image
* @return Calculated maximum size of the images
* @param actualImage The actual image
* @return Calculated minimum size of the images
*/
private static Dimension calculateMaxImageSize(
private static Dimension calculateMinImageSize(
final BufferedImage expectedImage,
final BufferedImage actualImage
) {
return new Dimension(
Math.max(expectedImage.getWidth(), actualImage.getWidth()),
Math.max(expectedImage.getHeight(), actualImage.getHeight())
Math.min(expectedImage.getWidth(), actualImage.getWidth()),
Math.min(expectedImage.getHeight(), actualImage.getHeight())
);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,4 +48,10 @@ public void testT01_CheckImageLayout() {
uiElement.expect().screenshot().pixelDistance("TestImage").isLowerThan(1.0);
}

@Test
public void testT02_CheckImageLayoutDifferentSizes() {
UiElement uiElement = getUIElementQa("testimage");
uiElement.expect().screenshot().pixelDistance("TestImageDifferentSize").isLowerThan(1.0);
}

}
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.