Skip to content

Commit 5e8fe96

Browse files
authored
More ubuntu tests (#235)
- Run Firefox and Chrome browse tests in headless mode on ubuntu - Shared common setup steps with yaml anchors to avoid bugs
1 parent 45439df commit 5e8fe96

File tree

2 files changed

+62
-35
lines changed

2 files changed

+62
-35
lines changed

.github/workflows/test.yml

Lines changed: 34 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -10,40 +10,56 @@ on:
1010
workflow_dispatch:
1111

1212
jobs:
13-
browser:
14-
name: Test Browser
13+
browser-macos:
14+
name: Test Browser on macOS
1515
runs-on: macos-latest
1616
env:
1717
GITHUB_ACTIONS_OUTPUT: ""
1818
strategy:
1919
fail-fast: false
2020
matrix:
21-
browser: [chrome, firefox, safari]
21+
browser: [safari]
2222
suite: [default, disabled, main]
2323
steps:
24-
- name: Extract Week Number
25-
run: echo "WEEK_NUMBER=$(date +%W)" >> $GITHUB_ENV
26-
27-
- name: Install Firefox
28-
if: ${{ matrix.browser == 'firefox' }}
29-
run: brew install --cask firefox
3024

31-
- name: Checkout Branch
25+
- &checkout-branch
26+
name: Checkout Branch
3227
uses: actions/checkout@v5
3328

34-
- name: Setup Node
29+
- &setup-node
30+
name: Setup Node
3531
uses: actions/setup-node@v5
3632
with:
3733
node-version-file: package.json
3834
cache: npm
3935

40-
- name: Install Node Packages
36+
- &install-node-packages
37+
name: Install Node Packages
4138
run: npm ci
4239

4340
- name: Run Tests
4441
run: |
4542
echo "Running in $BROWSER"
4643
npm run test:${{ matrix.browser }} -- ${{ matrix.suite }}
44+
45+
browser-linux:
46+
name: Test Browser on Linux
47+
runs-on: ubuntu-latest
48+
env:
49+
GITHUB_ACTIONS_OUTPUT: ""
50+
strategy:
51+
fail-fast: false
52+
matrix:
53+
browser: [chrome, firefox]
54+
suite: [default, disabled, main]
55+
steps:
56+
- *checkout-branch
57+
- *setup-node
58+
- *install-node-packages
59+
- name: Run Tests
60+
run: |
61+
echo "Running in $BROWSER"
62+
npm run test:${{ matrix.browser }} -- ${{ matrix.suite }}
4763
shell:
4864
name: Test Shell
4965
runs-on: ubuntu-latest
@@ -55,21 +71,13 @@ jobs:
5571
shell: [jsc, spidermonkey, v8]
5672
suite: [default, disabled, main]
5773
steps:
74+
- *checkout-branch
75+
- *setup-node
76+
- *install-node-packages
77+
5878
- name: Extract Week Number
5979
run: echo "WEEK_NUMBER=$(date +%W)" >> $GITHUB_ENV
6080

61-
- name: Checkout Branch
62-
uses: actions/checkout@v5
63-
64-
- name: Setup Node
65-
uses: actions/setup-node@v5
66-
with:
67-
node-version-file: package.json
68-
cache: npm
69-
70-
- name: Install Node Packages
71-
run: npm ci
72-
7381
- name: Cache jsvu Binaries
7482
uses: actions/cache@v4
7583
with:
@@ -89,14 +97,8 @@ jobs:
8997
with:
9098
fetch-depth: ${{ github.event_name == 'pull_request' && 2 || 0 }}
9199

92-
- name: Setup Node
93-
uses: actions/setup-node@v4
94-
with:
95-
node-version-file: package.json
96-
cache: npm
97-
98-
- name: Install Node Packages
99-
run: npm ci
100+
- *setup-node
101+
- *install-node-packages
100102

101103
- name: Run Build
102104
run: |

tests/run-browser.mjs

Lines changed: 28 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,8 @@
2626

2727
import serve from "./server.mjs";
2828
import { Builder, Capabilities, logging } from "selenium-webdriver";
29+
import { Options as ChromeOptions } from "selenium-webdriver/chrome.js";
30+
import { Options as FirefoxOptions } from "selenium-webdriver/firefox.js";
2931
import commandLineArgs from "command-line-args";
3032
import { promises as fs } from "fs";
3133
import path from "path";
@@ -95,20 +97,30 @@ if (options.suite && !VALID_TAGS.includes(options.suite))
9597
const BROWSER = options?.browser;
9698
if (!BROWSER)
9799
printHelp("No browser specified, use $BROWSER or --browser", optionDefinitions);
100+
const IS_HEADLESS = os.platform() === "linux" && !process.env.DISPLAY;
98101

99102
let capabilities;
103+
let browserOptions;
100104
switch (BROWSER) {
101105
case "safari":
102106
capabilities = Capabilities.safari();
103107
capabilities.set("safari:diagnose", true);
104108
break;
105109

106110
case "firefox": {
107-
capabilities = Capabilities.firefox();
111+
capabilities = Capabilities.firefox()
112+
if (IS_HEADLESS) {
113+
browserOptions = new FirefoxOptions();
114+
browserOptions.addArguments("-headless");
115+
}
108116
break;
109117
}
110118
case "chrome": {
111-
capabilities = Capabilities.chrome();
119+
capabilities = Capabilities.chrome()
120+
if (IS_HEADLESS) {
121+
browserOptions = new ChromeOptions();
122+
browserOptions.addArguments("--headless");
123+
}
112124
break;
113125
}
114126
case "edge": {
@@ -159,7 +171,20 @@ async function runEnd2EndTest(name, params) {
159171
}
160172

161173
async function testEnd2End(params) {
162-
const driver = await new Builder().withCapabilities(capabilities).build();
174+
const builder = new Builder().withCapabilities(capabilities);
175+
if (browserOptions) {
176+
switch(BROWSER) {
177+
case "firefox":
178+
builder.setFirefoxOptions(browserOptions);
179+
break;
180+
case "chrome":
181+
builder.setChromeOptions(browserOptions);
182+
break;
183+
default:
184+
break;
185+
}
186+
}
187+
const driver = await builder.build();
163188
const sessionId = (await driver.getSession()).getId();
164189
const driverCapabilities = await driver.getCapabilities();
165190
logInfo(`Browser: ${driverCapabilities.getBrowserName()} ${driverCapabilities.getBrowserVersion()}`);

0 commit comments

Comments
 (0)