Skip to content

Commit

Permalink
chore(ci,webdriverjs): update selenium-webdriver to latest (dequelabs…
Browse files Browse the repository at this point in the history
…#673)

* chore(ci): update selenium-webdriver to latest

* fix tests

* udpate webdriverjs
  • Loading branch information
straker authored Feb 28, 2023
1 parent 395d5fc commit b142be9
Show file tree
Hide file tree
Showing 6 changed files with 65 additions and 66 deletions.
52 changes: 26 additions & 26 deletions packages/cli/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion packages/cli/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@
"chromedriver": "^109.0.0",
"colors": "^1.4.0",
"commander": "^9.4.1",
"selenium-webdriver": "4.3.0"
"selenium-webdriver": "^4.8.1"
},
"devDependencies": {
"@types/chai": "^4.3.3",
Expand Down
31 changes: 15 additions & 16 deletions packages/cli/src/lib/webdriver.test.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import 'mocha';
import { assert } from 'chai';
import { startDriver } from './webdriver';
import { WebDriver } from 'selenium-webdriver';
import chromedriver from 'chromedriver';
import chrome from 'selenium-webdriver/chrome';
import type { Options } from 'selenium-webdriver/chrome';
Expand All @@ -9,6 +10,7 @@ import { WebdriverConfigParams } from '../types';
describe('startDriver', () => {
let config: WebdriverConfigParams;
let browser: string;
let driver: WebDriver;
beforeEach(() => {
browser = 'chrome-headless';
config = {
Expand All @@ -19,55 +21,52 @@ describe('startDriver', () => {
});

afterEach(async () => {
const service = chrome.getDefaultService();
if (service.isRunning()) {
await service.kill();
}
await driver.quit();
});

it('creates a driver', async () => {
const driver = await startDriver(config);
driver = await startDriver(config);
assert.isObject(driver);
assert.isFunction(driver.manage);
});

xit('sets the config.browser as the browser', async () => {
browser = 'chrome';
const driver = await startDriver(config);
driver = await startDriver(config);
const capabilities = await driver.getCapabilities();
assert.equal(capabilities.get('browserName'), browser);
});

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

assert.equal(capabilities.get('browserName'), 'chrome');
});

it('uses the chromedriver path with chrome-headless', async () => {
browser = 'chrome-headless';
await startDriver(config);
const service = chrome.getDefaultService();
driver = await startDriver(config);
const chromedriverPath = (config as any).builder.chromeService_.exe_;

assert.equal((service as any).executable_, chromedriver.path);
assert.equal(chromedriverPath, chromedriver.path);
});

it('uses the passed in chromedriver path with chrome-headless', async () => {
browser = 'chrome-headless';
config.chromedriverPath = path.relative(process.cwd(), chromedriver.path);
await startDriver(config);
const service = chrome.getDefaultService();
driver = await startDriver(config);
const chromedriverPath = (config as any).builder.chromeService_.exe_;

assert.notEqual(config.chromedriverPath, chromedriver.path);
assert.equal((service as any).executable_, config.chromedriverPath);
assert.equal(chromedriverPath, config.chromedriverPath);
});

it('passes the --no-sandbox argument to chromeOptions', async () => {
browser = 'chrome-headless';
config.chromeOptions = ['--no-sandbox'];
await startDriver(config);
driver = await startDriver(config);

const options = config?.builder?.getChromeOptions();
assert.isArray(options?.get('goog:chromeOptions').args);
Expand All @@ -80,7 +79,7 @@ describe('startDriver', () => {
it('passes multiple arguments argument to chromeOptions', async () => {
browser = 'chrome-headless';
config.chromeOptions = ['no-sandbox', 'disable-dev-shm-usage'];
await startDriver(config);
driver = await startDriver(config);

const options = config?.builder?.getChromeOptions();
assert.isArray(options?.get('goog:chromeOptions').args);
Expand All @@ -94,7 +93,7 @@ describe('startDriver', () => {
it('sets the --timeout flag', async () => {
browser = 'chrome-headless';
config.timeout = 10000;
const driver = await startDriver(config);
driver = await startDriver(config);
config.builder;
const timeoutValue = await driver.manage().getTimeouts();

Expand Down
10 changes: 5 additions & 5 deletions packages/cli/src/lib/webdriver.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,7 @@ const startDriver = async (
if (config.browser === 'chrome-headless') {
const service = new chrome.ServiceBuilder(
config.chromedriverPath || chromedriver.path
).build();
// Pinned to selenium-webdriver@4.3.0
// https://github.com/SeleniumHQ/selenium/pull/10796/files#diff-6c87d95a2288e92e15a6bb17710c763c01c2290e679beb26220858f3218b6a62L260
chrome.setDefaultService(service);
);

let options = new chrome.Options().headless();
if (config.chromeOptions?.length) {
Expand All @@ -24,7 +21,10 @@ const startDriver = async (
}, options);
}

builder = new Builder().forBrowser('chrome').setChromeOptions(options);
builder = new Builder()
.forBrowser('chrome')
.setChromeOptions(options)
.setChromeService(service);
} else {
builder = new Builder().forBrowser(config.browser);
}
Expand Down
34 changes: 17 additions & 17 deletions packages/webdriverjs/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion packages/webdriverjs/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@
"mocha": "^10.0.0",
"nyc": "^15.1.0",
"rimraf": "^3.0.2",
"selenium-webdriver": "4.3.0",
"selenium-webdriver": "^4.8.1",
"sinon": "^14.0.1",
"test-listen": "^1.1.0",
"ts-node": "^10.9.1",
Expand Down

0 comments on commit b142be9

Please sign in to comment.