Skip to content

Conversation

daviande
Copy link
Contributor

@daviande daviande commented Mar 8, 2017

Update WebDriverJS to support the Chrome debugging protocol
functionality for getting and setting network emulation settings. This
functionality was added to ChromeDriver in March of 2015
(https://chromium.googlesource.com/chromium/src.git/+/12a55ff7369b35adb29cd28f5e3dd4ef923e3e6c),
but hasn't been implemented in the JavaScript bindings.

Example script using this functionality:
var webdriver = require('selenium-webdriver');

var driver = new webdriver.Builder()
.forBrowser('chrome')
.build();

var latency = 5;
var throughput = 500 * 1024;
driver.setNetworkConditions(latency, throughput, throughput)
.then(() => driver.getNetworkConditions())
.then(network => {
console.log(network);
driver.get('https://fast.com/');
})
// once selenium disconnects from remote debugging protocol,
// emulation settings are discarded
.then(() => driver.sleep(60000));

Update WebDriverJS to support the Chrome debugging protocol
functionality for getting and setting network emulation settings.  This
functionality was added to ChromeDriver in March of 2015
(https://chromium.googlesource.com/chromium/src.git/+/12a55ff7369b35adb29cd28f5e3dd4ef923e3e6c),
but hasn't been implemented in the JavaScript bindings.

Example script using this functionality:
var webdriver = require('selenium-webdriver');

var driver = new webdriver.Builder()
.forBrowser('chrome')
.build();

var latency = 5;
var throughput = 500 * 1024;
driver.setNetworkConditions(latency, throughput, throughput)
.then(() => driver.getNetworkConditions())
.then(network => {
console.log(network);
driver.get('https://fast.com/');
})
// once selenium disconnects from remote debugging protocol,
// emulation settings are discarded
.then(() => driver.sleep(60000));
@lmtierney lmtierney added the C-nodejs JavaScript Bindings label Mar 9, 2017
* @return {!promise.Thenable<void>} A promise that will be resolved
* when network emulation settings are set.
*/
setNetworkConditions(latency, download_throughput, upload_throughput) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

since there are several optional parameters, can you change this to take a config object like addCookie?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sounds good, thanks for the feedback. I'll update the code.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

After some further testing, it looks like all of the fields are required. If you remove a field (latency for example), the chromedriver throws an error (see below). Do you think I should still switch to a config object?

Thanks,
Dave

WebDriverError: unknown error: invalid 'network_conditions' is missing 'latency'
(Session info: chrome=56.0.2924.87)
(Driver info: chromedriver=2.27.440174 (e97a722caafc2d3a8b807ee115bfb307f7d2cfd9),platform=Windows NT 10.0.14393 x86_64)
at Object.checkLegacyResponse (C:\Users\t-dan\Desktop\temp\node_modules\selenium-webdriver\lib\error.js:517:15)
at parseHttpResponse (C:\Users\t-dan\Desktop\temp\node_modules\selenium-webdriver\lib\http.js:516:11)
at doSend.then.response (C:\Users\t-dan\Desktop\temp\node_modules\selenium-webdriver\lib\http.js:432:13)
at process._tickCallback (internal/process/next_tick.js:109:7)
From: Task: Driver.setNetworkConditions(5, 512000, 512000)
at thenableWebDriverProxy.schedule (C:\Users\t-dan\Desktop\temp\node_modules\selenium-webdriver\lib\webdriver.js:816:17)
at thenableWebDriverProxy.setNetworkConditions (C:\Users\t-dan\Desktop\temp\node_modules\selenium-webdriver\chrome.js:767:17)
at Object. (C:\Users\t-dan\Desktop\temp\app.js:7:8)
at Module._compile (module.js:571:32)
at Object.Module._extensions..js (module.js:580:10)
at Module.load (module.js:488:32)
at tryModuleLoad (module.js:447:12)
at Function.Module._load (module.js:439:3)
at Module.runMain (module.js:605:10)
at run (bootstrap_node.js:425:7)

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, since the parameters are 3 numbers I think it will be difficult for users to remember the order.

Also, it looks like chromedriver accepts throughput when download_throughput and upload_throughput are the same.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ok, that sounds like the better approach. Didn't realize the 'throughput' alternative, thanks for letting me know.

*/
setNetworkConditions(latency, download_throughput, upload_throughput) {
const params = {
'offline': false,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Allow users to configure this too?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, sounds good.

Change setNetworkConditions to take a config object, so that users don't
need to remember the order of parameters.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
C-nodejs JavaScript Bindings
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants