Test Overview
This test checks if a file upload and download feature works correctly on a web page. It verifies that the file is uploaded successfully and that the downloaded file matches the uploaded one.
This test checks if a file upload and download feature works correctly on a web page. It verifies that the file is uploaded successfully and that the downloaded file matches the uploaded one.
describe('File Upload and Download Validation', () => { it('should upload a file and verify download content', () => { cy.visit('https://example.com/file-upload-download') // Upload file const fileName = 'sample.txt' cy.get('input[type=file]').attachFile(fileName) cy.get('#upload-button').click() // Verify upload success message cy.get('#upload-success').should('contain.text', 'Upload successful') // Trigger file download cy.get('#download-link').click() // Read downloaded file and verify content const downloadsFolder = Cypress.config('downloadsFolder') cy.readFile(`${downloadsFolder}/${fileName}`).should('contain', 'This is a sample file for testing.') }) })
| Step | Action | System State | Assertion | Result |
|---|---|---|---|---|
| 1 | Test starts and navigates to the file upload/download page | Browser opens at https://example.com/file-upload-download with upload input and download link visible | - | PASS |
| 2 | Finds file input element and attaches 'sample.txt' file | File input has 'sample.txt' ready for upload | - | PASS |
| 3 | Clicks the upload button to submit the file | Upload process starts | - | PASS |
| 4 | Checks for upload success message '#upload-success' containing 'Upload successful' | Success message displayed on page | Verify text 'Upload successful' is present | PASS |
| 5 | Clicks the download link to download the file | Browser starts downloading 'sample.txt' | - | PASS |
| 6 | Reads the downloaded file from the downloads folder | 'sample.txt' file is present in downloads folder | File content contains 'This is a sample file for testing.' | PASS |