Skip to content

Commit 3021877

Browse files
authored
ci: fix chrome integration tests and split browser tests (dequelabs#3735)
1 parent c1af750 commit 3021877

File tree

2 files changed

+57
-85
lines changed

2 files changed

+57
-85
lines changed

Diff for: .circleci/config.yml

+29-14
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ jobs:
5151
- run: npm run eslint
5252

5353
# Run the test suite.
54-
test_unix:
54+
test_chrome:
5555
<<: *defaults
5656
<<: *unix_box
5757
steps:
@@ -60,8 +60,18 @@ jobs:
6060
- <<: *restore_dependency_cache_unix
6161
- run: npx browser-driver-manager install chromedriver --verbose
6262
- run: npm run build
63-
- run: npm run test -- --browsers Chrome,Firefox
63+
- run: npm run test -- --browsers Chrome
6464
- run: npm run test:integration:chrome
65+
66+
test_firefox:
67+
<<: *defaults
68+
<<: *unix_box
69+
steps:
70+
- browser-tools/install-browser-tools
71+
- checkout
72+
- <<: *restore_dependency_cache_unix
73+
- run: npm run build
74+
- run: npm run test -- --browsers Firefox
6575
- run: npm run test:integration:firefox
6676

6777
# Run examples under `doc/examples`
@@ -276,38 +286,41 @@ workflows:
276286
requires:
277287
- dependencies_unix
278288
# Run tests on all commits, but after installing dependencies
279-
- test_unix:
289+
- test_chrome:
280290
requires:
281291
- lint
292+
- test_firefox:
293+
requires:
294+
- test_chrome
282295
- test_examples:
283296
requires:
284-
- test_unix
297+
- test_chrome
285298
- test_act:
286299
requires:
287-
- test_unix
300+
- test_chrome
288301
- test_aria_practices:
289302
requires:
290-
- test_unix
303+
- test_chrome
291304
- test_locales:
292305
requires:
293-
- test_unix
306+
- test_chrome
294307
- test_virtual_rules:
295308
requires:
296-
- test_unix
309+
- test_chrome
297310
- build_api_docs:
298311
requires:
299-
- test_unix
312+
- test_chrome
300313
- test_rule_help_version:
301314
requires:
302-
- test_unix
315+
- test_chrome
303316
- test_node:
304317
requires:
305-
- test_unix
318+
- test_chrome
306319
# Hold for approval
307320
- hold:
308321
type: approval
309322
requires:
310-
- test_unix
323+
- test_chrome
311324
- test_examples
312325
- test_locales
313326
- test_virtual_rules
@@ -322,7 +335,8 @@ workflows:
322335
- next_release:
323336
requires:
324337
- dependencies_unix
325-
- test_unix
338+
- test_chrome
339+
- test_firefox
326340
- test_examples
327341
- test_locales
328342
- test_virtual_rules
@@ -334,7 +348,8 @@ workflows:
334348
- release:
335349
requires:
336350
- dependencies_unix
337-
- test_unix
351+
- test_chrome
352+
- test_firefox
338353
- test_examples
339354
- test_locales
340355
- test_virtual_rules

Diff for: test/integration/full/test-webdriver.js

+28-71
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,18 @@
11
/*global window, Promise */
22

3-
var globby = require('globby');
4-
var WebDriver = require('selenium-webdriver');
5-
var chrome = require('selenium-webdriver/chrome');
6-
var chromedriver = require('chromedriver');
3+
const globby = require('globby');
4+
const chrome = require('selenium-webdriver/chrome');
5+
const firefox = require('selenium-webdriver/firefox');
6+
const chromedriver = require('chromedriver');
77

8-
var args = process.argv.slice(2);
8+
const args = process.argv.slice(2);
99

1010
// allow running certain browsers through command line args
1111
// (only one browser supported, run multiple times for more browsers)
12-
var browser = 'chrome';
12+
let browser = 'chrome';
1313
args.forEach(function (arg) {
1414
// pattern: browsers=Chrome
15-
var parts = arg.split('=');
15+
const parts = arg.split('=');
1616
if (parts[0] === 'browser') {
1717
browser = parts[1].toLowerCase();
1818
}
@@ -25,7 +25,7 @@ function collectTestResults(driver) {
2525
// inject a script that waits half a second
2626
return driver
2727
.executeAsyncScript(function () {
28-
var callback = arguments[arguments.length - 1];
28+
const callback = arguments[arguments.length - 1];
2929
setTimeout(function () {
3030
if (!window.mocha) {
3131
callback('mocha-missing;' + window.location.href);
@@ -57,7 +57,7 @@ function collectTestResults(driver) {
5757
* Test each URL
5858
*/
5959
function runTestUrls(driver, isMobile, urls, errors) {
60-
var url = urls.shift();
60+
const url = urls.shift();
6161
errors = errors || [];
6262

6363
return (
@@ -72,9 +72,9 @@ function runTestUrls(driver, isMobile, urls, errors) {
7272
})
7373
// And process them
7474
.then(function (promiseResults) {
75-
var capabilities = promiseResults[0];
76-
var result = promiseResults[1];
77-
var browserName =
75+
const capabilities = promiseResults[0];
76+
const result = promiseResults[1];
77+
const browserName =
7878
capabilities.get('browserName') +
7979
(capabilities.get('mobileEmulationEnabled') ? '-mobile' : '');
8080
console.log(url + ' [' + browserName + ']');
@@ -117,80 +117,45 @@ function runTestUrls(driver, isMobile, urls, errors) {
117117
* Build web driver depends whether REMOTE_SELENIUM_URL is set
118118
*/
119119
function buildWebDriver(browser) {
120-
// Pinned to [email protected]
121-
// https://github.com/SeleniumHQ/selenium/pull/10796/files#diff-6c87d95a2288e92e15a6bb17710c763c01c2290e679beb26220858f3218b6a62L260
122-
123-
var capabilities;
124-
var mobileBrowser = browser.split('-mobile');
125-
126-
if (mobileBrowser.length > 1) {
127-
browser = mobileBrowser[0];
128-
capabilities = {
129-
browserName: mobileBrowser[0],
130-
chromeOptions: {
131-
mobileEmulation: {
132-
deviceMetrics: {
133-
width: 320,
134-
height: 568,
135-
pixelRatio: 2
136-
}
137-
}
138-
}
139-
};
140-
}
120+
let webdriver;
121+
const mobileBrowser = browser.split('-mobile');
141122

142123
// fix chrome DevToolsActivePort file doesn't exist in CricleCI (as well as a
143124
// host of other problems with starting Chrome). the only thing that seems to
144125
// allow Chrome to start without problems consistently is using ChromeHeadless
145126
// @see https://stackoverflow.com/questions/50642308/webdriverexception-unknown-error-devtoolsactiveport-file-doesnt-exist-while-t
146127
if (browser === 'chrome') {
147-
var service = new chrome.ServiceBuilder(chromedriver.path).build();
148-
chrome.setDefaultService(service);
128+
const service = new chrome.ServiceBuilder(chromedriver.path).build();
149129

150-
capabilities = WebDriver.Capabilities.chrome();
151-
capabilities.set('chromeOptions', {
152-
args: [
130+
const options = new chrome.Options()
131+
.headless()
132+
.addArguments([
153133
'--no-sandbox',
154-
'--headless',
155134
'--disable-extensions',
156135
'--disable-dev-shm-usage'
157-
]
158-
});
136+
]);
137+
webdriver = chrome.Driver.createSession(options, service);
138+
} else if (browser === 'firefox') {
139+
const options = new firefox.Options().headless();
140+
webdriver = firefox.Driver.createSession(options);
159141
}
160142

161-
var webdriver = new WebDriver.Builder()
162-
.withCapabilities(capabilities)
163-
.forBrowser(browser);
164-
165143
if (process.env.REMOTE_SELENIUM_URL) {
166144
webdriver.usingServer(process.env.REMOTE_SELENIUM_URL);
167145
}
168146

169-
// @see https://github.com/SeleniumHQ/selenium/issues/6026
170-
if (browser === 'safari') {
171-
var safari = require('selenium-webdriver/safari');
172-
var server = new safari.ServiceBuilder()
173-
.addArguments('--legacy')
174-
.build()
175-
.start();
176-
177-
webdriver.usingServer(server);
178-
}
179-
180147
return {
181-
driver: webdriver.build(),
148+
driver: webdriver,
182149
isMobile: mobileBrowser.length > 1
183150
};
184151
}
185152

186153
function start(options) {
187-
var driver;
188-
var isMobile = false;
189154
// yes, really, and this isn't documented anywhere either.
190155
options.browser =
191156
options.browser === 'edge' ? 'MicrosoftEdge' : options.browser;
192157

193-
var testUrls = globby
158+
const testUrls = globby
194159
.sync([
195160
'test/integration/full/**/*.{html,xhtml}',
196161
'!**/frames/**/*.{html,xhtml}'
@@ -214,17 +179,9 @@ function start(options) {
214179
}
215180

216181
// try to load the browser
217-
try {
218-
var webDriver = buildWebDriver(options.browser);
219-
driver = webDriver.driver;
220-
isMobile = webDriver.isMobile;
221-
// If load fails, warn user and move to the next task
222-
} catch (err) {
223-
console.log();
224-
console.log(err.message);
225-
console.log('Aborted testing using ' + options.browser);
226-
return process.exit();
227-
}
182+
const webDriver = buildWebDriver(options.browser);
183+
const driver = webDriver.driver;
184+
const isMobile = webDriver.isMobile;
228185

229186
driver.manage().setTimeouts({
230187
pageLoad: 50000,

0 commit comments

Comments
 (0)