Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

118
Views
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
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!