Skip to content
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

Clicking on anchor elements expects a page load event #15220

Closed
mohsenny opened this issue Feb 25, 2021 · 5 comments
Closed

Clicking on anchor elements expects a page load event #15220

mohsenny opened this issue Feb 25, 2021 · 5 comments
Labels
type: duplicate This issue or pull request already exists

Comments

@mohsenny
Copy link

mohsenny commented Feb 25, 2021

Current behavior

In our web application, we have buttons in form of anchor elements, with links inside of them of course. These links points to S3 bucket files and clicking on those button triggers a download.

However, from Cypress' perspective, clicking on any anchor element that contains href inside of them, would expect a new page to load. For example here:

Screenshot_2021-02-25_at_15_01_43

at line #11 we're clicking on the button and the file starts getting downloaded, but immediately Cypress starts to wait for a new page to load which in this case there would be no new page to open, and therefore the tests fail

Desired behavior

Either Cypress should detect if redirection to a new page is happening when clicking on an anchor (maybe looking for the download attribute not to exist) to start waiting for a new page to load, or, another approach could be passing an option to click element that stops such event from being triggered:

cy.get(selector).click({newPageTrigger: false})

Test code to reproduce

This is the HTML element for the Download button:

<a data-wide="true" download="Event in the past.xls" theme="[object Object]" class="ant-btn sc-pjTIO fJuPmM ant-btn-primary ant-btn-lg" href="https://s3.eu-central-1.amazonaws.com/blahblah">
   <span role="img" aria-label="download" class="anticon anticon-download">
      <svg viewBox="64 64 896 896" focusable="false" class="" data-icon="download" width="1em" height="1em" fill="currentColor" aria-hidden="true">
         <path d="M505.7 661a8 8 0 0012.6 0l112-141.7c4.1-5.2.4-12.9-6.3-12.9h-74.1V168c0-4.4-3.6-8-8-8h-60c-4.4 0-8 3.6-8 8v338.3H400c-6.7 0-10.4 7.7-6.3 12.9l112 141.8zM878 626h-60c-4.4 0-8 3.6-8 8v154H214V634c0-4.4-3.6-8-8-8h-60c-4.4 0-8 3.6-8 8v198c0 17.7 14.3 32 32 32h684c17.7 0 32-14.3 32-32V634c0-4.4-3.6-8-8-8z"></path>
      </svg>
   </span>
   <span>Download</span>
</a>

Versions

Cypress version: 6.5.0
Node version: 15.3.0

@mohsenny mohsenny changed the title Clicking on anchor elements triggers a page load events Clicking on anchor elements exepcts a page load events Feb 25, 2021
@mohsenny mohsenny changed the title Clicking on anchor elements exepcts a page load events Clicking on anchor elements expects a page load events Feb 25, 2021
@jennifer-shehane
Copy link
Member

@mohsenny We have several examples of anchor links with download attributes being tested in our recipes: https://github.com/cypress-io/cypress-example-recipes/blob/master/examples/testing-dom__download/cypress/integration/remote-download-spec.js None of them show this behavior.

There must be something more unique about the application you're testing. Is there an onclick handler? Maybe it's setting the location?

Ideally a reproducible example - like a repo - that shows the issue would be best so we can investigate.

@jennifer-shehane jennifer-shehane added the stage: needs information Not enough info to reproduce the issue label Feb 26, 2021
@mohsenny
Copy link
Author

Hey @jennifer-shehane thank you for the links. You're probably right. Let me communicate this to our dev team and I'll get back to this ticket with more information 🙏

@jennifer-shehane
Copy link
Member

I have an example of this error actually already here: #14857

Duplicate of #14857

@jennifer-shehane jennifer-shehane added type: duplicate This issue or pull request already exists and removed stage: needs information Not enough info to reproduce the issue labels Feb 26, 2021
@jennifer-shehane
Copy link
Member

Actually, I'm not sure if it is a duplicate of #14857 exactly without a repro. So, comment here if it's different - or comment in the other issue if it is.

@mohsenny
Copy link
Author

mohsenny commented Feb 26, 2021

@jennifer-shehane Yep, it's an exact duplicate.
I'll be following the discussion in #14857 for any further updates.

Thank you so far!

@mohsenny mohsenny changed the title Clicking on anchor elements expects a page load events Clicking on anchor elements expects a page load event Feb 26, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
type: duplicate This issue or pull request already exists
Projects
None yet
Development

No branches or pull requests

2 participants