On version 9.3.0, Cypress released the .selectFile()
command.
This functionality, as the name suggests, is used for selecting files.
Such a command is useful when we need to include an attachment to a form, as the TAT CSC application allows us to do.
You can use cy.get('input[type="file"]')
to identify a file selection field, and chain the .selectFile()
command, passing to it the relative path of the file you intend to upload (based on the project’s root directory.)
For example: cy.get('input[type="file"]').selectFile('cypress/fixtures/example.json')
👨🏫 Althought the content mentions the
cypress-file-upload
plugin, it also mentions the new.selectFile
command, so read it untill the end. After all, it's good know it exists.
- Create a test called
selects a file from the fixtures folder
. - The test should verify that, after file selection, the correct file's
name
is persisted in thefiles
object of theinput
of typefile
. - Run the new test in the Cypress App, and when it passes, move on.
- Create a test called
selects a file simulating a drag-and-drop
. - The test should verify that, after file selection, the correct file's
name
is persisted in thefiles
object of theinput
of typefile
. - Run the new test in the Cypress App, and when it passes, move on.
- Create a test called
selects a file using a fixture to which an alias was given
. - The test should verify that, after file selection, the correct file's
name
is persisted in thefiles
object of theinput
of typefile
. - Run the new test in the Cypress App, and when it passes, move on.
To show your professional network what you've learned so far, post the following on LinkedIn.
I'm going through the "Cypress, from Zero to the Cloud" course, from the Talking About Testig online school, where I learned how to test file uploading. #TalkingAboutTesting #TATSchool #CypressFromZeroToTheCloud #Cypress
Note: Remember to tag me in your post. Here's my LinkedIn profile.
Congrats! Let's go to lesson 7 to learn how to handle links that open in another browser tab.