Skip to content

Commit

Permalink
fix(cli): start webdriver correctly (#69)
Browse files Browse the repository at this point in the history
  • Loading branch information
michael-siek authored Aug 17, 2020
1 parent 02beb41 commit 90675b4
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 16 deletions.
8 changes: 4 additions & 4 deletions packages/cli/lib/axe-test-urls.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,15 @@
const WebDriver = require('selenium-webdriver');
const AxeBuilder = require('@axe-core/webdriverjs');

function testPages(urls, config, events) {
const driver = config.driver;

async function testPages(urls, config, events) {
//selenium.dev/selenium/docs/api/javascript/module/selenium-webdriver/index_exports_ThenableWebDriver.html
// We tried to use the non-thenable webdriver and failed the unit test for startDriver() even after we tried to make it work
const driver = await config.driver;
// End of the line, no more page left
if (urls.length === 0) {
driver.quit();
return Promise.resolve([]);
}

return new Promise((resolve, reject) => {
// Grab the first item on the URL list
const currentUrl = urls[0].replace(/[,;]$/, '');
Expand Down
7 changes: 3 additions & 4 deletions packages/cli/lib/webdriver.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,11 +27,10 @@ async function startDriver(config) {
builder = new Builder().forBrowser(config.browser);
}
// Launch a browser
config.driver = builder.build();
config.builder = builder;

await config.driver.manage().setTimeouts({ script: scriptTimeout })
return config.driver;
const driver = builder.build();
await driver.manage().setTimeouts({ script: scriptTimeout })
return driver;
}

module.exports = {
Expand Down
2 changes: 1 addition & 1 deletion packages/cli/test/integrations.js
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ describe('integrations', function () {
program = {
browser: 'chrome-headless'
};
await startDriver(program);
program.driver = await startDriver(program);
urls = ['http://localhost:8182/test/testpage.html'];
});

Expand Down
14 changes: 7 additions & 7 deletions packages/cli/test/webdriver.js
Original file line number Diff line number Diff line change
Expand Up @@ -31,10 +31,10 @@ describe('startDriver', () => {
});

it('creates a driver', async () => {
await startDriver(config);
const driver = await startDriver(config);

assert.isObject(config.driver);
assert.isFunction(config.driver.manage);
assert.isObject(driver);
assert.isFunction(driver.manage);
});

xit('sets the config.browser as the browser', done => {
Expand All @@ -49,8 +49,8 @@ describe('startDriver', () => {

it('sets the browser as chrome with chrome-headless', async () => {
browser = 'chrome-headless';
await startDriver(config);
const capabilities = await config.driver.getCapabilities();
const driver = await startDriver(config);
const capabilities = await driver.getCapabilities();

assert.equal(capabilities.get('browserName'), 'chrome');
});
Expand Down Expand Up @@ -97,9 +97,9 @@ describe('startDriver', () => {
it('sets the --timeout flag', async () => {
browser = 'chrome-headless';
config.timeout = 10000;
await startDriver(config);
const driver = await startDriver(config);
await config.builder;
const timeoutValue = await config.driver.manage().getTimeouts();
const timeoutValue = await driver.manage().getTimeouts();

assert.isObject(timeoutValue);
assert.deepEqual(timeoutValue.script, 10000000);
Expand Down

0 comments on commit 90675b4

Please sign in to comment.