Skip to content

Commit

Permalink
JavaScript bindings for Chrome network emulation (#3624)
Browse files Browse the repository at this point in the history
  • Loading branch information
daviande authored and jleyba committed Mar 14, 2017
1 parent 3c200d7 commit d7bdd7c
Showing 1 changed file with 48 additions and 1 deletion.
49 changes: 48 additions & 1 deletion javascript/node/selenium-webdriver/chrome.js
Expand Up @@ -143,7 +143,9 @@ const CHROMEDRIVER_EXE =
* @enum {string}
*/
const Command = {
LAUNCH_APP: 'launchApp'
LAUNCH_APP: 'launchApp',
GET_NETWORK_CONDITIONS: 'getNetworkConditions',
SET_NETWORK_CONDITIONS: 'setNetworkConditions'
};


Expand All @@ -169,6 +171,14 @@ function configureExecutor(executor) {
Command.LAUNCH_APP,
'POST',
'/session/:sessionId/chromium/launch_app');
executor.defineCommand(
Command.GET_NETWORK_CONDITIONS,
'GET',
'/session/:sessionId/chromium/network_conditions');
executor.defineCommand(
Command.SET_NETWORK_CONDITIONS,
'POST',
'/session/:sessionId/chromium/network_conditions');
}


Expand Down Expand Up @@ -727,6 +737,43 @@ class Driver extends webdriver.WebDriver {
new command.Command(Command.LAUNCH_APP).setParameter('id', id),
'Driver.launchApp()');
}

/**
* Schedules a command to get Chrome network emulation settings.
* @return {!promise.Thenable<T>} A promise that will be resolved
* when network emulation settings are retrievied.
*/
getNetworkConditions() {
return this.schedule(
new command.Command(Command.GET_NETWORK_CONDITIONS),
'Driver.getNetworkConditions()');
}

/**
* Schedules a command to set Chrome network emulation settings.
*
* __Sample Usage:__
*
* driver.setNetworkConditions({
* offline: false,
* latency: 5, // Additional latency (ms).
* download_throughput: 500 * 1024, // Maximal aggregated download throughput.
* upload_throughput: 500 * 1024 // Maximal aggregated upload throughput.
* });
*
* @param {Object} spec Defines the network conditions to set
* @return {!promise.Thenable<void>} A promise that will be resolved
* when network emulation settings are set.
*/
setNetworkConditions(spec) {
if (!spec || typeof spec !== 'object') {
throw TypeError('setNetworkConditions called with non-network-conditions parameter');
}

return this.schedule(
new command.Command(Command.SET_NETWORK_CONDITIONS).setParameter('network_conditions', spec),
'Driver.setNetworkConditions(' + JSON.stringify(spec) + ')');
}
}


Expand Down

0 comments on commit d7bdd7c

Please sign in to comment.