Skip to content

Commit 9f22905

Browse files
authored
add deleteNetworkConditions for chromium (#10323)
This implements the functionality to delete previously set network conditions in Chromium. Fixes #10322
1 parent 9c748fa commit 9f22905

2 files changed

Lines changed: 33 additions & 0 deletions

File tree

javascript/node/selenium-webdriver/chromium.js

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -92,6 +92,7 @@ const Command = {
9292
LAUNCH_APP: 'launchApp',
9393
GET_NETWORK_CONDITIONS: 'getNetworkConditions',
9494
SET_NETWORK_CONDITIONS: 'setNetworkConditions',
95+
DELETE_NETWORK_CONDITIONS: 'deleteNetworkConditions',
9596
SEND_DEVTOOLS_COMMAND: 'sendDevToolsCommand',
9697
SEND_AND_GET_DEVTOOLS_COMMAND: 'sendAndGetDevToolsCommand',
9798
SET_PERMISSION: 'setPermission',
@@ -137,6 +138,11 @@ function configureExecutor(executor, vendorPrefix) {
137138
'POST',
138139
'/session/:sessionId/chromium/network_conditions'
139140
)
141+
executor.defineCommand(
142+
Command.DELETE_NETWORK_CONDITIONS,
143+
'DELETE',
144+
'/session/:sessionId/chromium/network_conditions'
145+
)
140146
executor.defineCommand(
141147
Command.SEND_DEVTOOLS_COMMAND,
142148
'POST',
@@ -706,6 +712,15 @@ class Driver extends webdriver.WebDriver {
706712
return this.execute(new command.Command(Command.GET_NETWORK_CONDITIONS))
707713
}
708714

715+
/**
716+
* Schedules a command to delete Chromium network emulation settings.
717+
* @return {!Promise} A promise that will be resolved when network
718+
* emulation settings have been deleted.
719+
*/
720+
deleteNetworkConditions() {
721+
return this.execute(new command.Command(Command.DELETE_NETWORK_CONDITIONS))
722+
}
723+
709724
/**
710725
* Schedules a command to set Chromium network emulation settings.
711726
*

javascript/node/selenium-webdriver/test/chrome/options_test.js

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -156,6 +156,24 @@ test.suite(
156156
assert.strictEqual(userAgent, 'foo;bar')
157157
})
158158

159+
it('can start chromium with network conditions set', async function () {
160+
driver = await env.builder().build()
161+
await driver.get(test.Pages.ajaxyPage)
162+
await driver.setNetworkConditions({
163+
offline: true,
164+
latency: 0,
165+
download_throughput: 0,
166+
upload_throughput: 0,
167+
})
168+
assert.deepStrictEqual(await driver.getNetworkConditions(), {
169+
download_throughput: 0,
170+
latency: 0,
171+
offline: true,
172+
upload_throughput: 0,
173+
})
174+
await driver.deleteNetworkConditions()
175+
})
176+
159177
it('can install an extension from path', async function () {
160178
let options = new chrome.Options().addExtensions(WEBEXTENSION_CRX)
161179

0 commit comments

Comments
 (0)