Screenshots having different sizes on different PCs in Selenium Grid Screenshots having different sizes on different PCs in Selenium Grid selenium selenium

Screenshots having different sizes on different PCs in Selenium Grid


The issue is not the size of the image, but the Alpha channel (transparency) which is present in the base drawing and missing in the screenshot.

The driver is supposed to return a PNG Base64 encoded string. But it's not specified whether it should be a 24-bit RGB or 32-bit RGBA PNG.So to be able to compare the buffers, you'll first have to convert each one of them to the desired color space.

Here's an example:

public static void main(String[] args) throws Exception {    BufferedImage imageA = ImageIO.read(new File("C:\\temp\\img_24bits.png"));    BufferedImage imageB = ImageIO.read(new File("C:\\temp\\img_32bits.png"));    boolean same = isSameImage(imageA, imageB);}public static boolean isSameImage(BufferedImage imageA, BufferedImage imageB) throws IOException {    DataBufferInt bufferA = getImageBuffer(imageA);    DataBufferInt bufferB = getImageBuffer(imageB);    if (bufferA.getSize() != bufferB.getSize() || bufferA.getNumBanks() != bufferB.getNumBanks())        return false;    for (int i = 0; i < bufferA.getNumBanks(); ++i) {        if (!Arrays.equals(bufferA.getData(i), bufferB.getData(i)))            return false;    }    return true;}private static DataBufferInt getImageBuffer(BufferedImage img) throws IOException {    BufferedImage  bi  = new BufferedImage(img.getWidth(), img.getHeight(), BufferedImage.TYPE_INT_ARGB);    ColorConvertOp cco = new ColorConvertOp(bi.getColorModel().getColorSpace(), img.getColorModel().getColorSpace(), null);    cco.filter(img, bi);    return (DataBufferInt)bi.getRaster().getDataBuffer();}


Although @Florent B.'s answer gave me a direction to approach the solution, but here's what I did to solve this issue.

  1. Checked whether the bit depth of the image is 24 or 32.
  2. If it is 32, then removed all the alpha channels from it.
  3. Next, I set a range that if the difference between the RGB values of the pixels of two corresponding images was less than 10, then consider those images as same.


I think you must use a command to set the resolution of the executed driver.To do so add in Java

driver.manage().window().setSize(new Dimension (1280, 1024));

before your teststeps.Now the screenshot will always have the same resolution.