Cypress downloads a blank PDF file from the UI
See original GitHub issueCurrent behavior:
Cypress downloads a blank PDF
Desired behavior:
Cypress should download the same PDF as downloaded manually
Test code to reproduce
Complete reproducible code with ReadMe is uploaded here: _https://github.com/abhidp/cypress-pdf-download_
Tests will run against the url: _https://receipts.uat-slyp.com.au/WRA-ba8511d6f86fcd488cc335a356ccadd2d37f1c30_
Instructions:
- clone this repo :
git clone https://github.com/abhidp/cypress-pdf-download.git
- install dependencies:
npm install
- open Cypress runner :
npm run cy:open
- choose Chrome as the browser
- execute test :
pdfExport.spec.js
Test#1
andTest#3
will passTest#2
will fail because the downloaded PDF file is blank which is what this issue is all about
Problem:
When the above steps are executed in Cypress, it downloads a blank PDF file: /cypress/downloads/SlypReceipt.pdf
When manually downloaded, you get the correct PDF file: /cypress/downloads/SlypReceipt_Working.pdf
Actual Result: Cypress downloads a blank PDF Expected Result: Cypress should download the same PDF as downloaded manually
Replication steps to download the PDF manually:
- navigate to the above url
- click on the Kebab menu (three vertical dots) at the top right corner of the page
- click on
Export as PDF
option and save it to your local disk
PDF downloaded by Cypress | PDF downloaded manually |
---|---|
Versions
Macbook Pro:
ProductName: Mac OS X
ProductVersion: 10.15.5
BuildVersion: 19F101
Cypress: 4.12.1
Browser:
Google Chrome is up to date
Version 84.0.4147.105 (Official Build) (64-bit)
Issue Analytics
- State:
- Created 3 years ago
- Reactions:1
- Comments:14 (1 by maintainers)
Top Results From Across the Web
Cypress downloads a blank PDF file from the UI · Issue #8232 ...
Current behavior: Cypress downloads a blank PDF. Desired behavior: Cypress should download the same PDF as downloaded manually. Test code to reproduce.
Read more >Part 36 - Cypress - Download and Validate ... - YouTube
Part 36 - Cypress - Download and Validate Downloaded File (Image/Word/ PDF ). Watch later. Share. Copy link. Info. Shopping. Tap to unmute....
Read more >Need guidance for downloading pdf in cypress - Stack Overflow
I am writing a E2e test case in cypress in which I have to download a pdf file and also I have to...
Read more >Testing a PDF file with Cypress - Filip Hric
But how do we know if anything happened? Well first of all, we can check that manually, by taking a look into /cypress/downloads...
Read more >readFile - Cypress Documentation
Read a file and yield its contents. Syntax Usage Correct Usage Arguments filePath (String) A path to a file within the project root...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
I can recreate this from the repo provided - the PDF downloaded within the Cypress Test Runner is blank.
I got stuck for 2 days on this and in my case I had to explicitly tell the API what type of encoding I’m expecting to get:
cy.request({ url: 'your-url', encoding: 'binary' }).then((res) => { cy.writeFile('cypress/downloads/whatever.pdf', res.body, { encoding: 'binary' }) })
Check the request object, I’m explicitly saying ‘encoding: ‘binary’’ in request and in writeFile command. Without one or both of them, I was getting blank document. Hopefully someone will find it helpful.