Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

119
Visualizações
cypress - compare two png images

The functionality is - after inputting some values in the UI, I will have an image download option and once download, I need to compare that PNG image with my base image which I already have in my cypress/fixtures/base/<nameOfTheFile.png>.

I am trying to make a utility function in cypress to compare two PNG images but I get issues one after another for all my approaches.

Utils.js (under integration folder)

const fs = require('fs');

export const comparePNGImages = (fileName) => {

    expect(fileName).to.be.a('string')

    const img1 = fs.readFileSync("./cypress/fixtures/baseImage/" + fileName);
    const img2 = fs.readFileSync("./cypress/fixtures/currentImage/" + fileName);

    expect(img1).to.matchImage(img2)

    return null;
}

and in test,

import { downloadPng, comparePNGImages } from './utils'
.........

var imageName = "SailingDirection.png";

//steps to input, download the image file, keep in fixtures folder
//.....

comparePNGImages(imageName)

.........

Error in TestRunner:

fs.readFileSync is not a function

Note:

I tried to change the import statement to the following:

import fs from 'fs';
import { fs } from 'fs';

but none worked.

Also, read that fs will not have access to the local file system but surprisingly, the same fs stuff works in the same cypress project which is in other file plugins/index.js

const fs = require('fs');
on('task', {
        validateTotalFileCount(folderName, expectedFileCount) {
            console.log("#### getTotalFileCount #### ");
            const length = fs.readdirSync(folderName).length;
            if (length == expectedFileCount) {
                throw new Error(`#### List of files not matched with expected count`)
            }
            return null;
        }
    })

Any help on this to fix it would be much appreciated.

about 4 years ago · Juan Pablo Isaza
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda