plasmaboyer / cypress-downloadfile

Cypress File download custom command

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

cypress-downloadfile

npm version

This is a Cypress custom file download command.

This repository is not maintained by the Cypress developers.

Installation

Install the module.

npm install cypress-downloadfile

Add the following line to cypress/support/commands.js.

require('cypress-downloadfile/lib/downloadFileCommand')

Add the following lines to cypress/plugins/index.js.

const {downloadFile} = require('cypress-downloadfile/lib/addPlugin')
module.exports = (on, config) => {
  on('task', {downloadFile})
}

If autocompletion does not work out of the box you can add the following line above your testfile

/// <reference types="cypress-downloadfile"/>

Example of basic command

cy.downloadFile('https://library.concordia.ca/help/technology/recovering_saved_files.pdf','mydownloads','demo.pdf')

In Version 1.6 you can now also pass in the headers. If no User-Agent is defined in headers, it will give a default User-Agent called "request".

const token = '<my bearer token>'

var headers = {
  authorization: 'Bearer ' + token,
  accept: 'application/json',
  'accept-language': 'en-US,en;q=0.9,fr-FR;q=0.8,fr;q=0.7',
  'User-Agent': 'a-specific-useragent'
}

cy.downloadFile('https://library.concordia.ca/help/technology/recovering_saved_files.pdf','mydownloads','demo.pdf', headers)

About

Cypress File download custom command

License:MIT License


Languages

Language:JavaScript 100.0%