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.

Support ability to visit non `text/html` content-type pages (aka - visit downloaded file page)

See original GitHub issue

Current behavior:

I am trying to test a download action from a .ts file using the attribute window.location.href. It doesn’t matter what value I assign for the URL string, the test instruction fails claiming a timeout waiting for the request when the file actually has been downloaded in few seconds. For some unknown reason Cypress never can reach the URL.

Note: I am using a Genesis UI theme as my development code base.

These are the paths that I have tried aiming to get an Ok result from the Cypress test:

  1. window.location.href = '/api/download/file_id';
  2. window.location.href = '/#/api/download/file_id';
  3. window.location.href = 'http://localhost:5000/api/download/file_id';
  4. window.location.href = 'http://localhost:5000/#/api/download/file_id';

All of them fail. But if I try the first option as a normal user from the browser directly, the download works perfectly.

Note: During the Cypress test, I can see how the file is actually downloaded. The download action occurs.

Desired behavior:

All that I am expecting is to be able to test my download action from the Cypress test.

If I trigger the download button using something like:

cy.get('[data-cy=download-file]').click();

I expect to get a positive response from the test if the file was actually downloaded.

How to reproduce:

Note: It would be great if you can try this steps using a Genesis UI theme as the base application.

  1. Create a form template with a button pointing to the .ts method on the (click) parameter: (click)="downloadFile()" Note: Include a data-cy parameter as part of the button in the form: data-cy="download-file"
  2. Inside the .ts method use the instruction, ensuring to use a valid path: window.location.href = '/path/to/file/for/download';
  3. Write a Cypress test when you try to trigger the download button from the form. Something like: cy.get('[data-cy=download-file]').click();
  4. You should get a timeout message similar to the one included as attached image.

Test code:

cy.get('[data-cy=download-file]').click(); 

Additional Info (images, stack traces, etc)

timeout

  • Operating System: Mac OSX 10.13.2
  • Cypress Version: 2.1.0
  • Browser Version: Google Chrome 65.0.3325.181

Issue Analytics

  • State:open
  • Created 5 years ago
  • Reactions:31
  • Comments:22 (2 by maintainers)

github_iconTop GitHub Comments

6reactions
sanagaraj-pivotalcommented, Sep 23, 2020

This is resolved when you disabling chrome web security. This can be done by adding following line into cypress.json

  "chromeWebSecurity": false
6reactions
ioana-glncommented, Jul 8, 2019

Any news on this?

Read more comments on GitHub >

github_iconTop Results From Across the Web

Unable to download file with content type text/html
Here the confusion comes, how come I'm able to download the file from the browser when the content-type is not application/pdf? Anything wrong ......
Read more >
Visit Non-HTML Page - Gleb Bahmutov
Imagine you have a REST API endpoint that returns a JSON object. Can you see that JSON response in a Cypress test?
Read more >
Internet Explorer (IE) mode troubleshooting and FAQ
Troubleshooting guide and FAQ for Microsoft Edge Internet Explorer mode.
Read more >
Issues · cypress-io/cypress · GitHub
Support ability to visit non text/html content-type pages (aka - visit downloaded file page) difficulty: 3️⃣ existing workaround stage: backlog ...
Read more >
JavaServer Pages (JSP) - A Tutorial
In fact, we shall see later that a JSP page is internally translated into a Java ... html> <html> <head> <meta http-equiv="Content-Type" content="text/html; ......
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