Bird
0
0

You want to test uploading multiple files at once using cy.selectFile. Which code snippet correctly uploads two files named doc1.pdf and image1.png located in the fixtures folder?

hard📝 Application Q15 of 15
Cypress - File Operations
You want to test uploading multiple files at once using cy.selectFile. Which code snippet correctly uploads two files named doc1.pdf and image1.png located in the fixtures folder?
Acy.get('input[type=file]').selectFile({ files: ['doc1.pdf', 'image1.png'] })
Bcy.get('input[type=file]').selectFile('cypress/fixtures/doc1.pdf, cypress/fixtures/image1.png')
Ccy.get('input[type=file]').selectFile(['cypress/fixtures/doc1.pdf', 'cypress/fixtures/image1.png'])
Dcy.get('input[type=file]').selectFile(['doc1.pdf', 'image1.png'])
Step-by-Step Solution
Solution:
  1. Step 1: Understand multiple file upload syntax

    cy.selectFile accepts an array of file paths to upload multiple files. Each path must be relative to the fixtures folder or absolute.
  2. Step 2: Evaluate each option

    cy.get('input[type=file]').selectFile(['cypress/fixtures/doc1.pdf', 'cypress/fixtures/image1.png']) correctly provides an array with full fixture paths. cy.get('input[type=file]').selectFile('cypress/fixtures/doc1.pdf, cypress/fixtures/image1.png') uses a single string with comma-separated paths, which is invalid. cy.get('input[type=file]').selectFile({ files: ['doc1.pdf', 'image1.png'] }) uses an object with files array but missing paths. cy.get('input[type=file]').selectFile(['doc1.pdf', 'image1.png']) uses array without fixture folder path, which will fail.
  3. Final Answer:

    cy.get('input[type=file]').selectFile(['cypress/fixtures/doc1.pdf', 'cypress/fixtures/image1.png']) -> Option C
  4. Quick Check:

    Array of fixture paths = Correct multiple upload [OK]
Quick Trick: Use array of full fixture paths for multiple files [OK]
Common Mistakes:
  • Passing comma-separated string instead of array
  • Omitting fixture folder in paths
  • Using object without correct file paths

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Cypress Quizzes