Skip to content
Open
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
38 changes: 0 additions & 38 deletions java/test/org/openqa/selenium/TakesScreenshotTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -326,44 +326,6 @@ private Set<String> generateExpectedColors(
return colors;
}

/**
* Get colors from image from each point at grid defined by stepX/stepY.
*
* @param image - image
* @param stepX - interval in pixels b/w point in X dimension
* @param stepY - interval in pixels b/w point in Y dimension
* @return set of colors in string hex presentation
*/
private Set<String> scanActualColors(BufferedImage image, final int stepX, final int stepY) {
Set<String> colors = new TreeSet<>();

try {
int height = image.getHeight();
int width = image.getWidth();
assertThat(width > 0).isTrue();
assertThat(height > 0).isTrue();

Raster raster = image.getRaster();
for (int i = 0; i < width; i = i + stepX) {
for (int j = 0; j < height; j = j + stepY) {
String hex =
String.format(
"#%02x%02x%02x",
(raster.getSample(i, j, 0)),
(raster.getSample(i, j, 1)),
(raster.getSample(i, j, 2)));
colors.add(hex);
}
}
} catch (Exception e) {
fail("Unable to get actual colors from screenshot: " + e.getMessage());
}

assertThat(colors).isNotEmpty();

return colors;
}

/**
* Compares sets of colors are same.
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@

import com.google.common.collect.Sets;
import java.awt.image.BufferedImage;
import java.awt.image.Raster;
import java.io.ByteArrayInputStream;
import java.io.File;
import java.io.IOException;
Expand All @@ -47,7 +46,7 @@
* coloured areas - take screenshot - calculate expected colors as in tested HTML page - scan
* screenshot for actual colors * compare
*
* @see org.openqa.selenium.TakesScreenshotTest
* <p>(See related screenshot tests in the parent package.)
*/

// TODO(user): verify expected behaviour after frame switching
Expand Down Expand Up @@ -184,44 +183,6 @@ private Set<String> generateExpectedColors(
return colors;
}

/**
* Get colors from image from each point at grid defined by stepX/stepY.
*
* @param image - image
* @param stepX - interval in pixels b/w point in X dimension
* @param stepY - interval in pixels b/w point in Y dimension
* @return set of colors in string hex presentation
*/
private Set<String> scanActualColors(BufferedImage image, final int stepX, final int stepY) {
Set<String> colors = new TreeSet<>();

try {
int height = image.getHeight();
int width = image.getWidth();
assertThat(width > 0).isTrue();
assertThat(height > 0).isTrue();

Raster raster = image.getRaster();
for (int i = 0; i < width; i = i + stepX) {
for (int j = 0; j < height; j = j + stepY) {
String hex =
String.format(
"#%02x%02x%02x",
(raster.getSample(i, j, 0)),
(raster.getSample(i, j, 1)),
(raster.getSample(i, j, 2)));
colors.add(hex);
}
}
} catch (Exception e) {
fail("Unable to get actual colors from screenshot: " + e.getMessage());
}

assertThat(colors).isNotEmpty();

return colors;
}

/**
* Compares sets of colors are same.
*
Expand Down
45 changes: 45 additions & 0 deletions java/test/org/openqa/selenium/testing/JupiterTestBase.java
Original file line number Diff line number Diff line change
Expand Up @@ -17,12 +17,18 @@

package org.openqa.selenium.testing;

import static org.assertj.core.api.Assertions.assertThat;
import static org.assertj.core.api.Assumptions.assumeThat;
import static org.junit.jupiter.api.Assertions.fail;

import java.awt.image.BufferedImage;
import java.awt.image.Raster;
import java.net.MalformedURLException;
import java.net.URL;
import java.time.Duration;
import java.util.Optional;
import java.util.Set;
import java.util.TreeSet;
import java.util.logging.Logger;
import org.junit.jupiter.api.AfterEach;
import org.junit.jupiter.api.BeforeAll;
Expand Down Expand Up @@ -116,4 +122,43 @@ public String toLocalUrl(String url) {
protected WebDriverWait wait(WebDriver driver) {
return new WebDriverWait(driver, Duration.ofSeconds(10));
}

/**
* Get colors from image from each point at grid defined by stepX/stepY.
*
* @param image - image
* @param stepX - interval in pixels b/w point in X dimension
* @param stepY - interval in pixels b/w point in Y dimension
* @return set of colors in string hex presentation
*/
protected final Set<String> scanActualColors(
BufferedImage image, final int stepX, final int stepY) {
Set<String> colors = new TreeSet<>();

try {
int height = image.getHeight();
int width = image.getWidth();
assertThat(width > 0).isTrue();
assertThat(height > 0).isTrue();

Raster raster = image.getRaster();
for (int i = 0; i < width; i = i + stepX) {
for (int j = 0; j < height; j = j + stepY) {
String hex =
String.format(
"#%02x%02x%02x",
(raster.getSample(i, j, 0)),
(raster.getSample(i, j, 1)),
(raster.getSample(i, j, 2)));
colors.add(hex);
}
}
} catch (Exception e) {
fail("Unable to get actual colors from screenshot: " + e.getMessage());
}

assertThat(colors).isNotEmpty();

return colors;
}
}