Bird
0
0

Given this Cypress code snippet:

medium📝 Predict Output Q4 of 15
Cypress - File Operations
Given this Cypress code snippet:
cy.get('#dropzone').attachFile('doc.pdf', { subjectType: 'drag-n-drop' });
cy.get('#file-name').should('contain.text', 'doc.pdf');

What will be the test result if the file is correctly uploaded?
ATest passes but file name is not checked
BTest fails because attachFile does not support drag-n-drop
CTest fails due to syntax error in attachFile
DTest passes because the file name appears in the element
Step-by-Step Solution
Solution:
  1. Step 1: Analyze attachFile with drag-n-drop

    The command correctly simulates drag and drop file upload on the element with id 'dropzone'.
  2. Step 2: Check assertion logic

    The assertion verifies that the element with id 'file-name' contains the text 'doc.pdf', which should be true after upload.
  3. Final Answer:

    Test passes because the file name appears in the element -> Option D
  4. Quick Check:

    Correct upload + assertion = pass [OK]
Quick Trick: Correct attachFile + assertion = test passes [OK]
Common Mistakes:
  • Assuming attachFile lacks drag-n-drop support
  • Confusing syntax errors with option errors
  • Ignoring the assertion check

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Cypress Quizzes