E2E File Download

Websites might expose files for users to download and then access from their local machine. Common cases are downloading tickets, receipts and itineraries.

# Steps

This example runs against our test webshop and proceeds to download a receipt for a previous purchase. It includes the following steps:

  1. Logging in to the website
  2. Navigating to the account page
  3. Downloading a linked file

We will check that the downloaded file is as expected by comparing it to a fixture file in our final assertion.

We can approach this scenario in different ways. One possibility is to perform the first two steps, then extract the href value and use it to retrieve the file with a GET request (performed with axios, for example).

    We could also click the link directly and wait for the download event, then proceed with the comparison. Waiting for the download event is currently supported by Playwright, but not by Puppeteer.

    Note that in this case, we need to enable downloads in the browser context before proceeding.

      Both examples can be run as follows:

        # Takeaways

        1. Use environment variables to inject secrets.
        2. Compare the expected file with the newly downloaded one.
        3. There is more than one way to download a file within our script.

        # Further reading

        1. Playwright's documentation on downloading files.