0
0
Cypresstesting~10 mins

File upload (cy.selectFile) in Cypress - Interactive Code Practice

Choose your learning style9 modes available
Practice - 5 Tasks
Answer the questions below
1fill in blank
easy

Complete the code to select a file for upload using Cypress.

Cypress
cy.get('input[type="file"]').[1]('example.json')
Drag options to blanks, or click blank then click option'
AattachFile
Bclick
Ctype
DselectFile
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'click' instead of 'selectFile' to upload files.
Trying to use 'type' to input file paths.
2fill in blank
medium

Complete the code to select a file with a specific file path.

Cypress
cy.get('input[type="file"]').selectFile([1]: 'cypress/fixtures/sample.png'})
Drag options to blanks, or click blank then click option'
AfilePath
Bcontents
Cpath
Dfile
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'contents' instead of 'filePath' to specify the file location.
Using 'path' which is not a valid option here.
3fill in blank
hard

Fix the error in the code to correctly select multiple files.

Cypress
cy.get('input[type="file"]').selectFile([[1]])
Drag options to blanks, or click blank then click option'
A['file1.png', 'file2.png']
B'file1.png', 'file2.png'
C'file1.png'
Dfile1.png, file2.png
Attempts:
3 left
💡 Hint
Common Mistakes
Passing multiple file names as a single string separated by commas.
Not using an array to select multiple files.
4fill in blank
hard

Fill both blanks to select a file and assert the file name is correct.

Cypress
cy.get('input[type="file"]').selectFile([1]).should('have.prop', [2])
Drag options to blanks, or click blank then click option'
A{ filePath: 'test.pdf' }
B'files'
C'files[0].name'
D'fileName'
Attempts:
3 left
💡 Hint
Common Mistakes
Using incorrect property names in the assertion.
Not passing the file path as an object.
5fill in blank
hard

Fill all three blanks to select a file with contents and verify its size.

Cypress
cy.get('input[type="file"]').selectFile([1]).then(fileInput => {
  expect(fileInput[0].files[0].[2]).to.equal([3])
})
Drag options to blanks, or click blank then click option'
A{ contents: 'Hello World', fileName: 'hello.txt' }
Bsize
C11
Dlength
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'length' instead of 'size' for file size.
Not providing both contents and fileName in the file object.