Cypress: Pdf is offered for download in electron

Created on 26 Nov 2018  路  18Comments  路  Source: cypress-io/cypress

Current behavior:

A Pdf url is offered for download in Electron.

Desired behavior:

The Pdf should open in the pdf viewer in Electron
This works fine in Chrome.
The content-disposition header is set to inline

I think, this was working fine before 3.1.2


cypress 3.1.2
ubuntu 18.4
chrome 70
electron 59

electron ready for work bug

All 18 comments

Could you provide a way to reproduce this?

We just hit this one and now I'm really confused. What should happen when there is an embedded pdf on a page and Cypress test is run on the page? Should it be displayed, should there be a placeholder (I've seen this on some runs, that there is an iframe placeholder on the page) or should this happen?

We seemingly changed nothing on our system but suddenly our test runs in CI started to hang and I found out it was because of the save dialog popping up when navigating to a page with an embedded pdf. We've had the tests run ok for a few months now and now I'm in doubt that what happened now and how they have passed before.

Tried with Cypress versions of 3.1.0 and 3.1.4.

Are you running the tests on CI with the --browser flag?

We'll need an example of the behavior, including test code and app code, to really look at the issue though.

https://github.com/Juholei/cypress-pdf-problem here's an isolated example app with the simplest test.

The app is a Reagent (React) ClojureScript app. Contains pdf embedded with an iframe. The test navigates to the page and looks for "Hello world!", but it gets stuck during the test run as the pdf prompts a save dialog.

Works fine with Chrome, the problem occurs when running in Electron. There's also a couple screenshots of the prompt occurring, one when running headless and one when running with the GUI


The web page itself can also be found at https://juholei.github.io/cypress-pdf-problem/.

This example does not contain setting content-disposition header to inline which is mentioned on the original issue. Our real project does have that though set. Tests are ran in the real project in CI with cypress run command and using Electron.

As per my original comment, I would like to know what should happen when the page under testing contains an embedded pdf and the tests are ran using Electron?

@Juholei Thanks so much for providing a reproducible example! 馃挴

I've simplified this repo so that ClojureScript is no longer required. You can find my fork https://github.com/jennifer-shehane/cypress-pdf-problem

I have the same issue, is they any workaround for this?

@olaf89 the workaround is to run the tests in Chrome. This is less than ideal though, as then it is not possible to get video of the test run.

Still hoping this will get fixed soon.

Any updates on this issue?

I wonder if it's because Electron doesn't package Chromium's built-in PDF viewer: https://github.com/electron/electron/issues/12337

Maybe a fix could be to add this plugin to the BrowserWindow launched for the AUT: https://github.com/gerhardberger/electron-pdf-window

I've discovered this problem as well, but not until I was trying to run our tests in CI using the headless option. Locally I was using Chrome so it took a while to figure out what was happening on the CI server.

Running into this one as well. PDFs shown inline are a big part of our app. We can run tests with Chrome in CI, but we lose the ability to generate artifacts without Electron.

I have the same issue, waiting for news...
I must to run with Electron to create video.
and not found workaround for this except run in chrome.

A simple example inline of way to reproduce. Requires testing.pdf file in project root.

index.html

<html>
<body>
  <iframe src="testing.pdf"></iframe>
</body>
</html>

spec.js

it('Visiting iframe with pdf src', function () {
  cy.visit('index.html')
})

@flotwig Electron removed support for the Chromium PDF viewer in 3.0.0. If this were due to the Electron not packaging the Chromium viewer https://github.com/electron/electron/issues/12337, then this test case should work in Cypress 3.4.1 and fail in 3.5.0 (since that is when we upgraded from 2.0.18 to 5.0.10, but that is not the case. Right?

Although this seems to describe this issue completely, they even mention iframes and nested iframes in Electron not working for PDF viewer: https://github.com/electron/electron/projects/7

I tested this all the way back to Cypress 2.0.0 and it breaks in that version too, so the original assertion that this may have been working in 3.1.2 by @rbokel doesn't appear to be the case.

These issue sound completely relevant, but they are all tagged as duplicates of https://github.com/electron/electron/issues/12337:

Workaround

I was unable to find a current workaround to have this work when running in Electron.

The only way around this is to run your tests in Chrome using the --browser chrome flag, which will launch Cypress on a Chrome browser installed on the machine.

This will be partially addressed in the Electron 9 upgrade https://github.com/cypress-io/cypress/pull/7791

The browser will no longer prompt to 'download', which will prevent some locking up if running via cypress run, however the pdf still does not appear to load in the iframe correctly.

Running this example after the PR shows the results below: https://github.com/jennifer-shehane/cypress-pdf-problem

Screen Shot 2020-06-29 at 1 05 12 PM

@jennifer-shehane Not able to understand what is the solution provided.... do I need to create index.html in cypress test suite...

@86SUSHIL There is no workaround. You can run your test in Chrome using the --browser flag to avoid running Cypress in electron.

@jennifer-shehane I have some restriction in using Chrome

Was this page helpful?
0 / 5 - 0 ratings