Home > OS >  Trying compare 2 CSV File in Cypress
Trying compare 2 CSV File in Cypress

Time:04-28

I'm trying to compare 2 CSV files, the intention is to verify that what I'm uploading contains the same information as what I'm downloading. The problem is that only 1 of the files is returning the values, the other one returns null.

it.only('Download a Material', function () {

  var csvDownloaded = 'cypress/downloads/Materiais.csv';
  var csvUploaded = 'cypress/fixtures/materials-configuration/MaterialsUpload.csv'

  materialsConfig.donwloadCsv();
  cy.readFile(csvUploaded, 'utf-8').then((uploadTxt) => {
    cy.readFile(csvDownloaded, 'utf-8', { timeout: 10000 }).then((downloadTxt) => {
      cy.readFile(downloadTxt, 'utf-8', { timeout: 40000 }).should('eq',uploadTxt)
    });
  });
});

enter image description here

CodePudding user response:

I think your problem is that you don't need to use cy.readFile on the result of cy.readFile(csvDownloaded), but can instead just compare it's result with the result of cy.readFile(csvUploaded). I think you're getting null for one of your comparison values because cy.readFile(downloadText) isn't a filepath that Cypress can find and open.

  cy.readFile(csvUploaded, 'utf-8').then((uploadTxt) => {
    cy.readFile(csvDownloaded, 'utf-8', { timeout: 10000 }).then((downloadTxt) => {
      expect(downloadTxt).to.equal(uploadTxt);
    });
  });
  • Related