0
0
Cypresstesting~10 mins

Drag and drop file upload in Cypress - Test Execution Trace

Choose your learning style9 modes available
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.

Test Code - Cypress
Cypress
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);
  });
});
Execution Trace - 5 Steps
StepActionSystem StateAssertionResult
1Test startsTest runner initialized, no browser opened yet-PASS
2Browser opens and navigates to 'https://example.com/upload'Upload page with drag and drop area visibleURL is correct and page loadedPASS
3Finds the drag and drop area with selector '#drag-drop-area'Drag and drop area is visible and ready for interactionElement '#drag-drop-area' exists and is visiblePASS
4Simulates dragging and dropping the file 'sample.txt' onto the drag and drop areaFile 'sample.txt' is dropped onto the upload area-PASS
5Checks that the upload list '#upload-list' contains the text 'sample.txt'Upload list shows 'sample.txt' as uploadedVerify '#upload-list' contains 'sample.txt'PASS
Failure Scenario
Failing Condition: The drag and drop area selector '#drag-drop-area' is missing or file drop does not trigger upload
Execution Trace Quiz - 3 Questions
Test your understanding
What does the test verify after dropping the file?
AThe file is deleted from the system
BThe page URL changes
CThe file name appears in the upload list
DThe drag and drop area disappears
Key Result
Always verify that the element selectors used for drag and drop are correct and visible before simulating file upload to avoid false failures.