Skip to main content

File downloads

DrevOps\BehatSteps\Steps\Web\FileDownloadTrait - Source, Example, Helpers

Test file download functionality with content verification.

  • Download files through links and URLs with session cookie handling.
  • Verify file names, content, and zip archive entries.
  • Set up download directories and handle file cleanup.

Skip processing with tag: @behat-steps-skip:FileDownloadTrait.

Special tags:

  • @download - enable download handling

Options​

OptionTypeDefaultTagDescription
file_download.enabledbooleanTRUE@behat-steps-skip:FileDownloadTraitIf TRUE, empties and creates the temp_dir directory before a @download scenario and deletes it afterwards. If FALSE, the download steps need that directory to exist already.
file_download.temp_dirstring'/tmp/behat_downloads'-The directory the download steps write downloaded files into. A @download scenario deletes it, with everything in it, before and after the scenario. A relative path resolves against the working directory, which bootstrapping Drupal in-process changes, so an absolute path is safer.
file_download.timeoutinteger120-The time, in seconds, a download can go without receiving data before it fails.

Steps​

@When I download the file from the URL :url

Download a file from the specified URL

When I download the file from the URL "/files/document.pdf"
When I download the file from the URL "http://example.com/files/report.xlsx"
@When I download the file from the link :link

Download the file from the specified HTML link

When I download the file from the link "Download PDF"
When I download the file from the link "Get Report"
@Then the downloaded file should contain:

Assert the contents of the download file

Then the downloaded file should contain:
"""
Financial Report 2023
"""
@Then the downloaded file name should be :name

Assert the file name of the downloaded file

Then the downloaded file name should be "report.pdf"
@Then the downloaded file name should contain :partial_name

Assert the downloaded file name contains a specific string

Then the downloaded file name should contain "report"
@Then the downloaded file should be a zip archive containing files with the following names:

Assert the downloaded file should be a zip archive containing specific files

Then the downloaded file should be a zip archive containing files with the following names:
| document.pdf |
| image.jpg |
| data.csv |
@Then the downloaded file should be a zip archive containing files with the following partial names:

Assert the downloaded file should be a zip archive containing files with partial names

Then the downloaded file should be a zip archive containing files with the following partial names:
| report |
| data |
| image |
@Then the downloaded file should be a zip archive not containing files with the following partial names:

Assert the downloaded file is a zip archive not containing files with partial names

Then the downloaded file should be a zip archive not containing files with the following partial names:
| confidential |
| private |
| draft |