Skip to content

Latest commit

 

History

History
47 lines (27 loc) · 2.55 KB

File metadata and controls

47 lines (27 loc) · 2.55 KB

Uploading files with Cypress

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')

Suggested content

👨‍🏫 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.

Exercise

  1. Create a test called selects a file from the fixtures folder.
  2. The test should verify that, after file selection, the correct file's name is persisted in the files object of the input of type file.
  3. Run the new test in the Cypress App, and when it passes, move on.

Extra exercise 1

  1. Create a test called selects a file simulating a drag-and-drop.
  2. The test should verify that, after file selection, the correct file's name is persisted in the files object of the input of type file.
  3. Run the new test in the Cypress App, and when it passes, move on.

Extra exercise 2

  1. Create a test called selects a file using a fixture to which an alias was given.
  2. The test should verify that, after file selection, the correct file's name is persisted in the files object of the input of type file.
  3. Run the new test in the Cypress App, and when it passes, move on.

Show the world what you've learned

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.