It's a common need. We should have a recipe to make it easy for users to get started.
I think Webdriver.IO would be the best choice.
This is quite straight forward:
import test from 'ava';
let webdriverio = require('webdriverio');
let client = webdriverio.remote({
// just using a local chromedriver
desiredCapabilities: {browserName: 'chrome'}
});
test.before(async t => {
await client.init()
.url('http://localhost');
});
test.after.always(async t => {
await client.end();
});
test('has a body', t => {
return client.isExisting('body').then(result => {
t.true(result);
});
});
I've only had success using AVA and webdriverio together when running tests serially
@rhubarbselleven Interested in submitting a recipe?
I did have success running tests in parallel with selenium-webdriver package.
You do need to start a Selenium server, for example with the webdriver-manager package.
Here is my example code:
import test from 'ava';
import webdriver from 'selenium-webdriver';
test.beforeEach(t => {
t.context.driver = new webdriver.Builder()
.forBrowser('chrome')
.usingServer('http://localhost:4444/wd/hub')
.build();
});
test('Search for webdriver', async t => {
let driver = t.context.driver;
await searchGoogle(driver, 'webdriver')
t.is(await driver.getTitle(), "webdriver - Google Search");
await driver.quit();
});
test('Search for avajs', async t => {
let driver = t.context.driver;
await searchGoogle(driver, 'avajs')
t.is(await driver.getTitle(), "avajs - Google Search");
await driver.quit();
});
test('Search for concurrent', async t => {
let driver = t.context.driver;
await searchGoogle(driver, 'concurrent')
t.is(await driver.getTitle(), "concurrent - Google Search");
await driver.quit();
});
async function searchGoogle(driver, keyword) {
await driver.get('http://www.google.com/ncr');
await driver.findElement(webdriver.By.name('q')).sendKeys(keyword);
await driver.findElement(webdriver.By.name('btnG')).click();
await driver.wait(webdriver.until.titleIs(keyword + ' - Google Search'), 1000);
}
@nreijmersdal After running the above code, the tests are getting executed serially. Getting the below results with 'ava --verbose'
√ Search for webdriver (6.6s)
√ Search for avajs (10.7s)
√ Search for concurrent (14.9s)
I'm running [email protected], [email protected] and [email protected] which uses selenium-server-standalone-3.5.3.jar. Any ideas what change is now required to get the tests running in parallel?
@aptester Sorry no idea. Also I am not using Ava anymore. Running each test in parallel doesn't make a lot of sense anyways. Maybe it is easier to group sets of tests and create a couple of command-line jobs to start the groups in parallel. This is what I used to do when we used Java for Selenium. Goodluck.
Most helpful comment
I did have success running tests in parallel with selenium-webdriver package.
You do need to start a Selenium server, for example with the webdriver-manager package.
Here is my example code: