JavaScript bindings for Chrome network emulation
@@ -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'
};
@@ -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');
}
@@ -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) + ')');
+ }
}
