diff --git a/packages/cli/index.js b/packages/cli/index.js index 6d8aafa1..fefc666d 100755 --- a/packages/cli/index.js +++ b/packages/cli/index.js @@ -8,7 +8,7 @@ const version = require('./package.json').version; const axeTestUrls = require('./lib/axe-test-urls'); const saveOutcome = require('./lib/save-outcome'); const utils = require('./lib/utils'); -const { startDriver } = require('./webdriver'); +const { startDriver } = require('./lib/webdriver'); program .version(version) diff --git a/packages/cli/lib/axe-test-urls.js b/packages/cli/lib/axe-test-urls.js index 9356814a..3132a4e5 100644 --- a/packages/cli/lib/axe-test-urls.js +++ b/packages/cli/lib/axe-test-urls.js @@ -2,14 +2,14 @@ const WebDriver = require('selenium-webdriver'); const AxeBuilder = require('axe-webdriverjs'); -const { stopDriver } = require('./webdriver'); function testPages(urls, config, events) { const driver = config.driver; - + const scriptTimeout = (config.timeout || 20) * 1000.0; + driver.manage().setTimeouts({ script: scriptTimeout }); // End of the line, no more page left if (urls.length === 0) { - stopDriver(config); + driver.quit(); return Promise.resolve([]); } diff --git a/packages/cli/lib/webdriver.js b/packages/cli/lib/webdriver.js index 6618558b..a0e8dfbd 100644 --- a/packages/cli/lib/webdriver.js +++ b/packages/cli/lib/webdriver.js @@ -4,8 +4,6 @@ const chrome = require('selenium-webdriver/chrome'); function startDriver(config) { let builder; - const scriptTimeout = (config.timeout || 20) * 1000.0; - if (config.browser === 'chrome-headless') { // Tell selenium use the driver in node_modules const service = new chrome.ServiceBuilder( @@ -27,23 +25,12 @@ function startDriver(config) { } else { builder = new Builder().forBrowser(config.browser); } - // Launch a browser config.driver = builder.build(); config.builder = builder; - return config.driver - .manage() - .timeouts() - .setScriptTimeout(scriptTimeout) - .then(() => config); -} - -function stopDriver(config) { - config.driver.quit(); } module.exports = { - startDriver, - stopDriver + startDriver }; diff --git a/packages/cli/test/axe-test-urls.js b/packages/cli/test/axe-test-urls.js index ae762210..ea15784a 100644 --- a/packages/cli/test/axe-test-urls.js +++ b/packages/cli/test/axe-test-urls.js @@ -15,7 +15,10 @@ describe('testPages', function () { wait: async arg => arg, switchTo: () => ({ defaultContent: () => {} }), findElements: async () => [], - quit: async arg => arg + quit: async arg => arg, + manage: () => ({ + setTimeouts: async arg => arg + }) }; config = { driver: mockDriver }; }); diff --git a/packages/cli/test/integrations.js b/packages/cli/test/integrations.js index 8ddd0d65..141ce794 100644 --- a/packages/cli/test/integrations.js +++ b/packages/cli/test/integrations.js @@ -5,7 +5,7 @@ const chrome = require('selenium-webdriver/chrome'); const http = require('http'); const nodeStatic = require('node-static'); const axeTestUrls = require('../lib/axe-test-urls'); -const { startDriver, stopDriver } = require('../lib/webdriver'); +const { startDriver } = require('../lib/webdriver'); describe('integrations', function () { let program, urls, server; @@ -36,7 +36,7 @@ describe('integrations', function () { }); afterEach(async () => { - stopDriver(program); + program.driver.quit() const service = chrome.getDefaultService(); if (service.isRunning()) { diff --git a/packages/cli/test/webdriver.js b/packages/cli/test/webdriver.js index badb7778..afbded7c 100644 --- a/packages/cli/test/webdriver.js +++ b/packages/cli/test/webdriver.js @@ -1,7 +1,7 @@ 'use strict'; const assert = require('chai').assert; -const { startDriver, stopDriver } = require('../lib/webdriver'); +const { startDriver } = require('../lib/webdriver'); const chromedriver = require('chromedriver'); const chrome = require('selenium-webdriver/chrome'); const path = require('path'); @@ -18,7 +18,6 @@ describe('startDriver', () => { }); afterEach(async () => { - stopDriver(config); const service = chrome.getDefaultService(); if (service.isRunning()) { await service.stop(); @@ -74,35 +73,25 @@ describe('startDriver', () => { assert.equal(service.executable_, config.chromedriverPath); }); - it('sets the --headless flag with chrome-headless', async () => { - browser = 'chrome-headless'; - const { builder } = await startDriver(config); - const capabilities = await builder.getCapabilities(); - const chromeOptions = capabilities.get('chromeOptions'); - assert.isObject(chromeOptions); - assert.deepEqual(chromeOptions.args, ['--headless']); - }); + it('sets the --headless flag with chrome-headless', async () => { + browser = 'chrome-headless'; + await startDriver(config); + const capabilities = await config.builder.getCapabilities(); + const chromeOptions = capabilities.get('chromeOptions'); - it('sets the --chrome-options flag with no-sandbox', async () => { - browser = 'chrome-headless'; - config.chromeOptions = ['--no-sandbox']; - const { builder } = await startDriver(config); - const capabilities = await builder.getCapabilities(); - const chromeOptions = capabilities.get('chromeOptions'); + assert.isObject(chromeOptions); + assert.deepEqual(chromeOptions.args, ['--headless']); + }); - assert.isArray(chromeOptions.args); - assert.deepEqual(chromeOptions.args, ['--headless', '--no-sandbox']); - }); -}); + it('sets the --chrome-options flag with no-sandbox', async () => { + browser = 'chrome-headless'; + config.chromeOptions = ['--no-sandbox']; + await startDriver(config); + const capabilities = await config.builder.getCapabilities(); + const chromeOptions = capabilities.get('chromeOptions'); -describe('stopDriver', () => { - it('calls browser.quit', () => { - let called = 0; - stopDriver({ - browser: 'chrome-headless', - driver: { quit: () => called++ } - }); - assert.equal(called, 1); - }); + assert.isArray(chromeOptions.args); + assert.deepEqual(chromeOptions.args, ['--headless', '--no-sandbox']); + }); });