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.automation('remote:debugger:protocol') command started failing in Cypress 7.3.0 #17723
Comments
+1 to this. I'm seeing the same problem. |
The same regression issue in |
@jennifer-shehane did this get lost? It's been two weeks with no response 😦 |
@jennifer-shehane Gleb pointed me to this Cypress recipe on the Cypress Gitter: https://github.com/cypress-io/cypress-example-recipes/blob/master/examples/server-communication__offline/cypress/integration/offline-spec.js Which is almost identical to my code except for the use of braces and explicit return statements for the arrow function bodies. Yet, I was able to use the MWE above in a cypress-test-tiny fork and trace the failure back to 7.3.0 as described. I realize this is a bit of an obscure feature, but you have blogs and recipes that reference it, and multiple people, both here and in the comments on the blog post, are struggling getting code referenced in those blogs/recipes to work in newer versions of Cypress. Could you at least confirm whether you can reproduce the error I'm seeing? |
According to my investigation, this issue may be injected by this commit in socketio/engine.io-client repo. The problemic code is as follows: + if (this.hostname !== "localhost") {
+ this.offlineEventListener = () => {
+ this.onClose("transport close");
+ };
+ addEventListener("offline", this.offlineEventListener, false);
+ } The socket is closed after sending CDP command: |
any idea or workaround? Can i get an older version of cypress to make it work? It only fails when is not localhost, in fact i can go offline but i cant recover from this status to the online status |
A quick workaround would be to use a version before cypress 7.0.0. As I stated here cypress-io/cypress-example-recipes#721 (comment) I got it successfully running in version 6.9.1. |
Another "work around". With the fact that cy.on('fail', e => {
if (
e.name === 'CypressError'
&& e.message.includes('timed out')
&& e.message.includes('remote:debugger:protocol')
&& e.message.includes('Network.emulateNetworkConditions')
&& e.message.includes('offline: true')
) {
// do not fail the test
return false;
}
});
cy.log('**go offline**')
.then(() =>
Cypress.automation('remote:debugger:protocol', { command: 'Network.enable' })
)
.then(() =>
Cypress.automation('remote:debugger:protocol', {
command: 'Network.emulateNetworkConditions',
params: {
offline: true,
latency: -1,
downloadThroughput: -1,
uploadThroughput: -1
}
})
); |
@szhong-becls your workaround did not work for me, unfortunately. |
Any update on this? My tests are also failing where this functionality is required |
I am also experiencing this issue on our project when I upgraded to |
I am also suffering with this issue. |
Same for me :( |
Same! 👀 |
Same, still not working in 9.1.1 Do anyone know alternative solution to simulate browser offline mode? |
Same here. Stuck with 6.9.1 because of this issue |
This workaround worked for my with |
same problem on "cypress": "^9.6.1" |
Can we please get this working? None of the workarounds above works anymore. I hate to be stuck with version 6.9 because of this |
We were also going offline and online in tests and are missing it... +1 here. |
Year 2023 |
Hope everyone had a happy holiday season! |
Yes, unfortunately this issue stills. |
Cypress 12.6.0, still has the same issue! |
Pls check my answer (the final answer in the issue discussion) at #235 (i couldn't cite the issue), that workaround worked for me. |
@AlanCodega mock all requests |
Kind a way for simulate OFFLINE (while Cypress team fixing 4 y.o bug)
|
Thanks @asmirnov-style! I adapted mine a bit too: const goOffline = () => {
cy.log('**go offline**')
// stub every request with a StaticResponse to simulate network error
.then(() => cy.intercept('*', { forceNetworkError: true }))
.then(() =>
cy.window().then((win) => win.dispatchEvent(new Event('offline')))
)
}
const goOnline = () => {
cy.log('**go online**')
// go back to normal network behavior
.then(() => cy.intercept('*'))
.then(() =>
cy.window().then((win) => win.dispatchEvent(new Event('online')))
)
} |
Modifying the real // go offline
cy.window().then((win) => {
cy.stub(win.navigator, 'onLine').value(false);
cy.wrap(win).trigger('offline');
});
// go online
cy.window().then((win) => {
cy.stub(win.navigator, 'onLine').value(true);
cy.wrap(win).trigger('online');
}); |
Is this issue fixed in v13? I tried this test and the results are as follows:
|
Current behavior
Starting in 7.3.0, the test code below (mostly copied from https://www.cypress.io/blog/2020/11/12/testing-application-in-offline-network-mode/) throws this error:
Desired behavior
The test should run without error.
Test code to reproduce
Set the
baseUrl
configuration key (e.g."https://www.cypress.io"
) and run the following spec. I can reproduce without setting thebaseUrl
but it's a little more complicated and I think this is better as a MWE.Cypress Version
7.3.0
Other
I encountered this when attempting to update to the latest version of Cypress, but traced it back to 7.3.0. Version 7.2.0 runs without error.
It looks like at least a couple other people have encountered this based on the comments on that blog post. I found that modifying the callback in the second
then
to not return anything did allow my tests to get further, only to hang indefinitely at random places in my test file so, as I suspected, that isn't a real solution.The text was updated successfully, but these errors were encountered: