Skip to content

Commit

Permalink
tests: automatically sync chrome and chromedriver versions
Browse files Browse the repository at this point in the history
  • Loading branch information
redJ4y committed Aug 19, 2024
1 parent ba40117 commit 4228e2e
Show file tree
Hide file tree
Showing 2 changed files with 51 additions and 6 deletions.
16 changes: 15 additions & 1 deletion .github/workflows/tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,13 +13,27 @@ jobs:

steps:
- uses: actions/checkout@v3

- name: Use Node.js 20.x
uses: actions/setup-node@v3
with:
node-version: 20.x
- uses: browser-actions/setup-chrome@latest

- name: Setup Chrome
id: setup-chrome
uses: browser-actions/setup-chrome@latest
with:
chrome-version: latest
install-chromedriver: true

- name: Set Chrome and ChromeDriver paths
run: |
echo "CHROME_BIN=${{ steps.setup-chrome.outputs.chrome-path }}" >> $GITHUB_ENV
echo "CHROMEDRIVER_PATH=${{ steps.setup-chrome.outputs.chromedriver-path }}" >> $GITHUB_ENV
- run: npm ci
- run: npx grunt
- run: npm test
env:
CHROME_BIN: ${{ env.CHROME_BIN }}
CHROMEDRIVER_PATH: ${{ env.CHROMEDRIVER_PATH }}
41 changes: 36 additions & 5 deletions wdio.conf.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,24 @@
const fs = require('fs');
const path = require('path');

const chromeDriverExists = (path) => {
return fs.existsSync(path);
};

const githubActionsChromeDriver = process.env.CHROMEDRIVER_PATH;
const localChromeDriver = path.join(__dirname, 'node_modules', 'chromedriver', 'bin', 'chromedriver');

// If we are on a Continuous Integration server, use the ChromeDriver installed by browser-actions/setup-chrome.
// Otherwise, use the ChromeDriver installed as a devDependency.
let chromeDriverPath;
if (githubActionsChromeDriver && chromeDriverExists(githubActionsChromeDriver)) {
chromeDriverPath = githubActionsChromeDriver;
} else if (chromeDriverExists(localChromeDriver)) {
chromeDriverPath = localChromeDriver;
} else {
console.warn('ChromeDriver not found in expected locations. Using default.');
}

exports.config = {
//
// ====================
Expand Down Expand Up @@ -48,9 +69,16 @@ exports.config = {
capabilities: [{
maxInstances: 4,
browserName: 'chrome',
'goog:chromeOptions': {
args: ['headless', 'disable-gpu', 'no-sandbox']
},
'goog:chromeOptions': (function() {
const options = {
args: ['headless', 'disable-gpu', 'no-sandbox'],
};
// Use the CHROME_BIN environment variable if present.
if (process.env.CHROME_BIN) {
options.binary = process.env.CHROME_BIN;
}
return options;
})(),
}],
//
// ===================
Expand Down Expand Up @@ -112,8 +140,11 @@ exports.config = {
{ mount: '/fixtures', path: './tests/fixtures' },
{ mount: '/dist', path: './dist' },
]
}
], 'chromedriver'],
}],
['chromedriver', {
chromedriverCustomPath: chromeDriverPath
}]
],
chromeDriverArgs: ['--headless', '--disable-gpu'],

// Framework you want to run your specs with.
Expand Down

0 comments on commit 4228e2e

Please sign in to comment.