-
Notifications
You must be signed in to change notification settings - Fork 78
Expand file tree
/
Copy pathwebdriver.test.ts
More file actions
141 lines (125 loc) · 4.64 KB
/
Copy pathwebdriver.test.ts
File metadata and controls
141 lines (125 loc) · 4.64 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
import 'mocha';
import { assert } from 'chai';
import { startDriver } from './webdriver';
import { WebDriver } from 'selenium-webdriver';
import chrome from 'selenium-webdriver/chrome';
import path from 'path';
import { WebdriverConfigParams } from '../types';
import sinon from 'sinon';
import { CHROME_TEST_PATH, CHROMEDRIVER_TEST_PATH } from './utils';
describe('startDriver', () => {
let config: WebdriverConfigParams;
let browser: string;
let driver: WebDriver;
before(() => {
assert(
process.env.CHROME_TEST_PATH,
[
'CHROME_TEST_PATH is not set.',
'Install Chrome: npx @puppeteer/browsers install chrome@stable',
'The command prints the resolved binary path; export it as CHROME_TEST_PATH.',
'e.g. export CHROME_TEST_PATH="$(npx @puppeteer/browsers install chrome@stable | awk \'{print $2}\')"'
].join('\n')
);
assert(
process.env.CHROMEDRIVER_TEST_PATH,
[
'CHROMEDRIVER_TEST_PATH is not set.',
'Install ChromeDriver: npx @puppeteer/browsers install chromedriver@stable',
'The command prints the resolved binary path; export it as CHROMEDRIVER_TEST_PATH.',
'e.g. export CHROMEDRIVER_TEST_PATH="$(npx @puppeteer/browsers install chromedriver@stable | awk \'{print $2}\')"'
].join('\n')
);
});
beforeEach(() => {
browser = 'chrome-headless';
config = {
timeout: 90,
get browser() {
return browser;
}
};
});
afterEach(async () => {
// try catch required due to `chrome.options` being mocked with sinon
// and not properly creating a driver
try {
await driver.quit();
} catch (error) {}
});
it('creates a driver', async () => {
driver = await startDriver(config);
assert.isObject(driver);
assert.isFunction(driver.manage);
});
xit('sets the config.browser as the browser', async () => {
browser = 'chrome';
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';
driver = await startDriver(config);
const capabilities = await driver.getCapabilities();
// https://github.com/seleniumbase/SeleniumBase/issues/2343\
assert.include(capabilities.get('browserName'), 'chrome');
});
it('uses the chrome path with chrome-headless', async () => {
browser = 'chrome-headless';
driver = await startDriver(config);
const options = config?.builder?.getChromeOptions();
const chromePath = (options as any).get('goog:chromeOptions').binary;
assert.equal(chromePath, CHROME_TEST_PATH);
});
it('uses the chromedriver path with chrome-headless', async () => {
browser = 'chrome-headless';
driver = await startDriver(config);
const chromedriverPath = (config as any).builder.chromeService_.exe_;
assert.equal(chromedriverPath, CHROMEDRIVER_TEST_PATH);
});
it('uses the passed in chromedriver path with chrome-headless', async () => {
browser = 'chrome-headless';
config.chromedriverPath = path.relative(
process.cwd(),
CHROMEDRIVER_TEST_PATH as string
);
driver = await startDriver(config);
const chromedriverPath = (config as any).builder.chromeService_.exe_;
assert.notEqual(config.chromedriverPath, CHROMEDRIVER_TEST_PATH);
assert.equal(chromedriverPath, config.chromedriverPath);
});
it('passes multiple arguments argument to chromeOptions', async () => {
browser = 'chrome-headless';
config.chromeOptions = ['disable-dev-shm-usage'];
driver = await startDriver(config);
const options = config?.builder?.getChromeOptions();
assert.isArray(options?.get('goog:chromeOptions').args);
assert.deepEqual(options?.get('goog:chromeOptions').args, [
'headless',
'disable-dev-shm-usage',
'no-sandbox'
]);
});
it('sets the --timeout flag', async () => {
browser = 'chrome-headless';
config.timeout = 10000;
driver = await startDriver(config);
config.builder;
const timeoutValue = await driver.manage().getTimeouts();
assert.isObject(timeoutValue);
assert.deepEqual(timeoutValue.script, 10000000);
});
it('invokes `options.headless()` on versions of selenium-webdriver < 4.17.0', async () => {
const stub = sinon.stub(chrome, 'Options').returns({
headless: () => {}
});
// try catch required due to `chrome.options` being mocked with sinon
// and not properly creating a driver
try {
driver = await startDriver(config);
} catch (error) {}
assert.isTrue(stub.calledOnce);
stub.restore();
});
});