-
Notifications
You must be signed in to change notification settings - Fork 3.2k
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
Ability to prevent/stop loading 'Page load' #7083
Comments
@jennifer-shehane please have a look |
It doesn't appear that the I can't think of a way to stop loading of a specific XHR in Cypress currently. |
I found a way to issue In my example, we visit it('test', () => {
// set up the listener before the action that will cause reroute
cy.on('window:before:load', (win) => {
// just log the win.location.href for convenience
console.log('WINDOW BEFORE LOAD', win.location.href)
// if we're trying to load the page we want to stop, win.stop()
if (win.location.href === 'https://www.cypress.io/') {
win.stop()
}
})
cy.visit('https://docs.cypress.io')
cy.get('#logo').click()
}) If you want the listener to be global (across all tests), make sure to use HOWEVER, this does not prevent Cypress from listening to the page load. Cypress still waits for the page to load - so since you've prevented the page from loading, the test will now fail after the default 60 second timeout. This doesn't seem like a great solution to me. |
@ jennifer-shehane |
👍 , this would be a really useful feature |
@norvinino No, there is no solution for this which is why this issue is open. |
In our case, a button in our application fires an XHR to get a temporary URL for a download, then uses I think this use case is related to a number of open and closed issues, but wasn't sure where to include it. |
The workaround I'm using, I should mention, is the |
is there any ETA on this? Thank you! FYI: what is the best solution to stop page LOAD option and move to another step? |
I'm running into similar issues. Was playing around with the new download feature in 6.3.0 but that functionality seems to be maybe targeted at simply downloading a file from a link. I am dynamically generating a file (via ColdFusion) and serving it through the browser. So in 6.3.0 I submit my form, the file is downloaded to cypress/downloads (yay) but Cypress fails while waiting for a page load which never happens (boo) This is also similar to #8619 Searching it seems there have been quite a few issues opened for some way to stop or intercept a page load. |
Hi Team I am also facing similar issues |
@jimpriest Can you open a new issue detailing how this never loads the page when testing file download? We'd like to look into this. As mentioned, 6.3.0 does offer testing file downloads in case this was anyone elses blocker in this issue. Please update and remove any workaround code you had for testing downloads. If you encounter a new issue - please open a new issue. Thanks. |
@jennifer-shehane Do you have any workaround as i tried all the workarounds to handle window and page alerts ...I am using electron browser and can't use chrome & firefox due to security concerns in my organization .Please help |
Hi! This is huge blocker for my test suite. Did anyone looked into this problem? |
There is no workaround. You need to avoid the action that is causing the redirect at the moment until this feature is added to Cypress. |
@jennifer-shehane I'm facing a similar issue when testing a login action. Can you take a look here please? #15849 Thanks. |
Hi, I am also facing the same issue when downloading files. Please suggest any work around for this. |
I found a work around here - #14857 cy.window().document().then(function (doc) {
doc.addEventListener('click', () => {
setTimeout(function () { doc.location.reload() }, 5000)
})
cy.get('[ng-click="vm.export()"]').click()
}) Thanks to Sarja 👍 |
I am facing this issue with my Google Analytics events coverage. On my tests I stubbed Google Analytics events on every action, these events are fired before the new page loads, so I don't need to wait for this load in order to assert, yet Cypress forced the test to wait making the time execution last longer than it could. Is there any workaround that doesn't involved block hosting? Thank you. |
In my case I was able to manually trigger the Page Load event: |
Complete blocker for me. We need a clean way to tell Cypress not to wait for a non-existent page. |
Same here. We can't test any of our downloads as we use an iframe pointing towards an AWS URL. The page load never happens and we can't move forward with testing one of our most critical functions. |
I've fixed a similar issue. My page redirects with the parameter ?target=http://xxxx.com/xxx, Just replacing the 'http:' with 'https:' can resolve this issue. |
|
hi how did you solve the problem |
cy.intercept('GET', downloadUrl).as('downloadFile');
cy.doIfDataCySelectorExist(selector, () => {
cy.window().then(function (win) {
win.addEventListener('click', () => {
setTimeout(function () {
win.location.reload()
}, 5000)
})
cy.getByDataCySelector(selector).click();
cy.wait('@downloadFile').its('response.statusCode').should('eq', 200);
})
}) |
Nearly 3 years now. Should we conclude there's no interest in fixing this? |
Tis a real kicker this. Download file served from a tokenised url here. File downloads absolutely fine. Cypress doesn't know what to do. Triggering the download by setting the window.location |
I got passed it by just catching the error via pasting this before the submit:
|
LOL! That is one way to do it. This makes tests unfathomably slow as they wait for Cypress to retry for 30 seconds for each download assertion. |
That probably depends on timeout settings and what you are waiting for (might not be a download, like it wasn't for me). But yeah it's hilarious. One thing you might also try is hitting the endpoint through jQuery instead of cypress. But you might find that equally hilarious for some reason specific to your own random use case. idk. |
Are there any updates for this issue ? |
I'm so frustrating with this issue |
I am facing the same issue here! |
any solution for this? |
They do not care I guess. Dealbreaker for me. |
Is there still no solution for this page load event issue? This is a big problem that affects the execution of our tests. Please take care of it @cypress-app-bot |
Well I try to stop to load the xhr and continue my test without page load time out error
but not working and not even stop the xhr loading. Please guide if im using in correct way or it is actual bug.
Try with black list as well in cypress.json file but did not work
this is xhr I want to stop loading
"https://www.deepl.com/PHP/backend/docTrans.php?request_type=jsonrpc&il=en"
Reason why I need this because these is 1 xhr that will load after 5 seconds and this is never ending process in my application under test.
cy version 4.4.0
OS windows 10
The text was updated successfully, but these errors were encountered: