New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Cypress tests hang waiting on user to interact with download dialog #433

Open
josephong opened this Issue Feb 16, 2017 · 6 comments

Comments

6 participants
@josephong

josephong commented Feb 16, 2017

Sorry if this is addressed in the documentation – I couldn't find anything on it. When I run a spec, programmatically clicking on a link that downloads a file triggers a download dialog. However, in order to make the test progress, I have to manually dismiss the dialog.

Is there an option that will close download dialogs automatically?

@brian-mann

This comment has been minimized.

Show comment
Hide comment
@brian-mann

brian-mann Feb 16, 2017

Member

Nope this requires native events, which have not been implemented in Cypress.

There is an issue open #311 but I haven't written the explanation for it. It's orthogonal to #310 though which can give you some perspective.

Currently as a workaround just:

  • don't click the link
  • bind to the event which triggers the dialog (in Cypress) and call e.preventDefault() on it
Member

brian-mann commented Feb 16, 2017

Nope this requires native events, which have not been implemented in Cypress.

There is an issue open #311 but I haven't written the explanation for it. It's orthogonal to #310 though which can give you some perspective.

Currently as a workaround just:

  • don't click the link
  • bind to the event which triggers the dialog (in Cypress) and call e.preventDefault() on it
@bahmutov

This comment has been minimized.

Show comment
Hide comment
@bahmutov

bahmutov Feb 16, 2017

Collaborator

if the test e.preventDefault() on the button, for example, it would just disable the button's action we need and trying to test, right?

Collaborator

bahmutov commented Feb 16, 2017

if the test e.preventDefault() on the button, for example, it would just disable the button's action we need and trying to test, right?

@brian-mann

This comment has been minimized.

Show comment
Hide comment
@brian-mann

brian-mann Feb 16, 2017

Member

Okay what you should do is isolate the method that ends up making the HTTP request which sends the disposition headers which caused the file prompt to appear.

Then just use cy.stub to stub out that method and make sure its invoked with the right arguments. Then the thing creating the side effect is isolated and well tested without it doing anything.

You'll need this globally exposed somehow, either attached to some global App object, or perhaps just in test mode expose the function itself. Few different ways to solve this.

Member

brian-mann commented Feb 16, 2017

Okay what you should do is isolate the method that ends up making the HTTP request which sends the disposition headers which caused the file prompt to appear.

Then just use cy.stub to stub out that method and make sure its invoked with the right arguments. Then the thing creating the side effect is isolated and well tested without it doing anything.

You'll need this globally exposed somehow, either attached to some global App object, or perhaps just in test mode expose the function itself. Few different ways to solve this.

@kutlaykural

This comment has been minimized.

Show comment
Hide comment
@kutlaykural

kutlaykural Jun 21, 2018

Hi @brian-mann
I am triying to stub a request which has disposition headers.
Is there any difference between "XHR and Fetch" request and Doc for Cypress

screen shot 2018-06-21 at 16 01 30

kutlaykural commented Jun 21, 2018

Hi @brian-mann
I am triying to stub a request which has disposition headers.
Is there any difference between "XHR and Fetch" request and Doc for Cypress

screen shot 2018-06-21 at 16 01 30

@brian-mann

This comment has been minimized.

Show comment
Hide comment
@brian-mann

brian-mann Jun 21, 2018

Member

Just use cy.request to programmatically make the request that would send the right headers to download the file and assert on the headers. That's all you need to do to know that the browser would have downloaded the file.

Alternatively you could set some flags in chrome to force it to accept downloads to a default location and then just assert that the file is present on the file system.

Member

brian-mann commented Jun 21, 2018

Just use cy.request to programmatically make the request that would send the right headers to download the file and assert on the headers. That's all you need to do to know that the browser would have downloaded the file.

Alternatively you could set some flags in chrome to force it to accept downloads to a default location and then just assert that the file is present on the file system.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment