Test Overview
This test automates uploading a file using Cypress's cy.selectFile command. It verifies that the file input accepts the file and that the file name is displayed correctly after upload.
This test automates uploading a file using Cypress's cy.selectFile command. It verifies that the file input accepts the file and that the file name is displayed correctly after upload.
describe('File upload test', () => { it('uploads a file and verifies the file name', () => { cy.visit('https://example.com/upload') cy.get('input[type="file"]').selectFile('cypress/fixtures/sample.txt') cy.get('#file-name-display').should('contain.text', 'sample.txt') }) })
| Step | Action | System State | Assertion | Result |
|---|---|---|---|---|
| 1 | Test starts | Test runner initialized, no browser opened yet | - | PASS |
| 2 | Browser opens and navigates to 'https://example.com/upload' | Upload page is loaded with a file input and a file name display element | Page loaded successfully | PASS |
| 3 | Finds the file input element using selector 'input[type="file"]' | File input element is visible and enabled | File input element exists | PASS |
| 4 | Uploads the file 'cypress/fixtures/sample.txt' using cy.selectFile | File input now contains the selected file | File input value updated with 'sample.txt' | PASS |
| 5 | Finds the element with id 'file-name-display' to verify uploaded file name | Element visible on page showing uploaded file name | Element text contains 'sample.txt' | PASS |
| 6 | Test ends with all assertions passing | File upload verified successfully | All assertions passed | PASS |