0
0
Cypresstesting~5 mins

File upload (cy.selectFile) in Cypress - Cheat Sheet & Quick Revision

Choose your learning style9 modes available
Recall & Review
beginner
What is the purpose of cy.selectFile() in Cypress?

cy.selectFile() is used to simulate a user selecting a file for upload in a test. It helps automate file upload testing by programmatically choosing files.

Click to reveal answer
beginner
How do you specify a file to upload using cy.selectFile()?

You provide the file path as a string or an object with file details inside cy.selectFile(). For example: cy.get('input[type=file]').selectFile('cypress/fixtures/sample.png').

Click to reveal answer
intermediate
What option do you use with cy.selectFile() to simulate a drag-and-drop file upload?

Use the option { action: 'drag-drop' } to simulate dragging and dropping a file onto the target element.

Click to reveal answer
intermediate
Why is it important to use fixtures for file upload tests in Cypress?

Fixtures store test files in a central place, making tests easier to maintain and share. Using fixtures ensures consistent file content and paths during tests.

Click to reveal answer
intermediate
What assertion can you use to verify a file was uploaded successfully after using cy.selectFile()?

You can check the input element's files property or verify UI changes like file name display. For example: cy.get('input[type=file]').should('have.prop', 'files').and('have.length', 1).

Click to reveal answer
Which command in Cypress is used to simulate file selection for upload?
Acy.chooseFile()
Bcy.uploadFile()
Ccy.fileUpload()
Dcy.selectFile()
How do you simulate a drag-and-drop file upload with cy.selectFile()?
AUse <code>{ drag: true }</code> option
BUse <code>{ action: 'drag-drop' }</code> option
CUse <code>{ drop: true }</code> option
DUse <code>{ simulateDrag: true }</code> option
Where should test files be stored for easy access in Cypress file upload tests?
AIn the plugins folder
BIn the support folder
CIn the fixtures folder
DIn the node_modules folder
What type of HTML element does cy.selectFile() usually target?
A<input type="file">
B<button>
C<textarea>
D<select>
Which assertion checks that exactly one file was selected after upload?
Ashould('have.prop', 'files').and('have.length', 1)
Bshould('contain.text', '1 file')
Cshould('have.value', 'file1.txt')
Dshould('be.visible')
Explain how to use cy.selectFile() to upload a file in a Cypress test.
Think about selecting the file, how to specify it, and how to check it worked.
You got /4 concepts.
    Describe why using fixtures is helpful for file upload testing in Cypress.
    Consider how test files are managed and reused.
    You got /4 concepts.