Make parallel requests to a Selenium Webdriver grid Make parallel requests to a Selenium Webdriver grid selenium selenium

Make parallel requests to a Selenium Webdriver grid


The answer may be multiple control flows:

WebDriverJS supports defining "parallel" flows using webdriver.promise.createFlow(). This function accepts a callback which will be passed the newly created flow. Tasks scheduled within this flow will be synchronized with each other, but will remain independent of any other control flows. Each call to createFlow() returns a promise that will resolve when the flow has completed.

The example at the end of the chapter (which I'll quite verbatim) shows multiple Google search terms being tested concurrently:

var terms = [   'javascript',   'selenium',   'webdriver'];var flows = terms.map(function(term) { return webdriver.promise.createFlow(function() {   var driver = new webdriver.Builder().build();   driver.get('http://www.google.com');   driver.findElement(webdriver.By.name('q')).sendKeys(term);   driver.findElement(webdriver.By.name('btnG')).click();   driver.getTitle().then(function(title) {     if (title !== (term + ' - Google Search')) {       throw Error('Unexpected title: ' + title);     }   }); });});webdriver.promise.fullyResolved(flows).then(function() { console.log('All tests passed!');});

It should be easy enough to add your custom driver build and lookups into that example. Perhaps the following:

var flows = [0,1,2,3].map(function(index) { return webdriver.promise.createFlow(function() {   var driver = new webdriver.Builder().forBrowser('firefox').usingServer('http://someurl:44111/wd/hub/').build();   console.log('Get');   driver.get('http://www.somepage.com').then(function() {        console.log('Screenshot');        driver.takeScreenshot().then(function(data){            console.log('foo/test' + index + '.png');            //var decodedImage = new Buffer(data, 'base64')            driver.quit();        });    }); });});