Challenge - 5 Problems
File Download Verification Master
Get all challenges correct to earn this badge!
Test your skills under time pressure!
❓ Predict Output
intermediate2: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) })
Attempts:
2 left
💡 Hint
cy.readFile can check if a file exists after download
✗ Incorrect
The code downloads the file and then checks if it exists in the downloads folder. This confirms the download succeeded.
❓ assertion
intermediate1: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(____)Attempts:
2 left
💡 Hint
Use the correct Cypress string assertion for substring matching
✗ Incorrect
The 'contain' assertion checks if the file content includes the given substring.
🔧 Debug
advanced2: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)
Attempts:
2 left
💡 Hint
Downloads may take time; reading file immediately can fail
✗ Incorrect
The test tries to read the file immediately after clicking download, but the file may not be fully saved yet.
🧠 Conceptual
advanced2:30remaining
Best practice for verifying file downloads in Cypress
Which approach is best to verify a file download in Cypress tests?
Attempts:
2 left
💡 Hint
Intercepting network requests gives more control and certainty
✗ Incorrect
Intercepting the download request allows verifying the actual file content and status before checking the file system.
❓ framework
expert3: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) })
Attempts:
2 left
💡 Hint
Use timeout option in cy.readFile to wait for file
✗ Incorrect
Setting a timeout in cy.readFile allows waiting for the file to appear before asserting existence.