-
-
Notifications
You must be signed in to change notification settings - Fork 8.6k
JavaScript bindings for Chrome network emulation #3624
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
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));
* @return {!promise.Thenable<void>} A promise that will be resolved | ||
* when network emulation settings are set. | ||
*/ | ||
setNetworkConditions(latency, download_throughput, upload_throughput) { |
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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)
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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, |
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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.
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));
X
in the preceding checkbox, I verify that I have signed the Contributor License Agreement