Skip to content

Instantly share code, notes, and snippets.

@remarkablemark
Created June 27, 2016 20:41
Show Gist options
  • Select an option

  • Save remarkablemark/fd967e6403f763b588f21c775f1bf4e9 to your computer and use it in GitHub Desktop.

Select an option

Save remarkablemark/fd967e6403f763b588f21c775f1bf4e9 to your computer and use it in GitHub Desktop.
Setting a cookie with WebDriverJS with parallel flows.
'use strict';
/**
* Module dependencies.
*/
const webdriver = require('selenium-webdriver');
/**
* Run clients in parallel and set cookie.
* https://github.com/SeleniumHQ/selenium/blob/master/javascript/node/selenium-webdriver/example/parallel_flows.js
*/
for (let index = 0; index < 5; index++) {
const flow = new webdriver.promise.ControlFlow();
flow.on('uncaughtException', (error) => {
console.error(index, 'uncaughtException in flow', error);
});
const builder = new webdriver.Builder();
const driver = builder.forBrowser('phantomjs')
.setControlFlow(flow)
.build();
driver.get(`https://httpbin.org/cookies/set?index=${index}`);
driver.getTitle().then((title) => {
console.log(index, title);
});
driver.manage().getCookies().then((cookies) => {
console.log(index, cookies)
});
driver.quit();
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment