Test Overview
This test checks if a user can successfully upload a file by dragging and dropping it onto the upload area. It verifies that the file appears in the upload list after dropping.
This test checks if a user can successfully upload a file by dragging and dropping it onto the upload area. It verifies that the file appears in the upload list after dropping.
describe('Drag and drop file upload', () => { it('uploads a file by drag and drop', () => { cy.visit('https://example.com/upload'); const fileName = 'sample.txt'; cy.get('#drag-drop-area').attachFile(fileName, { subjectType: 'drag-n-drop' }); cy.get('#upload-list').should('contain.text', fileName); }); });
| 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 with drag and drop area visible | URL is correct and page loaded | PASS |
| 3 | Finds the drag and drop area with selector '#drag-drop-area' | Drag and drop area is visible and ready for interaction | Element '#drag-drop-area' exists and is visible | PASS |
| 4 | Simulates dragging and dropping the file 'sample.txt' onto the drag and drop area | File 'sample.txt' is dropped onto the upload area | — | PASS |
| 5 | Checks that the upload list '#upload-list' contains the text 'sample.txt' | Upload list shows 'sample.txt' as uploaded | Verify '#upload-list' contains 'sample.txt' | PASS |
subjectType: 'drag-n-drop' in Cypress file upload tests?subjectType: 'drag-n-drop' option in Cypress simulates the user dragging a file and dropping it into a target area, mimicking real user behavior.example.png into an element with selector #dropzone?attachFile with the option { subjectType: 'drag-n-drop' } to simulate drag and drop.#dropzone and attaches example.png correctly with the required option.testfile.pdf is successfully dropped?cy.get('#upload-area').attachFile('testfile.pdf', { subjectType: 'drag-n-drop' })
cy.get('#upload-message').should('contain.text', 'Upload successful')attachFile with subjectType: 'drag-n-drop' correctly to simulate dropping testfile.pdf.#upload-message contains the text 'Upload successful', which indicates a successful upload.attachFile is not a function. What is the most likely cause?cy.get('#dropzone').attachFile('file.txt', { subjectType: 'drag-n-drop' })attachFile is not a function means Cypress does not recognize the attachFile command.commands.js.img1.png and img2.png into the element .upload-area?{ subjectType: 'drag-n-drop' } must be included.Pass the test and this pattern moves unknown