cypress: Cypress.automation('remote:debugger:protocol') command started failing in Cypress 7.3.0
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:
CypressError: `cy.then()` timed out after waiting `4000ms`.
Your callback function returned a promise that never resolved.
The callback function was:
() => Cypress.automation('remote:debugger:protocol', {
command: 'Network.emulateNetworkConditions',
params: {
offline: true,
latency: -1,
downloadThroughput: -1,
uploadThroughput: -1
}
})
at https://www.cypress.io/__cypress/runner/cypress_runner.js:136167:24
From previous event:
at Context.thenFn (https://www.cypress.io/__cypress/runner/cypress_runner.js:136166:13)
at Context.then (https://www.cypress.io/__cypress/runner/cypress_runner.js:136597:21)
at Context.<anonymous> (https://www.cypress.io/__cypress/runner/cypress_runner.js:151455:21)
From Your Spec Code:
at Context.eval (https://www.cypress.io/__cypress/tests?p=cypress/integration/spec.js:133:9)
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 the baseUrl but it’s a little more complicated and I think this is better as a MWE.
describe('page', () => {
it('tries to go offline', () => {
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
}
})
);
cy.visit('/');
});
});
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.
About this issue
- Original URL
- State: open
- Created 3 years ago
- Reactions: 34
- Comments: 30
Thanks @asmirnov-style!
I adapted mine a bit too:
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
Cypress 12.6.0, still has the same issue! How do you guys test offline/online in Cypress??
Same here. Stuck with 6.9.1 because of this issue
According to my investigation, this issue may be injected by this commit in socketio/engine.io-client repo. It supports a
listen to the "offline" eventfeature in version 5.0.0 (2021-03-10).The problemic code is as follows:
The socket is closed after sending CDP command:
{ "command": "Network.emulateNetworkConditions", "parameters": { "offline": true } }. Then the command response is never received andCypress.automation('remote:debugger:protocol', { ... })is timeout.Kind a way for simulate OFFLINE (while Cypress team fixing 4 y.o bug)
We were also going offline and online in tests and are missing it… +1 here.
I am also suffering with this issue. I have confirmed Cypress 6.9.1 is still working properly. I have tested Cypress 6.9.1 against Chrome 96 and Electron 87 (working properly in both cases). Cypress 8.7.0 fails, Cypress 9.0.0 fails. So, or we go back to 6.9.1, or…
I am also experiencing this issue on our project when I upgraded to
v8.6.0. Is there a provided solution or an ETA for a fix? We cannot upgrade till this is fixed. 😭Another “work around”. With the fact that
Network.emulateNetworkConditionsandoffline: truedid set the Chrome network to offline, but Cypress cannot receive the command execution result. So we can tell Cypress to ignore this particular error, and continue to run our test specs.Modifying the real
onLineattribute, tested in Cypress 12.11.0:Same, still not working in 9.1.1
Do anyone know alternative solution to simulate browser offline mode?
Any update on this? My tests are also failing where this functionality is required
@szhong-becls your workaround did not work for me, unfortunately.
The same regression issue in
8.0.0+1 to this. I’m seeing the same problem.
Is this issue fixed in v13?
I tried this test and the results are as follows:
@AlanCodega mock all requests
Pls check my answer (the final answer in the issue discussion) at https://github.com/cypress-io/cypress/issues/235 (i couldn’t cite the issue), that workaround worked for me.
Hope everyone had a happy holiday season! As of v12.3.0 looks like the remote:debugger:protocol still fails to go back online. Can anyone else confirm?
This workaround worked for my with
cypress openbut hangs forcypress run