0
0
Cypresstesting~20 mins

Drag and drop file upload in Cypress - Practice Problems & Coding Challenges

Choose your learning style9 modes available
Challenge - 5 Problems
🎖️
Drag and Drop File Upload Master
Get all challenges correct to earn this badge!
Test your skills under time pressure!
Predict Output
intermediate
2:00remaining
Output of Cypress drag and drop file upload test
What will be the test result when running this Cypress test code for drag and drop file upload?
Cypress
describe('Drag and Drop File Upload', () => {
  it('uploads a file via drag and drop', () => {
    cy.visit('/upload')
    cy.get('#dropzone').attachFile('example.pdf', { subjectType: 'drag-n-drop' })
    cy.get('#uploaded-file-name').should('contain.text', 'example.pdf')
  })
})
ATest fails because the selector '#dropzone' does not exist
BTest fails with error: attachFile is not a function
CTest passes because the file is correctly attached and verified
DTest passes but the assertion fails due to wrong file name
Attempts:
2 left
💡 Hint
Check if the attachFile command is used correctly with drag-n-drop option.
locator
intermediate
1:30remaining
Best locator for drag and drop file upload area
Which locator is the best practice to select the drag and drop upload area for testing accessibility and reliability?
Acy.get('[aria-label="File Upload Dropzone"]')
Bcy.get('div').contains('Drop files here')
Ccy.get('#upload-area')
Dcy.get('.dropzone')
Attempts:
2 left
💡 Hint
Consider accessibility attributes and stable selectors.
assertion
advanced
1:30remaining
Correct assertion for verifying file upload success message
Which assertion correctly verifies that the success message 'Upload complete' is visible after drag and drop file upload?
Acy.get('#message').should('have.text', 'Upload complete')
Bcy.get('#message').should('contain.text', 'Upload complete')
Ccy.get('#message').should('include.text', 'Upload complete')
Dcy.get('#message').should('be.visible').and('contain', 'Upload complete')
Attempts:
2 left
💡 Hint
Check for visibility and partial text match.
🔧 Debug
advanced
2:00remaining
Identify the error in this drag and drop file upload test code
What error will this Cypress test code produce when running drag and drop file upload?
Cypress
cy.get('#dropzone').attachFile('test.png')
cy.get('#uploaded-file').should('contain', 'test.png')
ATest fails because attachFile requires subjectType: 'drag-n-drop' for dropzones
BError: attachFile missing drag-n-drop option for dropzone
CTest passes without errors
DError: Cannot find file 'test.png'
Attempts:
2 left
💡 Hint
Consider how attachFile works with drag and drop elements.
framework
expert
3:00remaining
Best practice for testing drag and drop file upload in Cypress with accessibility
Which approach best combines accessibility, reliability, and maintainability when testing drag and drop file upload in Cypress?
AUse cy.get('#upload').attachFile('file.pdf') without drag-n-drop option and assert with cy.get('#message').should('have.text', 'Upload complete')
BUse cy.get('[aria-label="Upload Area"]').attachFile('file.pdf', { subjectType: 'drag-n-drop' }) and assert visibility and text with should('be.visible').and('contain.text', 'Upload complete')
CUse cy.get('.dropzone').attachFile('file.pdf', { subjectType: 'drag-n-drop' }) and assert with cy.contains('Upload complete')
DUse cy.get('input[type=file]').attachFile('file.pdf') and assert with cy.get('.success').should('exist')
Attempts:
2 left
💡 Hint
Think about accessibility attributes and proper assertions.