0
0
Cypresstesting~20 mins

File download verification in Cypress - Practice Problems & Coding Challenges

Choose your learning style9 modes available
Challenge - 5 Problems
🎖️
File Download Verification Master
Get all challenges correct to earn this badge!
Test your skills under time pressure!
Predict Output
intermediate
2:00remaining
Verify file download success with Cypress
What will be the result of this Cypress test code when verifying a file download?
Cypress
cy.downloadFile('https://example.com/report.pdf', 'cypress/downloads', 'report.pdf')
  .then(() => {
    cy.readFile('cypress/downloads/report.pdf').should('have.length.above', 0)
  })
ATest fails because cy.readFile cannot read PDF files
BTest passes but file content is not verified
CTest fails due to syntax error in chaining
DTest passes because the file is downloaded and exists in the folder
Attempts:
2 left
💡 Hint
cy.readFile can check if a file exists after download
assertion
intermediate
1:30remaining
Correct assertion to verify downloaded file content
Which assertion correctly verifies that the downloaded text file contains the word 'Success'?
Cypress
cy.readFile('cypress/downloads/result.txt').should(____)
A"have.text", "Success"
B"contain", "Success"
C"include", "Success"
D"include.text", "Success"
Attempts:
2 left
💡 Hint
Use the correct Cypress string assertion for substring matching
🔧 Debug
advanced
2:00remaining
Identify the error in this file download test
Why does this Cypress test fail to verify the downloaded file?
Cypress
cy.get('#download-btn').click()
cy.readFile('cypress/downloads/report.pdf').should('have.length.above', 0)
Acy.readFile cannot read PDF files
BThe selector '#download-btn' is invalid
CThe test does not wait for the download to complete before reading the file
DThe file path is incorrect
Attempts:
2 left
💡 Hint
Downloads may take time; reading file immediately can fail
🧠 Conceptual
advanced
2:30remaining
Best practice for verifying file downloads in Cypress
Which approach is best to verify a file download in Cypress tests?
AIntercept the download request and check the response headers and body
BClick download button and immediately check file existence in downloads folder
CUse cy.readFile to read the file before clicking download
DCheck the UI message that says 'Download started' without checking the file
Attempts:
2 left
💡 Hint
Intercepting network requests gives more control and certainty
framework
expert
3:00remaining
Implementing a custom Cypress command for file download verification
Which custom Cypress command implementation correctly waits for a file to be downloaded and verifies its existence?
Cypress
Cypress.Commands.add('verifyDownload', (fileName) => {
  const downloadsFolder = Cypress.config('downloadsFolder')
  cy.readFile(`${downloadsFolder}/${fileName}`, { timeout: 15000 }).should('have.length.above', 0)
})
AThe command waits up to 15 seconds for the file to exist and asserts its presence
BThe command immediately reads the file without waiting, causing flaky tests
CThe command uses incorrect path syntax causing a runtime error
DThe command only checks file size but not existence
Attempts:
2 left
💡 Hint
Use timeout option in cy.readFile to wait for file