diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index 12e5f35a..a3af087c 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -10,40 +10,56 @@ on: workflow_dispatch: jobs: - browser: - name: Test Browser + browser-macos: + name: Test Browser on macOS runs-on: macos-latest env: GITHUB_ACTIONS_OUTPUT: "" strategy: fail-fast: false matrix: - browser: [chrome, firefox, safari] + browser: [safari] suite: [default, disabled, main] steps: - - name: Extract Week Number - run: echo "WEEK_NUMBER=$(date +%W)" >> $GITHUB_ENV - - - name: Install Firefox - if: ${{ matrix.browser == 'firefox' }} - run: brew install --cask firefox - - name: Checkout Branch + - &checkout-branch + name: Checkout Branch uses: actions/checkout@v5 - - name: Setup Node + - &setup-node + name: Setup Node uses: actions/setup-node@v5 with: node-version-file: package.json cache: npm - - name: Install Node Packages + - &install-node-packages + name: Install Node Packages run: npm ci - name: Run Tests run: | echo "Running in $BROWSER" npm run test:${{ matrix.browser }} -- ${{ matrix.suite }} + + browser-linux: + name: Test Browser on Linux + runs-on: ubuntu-latest + env: + GITHUB_ACTIONS_OUTPUT: "" + strategy: + fail-fast: false + matrix: + browser: [chrome, firefox] + suite: [default, disabled, main] + steps: + - *checkout-branch + - *setup-node + - *install-node-packages + - name: Run Tests + run: | + echo "Running in $BROWSER" + npm run test:${{ matrix.browser }} -- ${{ matrix.suite }} shell: name: Test Shell runs-on: ubuntu-latest @@ -55,21 +71,13 @@ jobs: shell: [jsc, spidermonkey, v8] suite: [default, disabled, main] steps: + - *checkout-branch + - *setup-node + - *install-node-packages + - name: Extract Week Number run: echo "WEEK_NUMBER=$(date +%W)" >> $GITHUB_ENV - - name: Checkout Branch - uses: actions/checkout@v5 - - - name: Setup Node - uses: actions/setup-node@v5 - with: - node-version-file: package.json - cache: npm - - - name: Install Node Packages - run: npm ci - - name: Cache jsvu Binaries uses: actions/cache@v4 with: @@ -89,14 +97,8 @@ jobs: with: fetch-depth: ${{ github.event_name == 'pull_request' && 2 || 0 }} - - name: Setup Node - uses: actions/setup-node@v4 - with: - node-version-file: package.json - cache: npm - - - name: Install Node Packages - run: npm ci + - *setup-node + - *install-node-packages - name: Run Build run: | diff --git a/tests/run-browser.mjs b/tests/run-browser.mjs index 92caadb0..44cc825a 100644 --- a/tests/run-browser.mjs +++ b/tests/run-browser.mjs @@ -26,6 +26,8 @@ import serve from "./server.mjs"; import { Builder, Capabilities, logging } from "selenium-webdriver"; +import { Options as ChromeOptions } from "selenium-webdriver/chrome.js"; +import { Options as FirefoxOptions } from "selenium-webdriver/firefox.js"; import commandLineArgs from "command-line-args"; import { promises as fs } from "fs"; import path from "path"; @@ -95,8 +97,10 @@ if (options.suite && !VALID_TAGS.includes(options.suite)) const BROWSER = options?.browser; if (!BROWSER) printHelp("No browser specified, use $BROWSER or --browser", optionDefinitions); +const IS_HEADLESS = os.platform() === "linux" && !process.env.DISPLAY; let capabilities; +let browserOptions; switch (BROWSER) { case "safari": capabilities = Capabilities.safari(); @@ -104,11 +108,19 @@ switch (BROWSER) { break; case "firefox": { - capabilities = Capabilities.firefox(); + capabilities = Capabilities.firefox() + if (IS_HEADLESS) { + browserOptions = new FirefoxOptions(); + browserOptions.addArguments("-headless"); + } break; } case "chrome": { - capabilities = Capabilities.chrome(); + capabilities = Capabilities.chrome() + if (IS_HEADLESS) { + browserOptions = new ChromeOptions(); + browserOptions.addArguments("--headless"); + } break; } case "edge": { @@ -159,7 +171,20 @@ async function runEnd2EndTest(name, params) { } async function testEnd2End(params) { - const driver = await new Builder().withCapabilities(capabilities).build(); + const builder = new Builder().withCapabilities(capabilities); + if (browserOptions) { + switch(BROWSER) { + case "firefox": + builder.setFirefoxOptions(browserOptions); + break; + case "chrome": + builder.setChromeOptions(browserOptions); + break; + default: + break; + } + } + const driver = await builder.build(); const sessionId = (await driver.getSession()).getId(); const driverCapabilities = await driver.getCapabilities(); logInfo(`Browser: ${driverCapabilities.getBrowserName()} ${driverCapabilities.getBrowserVersion()}`);