Open bahmutov opened 8 years ago
I tried, but it still does not work on Chrome when I am trying to get back online, it only works on Electron.
I also tried the solution posted in here, but without success: https://www.cypress.io/blog/2020/11/12/testing-application-in-offline-network-mode/
Copy exactly same from above and try again
your code is missing return, premise returning nothing, try this
cy.log('go offline'); return 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, }, }) return cy.wait(1000); });
your code is missing return, premise returning nothing, try this
cy.log('go offline'); return 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, }, }) return cy.wait(1000); });
I managed to get it offline, but the problem is to put it back online, in which it is working well only on Electron.
Downgraded Cypress to 7.2.0. Seems to work.
UPD Nope. Also rather torturous experience. I'll better try using forceNetworkError.
Same problem: 7.9.0 version.
I observe this problem in 10+ version in Electron runner as well.
This one works for me
const goOffline = () => { cy.log('go offline'); return 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, }, }) return true }); };
I'm facing this problem too. I'm using this code below:
network(params) {
cy.log(`**Offline: ${params.offline}**`)
.then(() => {
Cypress.automation('remote:debugger:protocol', {
command: 'Network.enable',
});
})
.then(() => {
Cypress.automation('remote:debugger:protocol', {
command: 'Network.emulateNetworkConditions',
params: {
offline: params.offline,
latency: 0,
downloadThroughput: 0,
uploadThroughput: 0,
connectionType: 'none',
},
});
});
},
I've work with cypress 9.5.1. After going offline, can't get back online. Anyone has a solution for this?
Cypress v10.3.1 and still the same issue with going back Online. Looks like it's turn Network for a second and then break connection. Any ideas?
Hello everyone
I have been stuck into this issue for at least 2 weeks ago and i got a "solution" to try simulate offline mode. The code is in the image below
Create this function on custom commands file of your project and call it using "cy.network({online: false})" This work for me. I hope that this workaround work for you too.
I'm using cypress 9.5.1
Guys it's 2023 👀
laerteneto @laerteneto did you get any solution?
Modifying the real onLine
attribute, tested in Cypress 12.11.0:
// 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');
});
@laerteneto did you get any solution? Im stuck with go online too
Modifying the real
onLine
attribute, tested in Cypress 12.11.0:// 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'); });
Confirming the workability of this solution.
Cypress v10, Chrome 117 (only in headless).
Don't forget to put go online into before, beforeEach and afterEach
Guys it's 2024 👀
I'm using this for Cypress 13.11.0 and Chrome v126: https://www.cypress.io/blog/2020/11/12/testing-application-in-offline-network-mode Works for me.
8 years later....
I did exactly what it's in this article, but the problem is that all tests after goOnline
become absolutely slowly and I can't figure why.
It seems like Network.disable
doesn't work.
Description Offline support is becoming important to web applications. It would be nice to switch the browser to the offline mode from Cypress either by test or for all tests and run it. If might be difficult and might require Cypress to handle ServiceWorkers very well.
Additional Info