question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Cypress downloads a blank PDF file from the UI

See original GitHub issue

Current 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 and Test#3 will pass
  • Test#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 image
  • click on Export as PDF option and save it to your local disk
PDF downloaded by Cypress PDF downloaded manually
image image

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:open
  • Created 3 years ago
  • Reactions:1
  • Comments:14 (1 by maintainers)

github_iconTop GitHub Comments

7reactions
jennifer-shehanecommented, Aug 11, 2020

I can recreate this from the repo provided - the PDF downloaded within the Cypress Test Runner is blank.

0reactions
Lukasz-Debieccommented, Nov 3, 2022

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.

Read more comments on GitHub >

github_iconTop 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 >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found