Bird
0
0

You want to verify that a downloaded CSV file contains the header 'ID, Name, Email' and is not empty. Which Cypress test code correctly achieves this?

hard📝 Application Q15 of 15
Cypress - File Operations
You want to verify that a downloaded CSV file contains the header 'ID, Name, Email' and is not empty. Which Cypress test code correctly achieves this?
Acy.downloadFile('https://example.com/users.csv', 'cypress/downloads', 'users.csv') .then(() => { cy.readFile('cypress/downloads/users.csv').should('contain', 'ID, Name, Email').and('not.be.empty') })
Bcy.readFile('cypress/downloads/users.csv').should('contain', 'ID, Name, Email') cy.downloadFile('https://example.com/users.csv', 'cypress/downloads', 'users.csv')
Ccy.downloadFile('https://example.com/users.csv', 'cypress/downloads', 'users.csv') cy.readFile('cypress/downloads/users.csv').should('exist')
Dcy.downloadFile('https://example.com/users.csv', 'cypress/downloads', 'users.csv') .then(() => { cy.readFile('cypress/downloads/users.csv').should('be.empty') })
Step-by-Step Solution
Solution:
  1. Step 1: Ensure download completes before reading file

    cy.downloadFile('https://example.com/users.csv', 'cypress/downloads', 'users.csv') .then(() => { cy.readFile('cypress/downloads/users.csv').should('contain', 'ID, Name, Email').and('not.be.empty') }) chains .then() after downloadFile to wait for completion.
  2. Step 2: Verify file contains header and is not empty

    cy.downloadFile('https://example.com/users.csv', 'cypress/downloads', 'users.csv') .then(() => { cy.readFile('cypress/downloads/users.csv').should('contain', 'ID, Name, Email').and('not.be.empty') }) uses should('contain', ...) and .and('not.be.empty') correctly to check content and non-empty file.
  3. Final Answer:

    cy.downloadFile('https://example.com/users.csv', 'cypress/downloads', 'users.csv') .then(() => { cy.readFile('cypress/downloads/users.csv').should('contain', 'ID, Name, Email').and('not.be.empty') }) -> Option A
  4. Quick Check:

    Chain download and readFile with content checks = A [OK]
Quick Trick: Chain downloadFile with readFile and use should contain + not.be.empty [OK]
Common Mistakes:
  • Not chaining download and readFile causing timing issues
  • Checking file existence only without content validation
  • Asserting file is empty instead of not empty

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Cypress Quizzes