Skip to content
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

fix(cli): start webdriver correctly #69

Merged
merged 6 commits into from
Aug 17, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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) {
michael-siek marked this conversation as resolved.
Show resolved Hide resolved
//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