diff --git a/packages/driver/src/cy/commands/network.js b/packages/driver/src/cy/commands/network.js new file mode 100644 index 000000000000..8378e967ba2b --- /dev/null +++ b/packages/driver/src/cy/commands/network.js @@ -0,0 +1,20 @@ +module.exports = (Commands, Cypress) => { + Commands.addAll({ + network: (options = {}) => { + Cypress.automation('remote:debugger:protocol', { + command: 'Network.enable', + }) + + Cypress.automation('remote:debugger:protocol', { + command: 'Network.emulateNetworkConditions', + params: { + offline: options.offline, + 'latency': 0, + 'downloadThroughput': 0, + 'uploadThroughput': 0, + 'connectionType': 'none', + }, + }) + }, + }) +} diff --git a/packages/driver/src/cypress/commands.coffee b/packages/driver/src/cypress/commands.coffee index 3b014cb3c54d..65fef083561c 100644 --- a/packages/driver/src/cypress/commands.coffee +++ b/packages/driver/src/cypress/commands.coffee @@ -27,6 +27,7 @@ builtInCommands = [ require("../cy/commands/local_storage") require("../cy/commands/location") require("../cy/commands/misc") + require("../cy/commands/network") require("../cy/commands/popups") require("../cy/commands/navigation") require("../cy/commands/querying") diff --git a/packages/driver/test/cypress/fixtures/network.html b/packages/driver/test/cypress/fixtures/network.html new file mode 100644 index 000000000000..bf4c416cdbdc --- /dev/null +++ b/packages/driver/test/cypress/fixtures/network.html @@ -0,0 +1,16 @@ + + + + Network Fixture + + +

+ We are currently . +

+ + + diff --git a/packages/driver/test/cypress/integration/commands/network_spec.js b/packages/driver/test/cypress/integration/commands/network_spec.js new file mode 100644 index 000000000000..96831761b4fa --- /dev/null +++ b/packages/driver/test/cypress/integration/commands/network_spec.js @@ -0,0 +1,13 @@ +describe('src/cy/commands/network', () => { + before(() => { + cy.visit('/fixtures/network.html') + }) + + it('switches between offline and online', () => { + cy.contains('We are currently online.') + cy.network({ offline: true }) + cy.contains('We are currently offline.') + cy.network({ offline: false }) + cy.contains('We are currently online.') + }) +})