Bird
0
0

What is wrong with this Cypress drag and drop file upload code?

medium📝 Debug Q7 of 15
Cypress - File Operations
What is wrong with this Cypress drag and drop file upload code?
cy.get('.dropzone').attachFile('image.jpg', { subjectType: 'drag-n-drop' });
cy.get('.filename').should('contain.text', 'image.png');
ASelector '.dropzone' is incorrect
BattachFile does not support drag-n-drop
CAssertion expects wrong file name 'image.png' instead of 'image.jpg'
DMissing file encoding option
Step-by-Step Solution
Solution:
  1. Step 1: Check file name consistency

    The file uploaded is 'image.jpg' but the assertion checks for 'image.png', causing failure.
  2. Step 2: Validate other code parts

    attachFile supports drag-n-drop, selectors are valid, encoding option is optional.
  3. Final Answer:

    Assertion expects wrong file name 'image.png' instead of 'image.jpg' -> Option C
  4. Quick Check:

    Assertion file name must match uploaded file [OK]
Quick Trick: Match assertion file name exactly with uploaded file [OK]
Common Mistakes:
  • Mismatched file names in assertions
  • Doubting attachFile drag-n-drop support
  • Assuming selectors are wrong without checking

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Cypress Quizzes