UNPKG

@axe-core/cli

Version:

A CLI for accessibility testing using axe-core

135 lines 7.14 kB
"use strict"; var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) { function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); } return new (P || (P = Promise))(function (resolve, reject) { function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } } function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } } function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); } step((generator = generator.apply(thisArg, _arguments || [])).next()); }); }; var __importDefault = (this && this.__importDefault) || function (mod) { return (mod && mod.__esModule) ? mod : { "default": mod }; }; Object.defineProperty(exports, "__esModule", { value: true }); require("mocha"); const chai_1 = require("chai"); const webdriver_1 = require("./webdriver"); const chrome_1 = __importDefault(require("selenium-webdriver/chrome")); const path_1 = __importDefault(require("path")); const sinon_1 = __importDefault(require("sinon")); const utils_1 = require("./utils"); describe('startDriver', () => { let config; let browser; let driver; before(() => { (0, chai_1.assert)(process.env.CHROME_TEST_PATH, 'CHROME_TEST_PATH is not set. Run `npx browser-driver-manager install chrome`'); (0, chai_1.assert)(process.env.CHROMEDRIVER_TEST_PATH, 'CHROMEDRIVER_TEST_PATH is not set. Run `npx browser-driver-manager install chrome`'); }); beforeEach(() => { browser = 'chrome-headless'; config = { timeout: 90, get browser() { return browser; } }; }); afterEach(() => __awaiter(void 0, void 0, void 0, function* () { // try catch required due to `chrome.options` being mocked with sinon // and not properly creating a driver try { yield driver.quit(); } catch (error) { } })); it('creates a driver', () => __awaiter(void 0, void 0, void 0, function* () { driver = yield (0, webdriver_1.startDriver)(config); chai_1.assert.isObject(driver); chai_1.assert.isFunction(driver.manage); })); xit('sets the config.browser as the browser', () => __awaiter(void 0, void 0, void 0, function* () { browser = 'chrome'; driver = yield (0, webdriver_1.startDriver)(config); const capabilities = yield driver.getCapabilities(); chai_1.assert.equal(capabilities.get('browserName'), browser); })); it('sets the browser as chrome with chrome-headless', () => __awaiter(void 0, void 0, void 0, function* () { browser = 'chrome-headless'; driver = yield (0, webdriver_1.startDriver)(config); const capabilities = yield driver.getCapabilities(); // https://github.com/seleniumbase/SeleniumBase/issues/2343\ chai_1.assert.include(capabilities.get('browserName'), 'chrome'); })); it('uses the chrome path with chrome-headless', () => __awaiter(void 0, void 0, void 0, function* () { var _a; browser = 'chrome-headless'; driver = yield (0, webdriver_1.startDriver)(config); const options = (_a = config === null || config === void 0 ? void 0 : config.builder) === null || _a === void 0 ? void 0 : _a.getChromeOptions(); const chromePath = options.get('goog:chromeOptions').binary; chai_1.assert.equal(chromePath, utils_1.CHROME_TEST_PATH); })); it('uses the chromedriver path with chrome-headless', () => __awaiter(void 0, void 0, void 0, function* () { browser = 'chrome-headless'; driver = yield (0, webdriver_1.startDriver)(config); const chromedriverPath = config.builder.chromeService_.exe_; chai_1.assert.equal(chromedriverPath, utils_1.CHROMEDRIVER_TEST_PATH); })); it('uses the passed in chromedriver path with chrome-headless', () => __awaiter(void 0, void 0, void 0, function* () { browser = 'chrome-headless'; config.chromedriverPath = path_1.default.relative(process.cwd(), utils_1.CHROMEDRIVER_TEST_PATH); driver = yield (0, webdriver_1.startDriver)(config); const chromedriverPath = config.builder.chromeService_.exe_; chai_1.assert.notEqual(config.chromedriverPath, utils_1.CHROMEDRIVER_TEST_PATH); chai_1.assert.equal(chromedriverPath, config.chromedriverPath); })); it('passes the --no-sandbox argument to chromeOptions', () => __awaiter(void 0, void 0, void 0, function* () { var _a; browser = 'chrome-headless'; config.chromeOptions = ['--no-sandbox']; driver = yield (0, webdriver_1.startDriver)(config); const options = (_a = config === null || config === void 0 ? void 0 : config.builder) === null || _a === void 0 ? void 0 : _a.getChromeOptions(); chai_1.assert.isArray(options === null || options === void 0 ? void 0 : options.get('goog:chromeOptions').args); chai_1.assert.deepEqual(options === null || options === void 0 ? void 0 : options.get('goog:chromeOptions').args, [ 'headless', '--no-sandbox' ]); })); it('passes multiple arguments argument to chromeOptions', () => __awaiter(void 0, void 0, void 0, function* () { var _a; browser = 'chrome-headless'; config.chromeOptions = ['no-sandbox', 'disable-dev-shm-usage']; driver = yield (0, webdriver_1.startDriver)(config); const options = (_a = config === null || config === void 0 ? void 0 : config.builder) === null || _a === void 0 ? void 0 : _a.getChromeOptions(); chai_1.assert.isArray(options === null || options === void 0 ? void 0 : options.get('goog:chromeOptions').args); chai_1.assert.deepEqual(options === null || options === void 0 ? void 0 : options.get('goog:chromeOptions').args, [ 'headless', 'no-sandbox', 'disable-dev-shm-usage' ]); })); it('sets the --timeout flag', () => __awaiter(void 0, void 0, void 0, function* () { browser = 'chrome-headless'; config.timeout = 10000; driver = yield (0, webdriver_1.startDriver)(config); config.builder; const timeoutValue = yield driver.manage().getTimeouts(); chai_1.assert.isObject(timeoutValue); chai_1.assert.deepEqual(timeoutValue.script, 10000000); })); it('invokes `options.headless()` on versions of selenium-webdriver < 4.17.0', () => __awaiter(void 0, void 0, void 0, function* () { const stub = sinon_1.default.stub(chrome_1.default, 'Options').returns({ headless: () => { } }); // try catch required due to `chrome.options` being mocked with sinon // and not properly creating a driver try { driver = yield (0, webdriver_1.startDriver)(config); } catch (error) { } chai_1.assert.isTrue(stub.calledOnce); stub.restore(); })); }); //# sourceMappingURL=webdriver.test.js.map