Skip to content

Commit

Permalink
Merge pull request #20 from testing-library/fix-firefox
Browse files Browse the repository at this point in the history
Fix firefox
  • Loading branch information
olivierwilkinson authored Jun 15, 2021
2 parents 3d87bdd + dede5a8 commit 053431b
Show file tree
Hide file tree
Showing 4 changed files with 25 additions and 19 deletions.
6 changes: 0 additions & 6 deletions .github/workflows/webdriverio-testing-library.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,12 +15,6 @@ jobs:
os: [ubuntu-latest]
node: [12]
steps:
- uses: nanasess/setup-chromedriver@master
with:
chromedriver-version: '79.0.3945.36'
- run: |
export DISPLAY=:99
sudo Xvfb -ac :99 -screen 0 1280x1024x24 > /dev/null 2>&1 & # optional
- uses: actions/setup-node@v1
with:
node-version: ${{ matrix.node }}
Expand Down
5 changes: 2 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -41,16 +41,15 @@
"@wdio/cli": "^7.3.1",
"@wdio/local-runner": "^7.3.1",
"@wdio/mocha-framework": "^7.3.1",
"@wdio/selenium-standalone-service": "^7.7.3",
"@wdio/spec-reporter": "^7.3.1",
"@wdio/sync": "^7.3.1",
"chromedriver": "^91.0.0",
"eslint": "^7.6.0",
"kcd-scripts": "^5.0.0",
"npm-run-all": "^4.1.5",
"semantic-release": "^17.0.2",
"ts-node": "^9.1.1",
"typescript": "^4.1.3",
"wdio-chromedriver-service": "^7.0.0"
"typescript": "^4.1.3"
},
"repository": {
"type": "git",
Expand Down
15 changes: 14 additions & 1 deletion src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,17 @@ async function injectDOMTestingLibrary(container: ElementBase) {
})

if (shouldInject.domTestingLibrary) {
await container.execute(DOM_TESTING_LIBRARY_UMD)
await container.execute(function (library) {
// add DOM Testing Library to page as a script tag to support Firefox
if (navigator.userAgent.indexOf('Firefox') !== -1) {
const script = document.createElement('script')
script.innerHTML = library
return document.head.append(script)
}

// eval library on other browsers
return eval(library)
}, DOM_TESTING_LIBRARY_UMD)
}

if (shouldInject.simmer) {
Expand Down Expand Up @@ -109,6 +119,9 @@ function executeQuery(
;(async () => {
let result: undefined | null | HTMLElement | HTMLElement[]
try {
// Override RegExp to fix 'matcher instanceof RegExp' check on Firefox
window.RegExp = RegExp

result = await window.TestingLibraryDom[query](
container,
matcher,
Expand Down
18 changes: 9 additions & 9 deletions wdio.conf.js
Original file line number Diff line number Diff line change
Expand Up @@ -54,21 +54,21 @@ exports.config = {
//
capabilities: [
{
// maxInstances can get overwritten per capability. So if you have an in-house Selenium
// grid with only 5 firefox instances available you can make sure that not more than
// 5 instances get started at a time.
maxInstances: 5,
//
browserName: 'chrome',
acceptInsecureCerts: true,
// If outputDir is provided WebdriverIO can capture driver session logs
// it is possible to configure which logTypes to include/exclude.
// excludeDriverLogs: ['*'], // pass '*' to exclude all driver session logs
// excludeDriverLogs: ['bugreport', 'server'],
'goog:chromeOptions': {
args: process.env.CI ? ['--headless'] : [],
},
},
{
maxInstances: 5,
browserName: 'firefox',
acceptInsecureCerts: true,
'moz:firefoxOptions': {
args: process.env.CI ? ['--headless'] : [],
},
},
],
//
// ===================
Expand Down Expand Up @@ -117,7 +117,7 @@ exports.config = {
// Services take over a specific job you don't want to take care of. They enhance
// your test setup with almost no effort. Unlike plugins, they don't add new
// commands. Instead, they hook themselves up into the test process.
services: ['chromedriver'],
services: [['selenium-standalone', {drivers: {firefox: true, chrome: true}}]],

// Framework you want to run your specs with.
// The following are supported: Mocha, Jasmine, and Cucumber
Expand Down

0 comments on commit 053431b

Please sign in to comment.