I have some JavaScript in my app that detects when the network connection goes away and temporarily caches data in local storage, to be synced with the server when the connection is re-established.
I've been trying to find a way to test this end-to-end using Capybara, but I can't seem to find any way of either temporarily disabling the app server or switching the headless browser into offline mode. FWIW I'm using Poltergeist as the driver.
Does anyone have an idea how this could be tested? (I can test the JavaScript app using sinon to fake the server going away, but I'd like to be able to test it end-to-end with a headless browser if possible).
If you stumbled on this question looking for a way to test offline / progressive web apps with Capybara and Chrome Headless, here's how:
params = {
cmd: 'Network.emulateNetworkConditions',
params: {
offline: true,
latency: 0,
downloadThroughput: 0,
uploadThroughput: 0
}
}
page.driver.browser.send(:bridge).send_command(params)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With