Skip to content

Commit 053431b

Browse files
Merge pull request #20 from testing-library/fix-firefox
Fix firefox
2 parents 3d87bdd + dede5a8 commit 053431b

File tree

4 files changed

+25
-19
lines changed

4 files changed

+25
-19
lines changed

.github/workflows/webdriverio-testing-library.yml

-6
Original file line numberDiff line numberDiff line change
@@ -15,12 +15,6 @@ jobs:
1515
os: [ubuntu-latest]
1616
node: [12]
1717
steps:
18-
- uses: nanasess/setup-chromedriver@master
19-
with:
20-
chromedriver-version: '79.0.3945.36'
21-
- run: |
22-
export DISPLAY=:99
23-
sudo Xvfb -ac :99 -screen 0 1280x1024x24 > /dev/null 2>&1 & # optional
2418
- uses: actions/setup-node@v1
2519
with:
2620
node-version: ${{ matrix.node }}

package.json

+2-3
Original file line numberDiff line numberDiff line change
@@ -41,16 +41,15 @@
4141
"@wdio/cli": "^7.3.1",
4242
"@wdio/local-runner": "^7.3.1",
4343
"@wdio/mocha-framework": "^7.3.1",
44+
"@wdio/selenium-standalone-service": "^7.7.3",
4445
"@wdio/spec-reporter": "^7.3.1",
4546
"@wdio/sync": "^7.3.1",
46-
"chromedriver": "^91.0.0",
4747
"eslint": "^7.6.0",
4848
"kcd-scripts": "^5.0.0",
4949
"npm-run-all": "^4.1.5",
5050
"semantic-release": "^17.0.2",
5151
"ts-node": "^9.1.1",
52-
"typescript": "^4.1.3",
53-
"wdio-chromedriver-service": "^7.0.0"
52+
"typescript": "^4.1.3"
5453
},
5554
"repository": {
5655
"type": "git",

src/index.ts

+14-1
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,17 @@ async function injectDOMTestingLibrary(container: ElementBase) {
4545
})
4646

4747
if (shouldInject.domTestingLibrary) {
48-
await container.execute(DOM_TESTING_LIBRARY_UMD)
48+
await container.execute(function (library) {
49+
// add DOM Testing Library to page as a script tag to support Firefox
50+
if (navigator.userAgent.indexOf('Firefox') !== -1) {
51+
const script = document.createElement('script')
52+
script.innerHTML = library
53+
return document.head.append(script)
54+
}
55+
56+
// eval library on other browsers
57+
return eval(library)
58+
}, DOM_TESTING_LIBRARY_UMD)
4959
}
5060

5161
if (shouldInject.simmer) {
@@ -109,6 +119,9 @@ function executeQuery(
109119
;(async () => {
110120
let result: undefined | null | HTMLElement | HTMLElement[]
111121
try {
122+
// Override RegExp to fix 'matcher instanceof RegExp' check on Firefox
123+
window.RegExp = RegExp
124+
112125
result = await window.TestingLibraryDom[query](
113126
container,
114127
matcher,

wdio.conf.js

+9-9
Original file line numberDiff line numberDiff line change
@@ -54,21 +54,21 @@ exports.config = {
5454
//
5555
capabilities: [
5656
{
57-
// maxInstances can get overwritten per capability. So if you have an in-house Selenium
58-
// grid with only 5 firefox instances available you can make sure that not more than
59-
// 5 instances get started at a time.
6057
maxInstances: 5,
61-
//
6258
browserName: 'chrome',
6359
acceptInsecureCerts: true,
64-
// If outputDir is provided WebdriverIO can capture driver session logs
65-
// it is possible to configure which logTypes to include/exclude.
66-
// excludeDriverLogs: ['*'], // pass '*' to exclude all driver session logs
67-
// excludeDriverLogs: ['bugreport', 'server'],
6860
'goog:chromeOptions': {
6961
args: process.env.CI ? ['--headless'] : [],
7062
},
7163
},
64+
{
65+
maxInstances: 5,
66+
browserName: 'firefox',
67+
acceptInsecureCerts: true,
68+
'moz:firefoxOptions': {
69+
args: process.env.CI ? ['--headless'] : [],
70+
},
71+
},
7272
],
7373
//
7474
// ===================
@@ -117,7 +117,7 @@ exports.config = {
117117
// Services take over a specific job you don't want to take care of. They enhance
118118
// your test setup with almost no effort. Unlike plugins, they don't add new
119119
// commands. Instead, they hook themselves up into the test process.
120-
services: ['chromedriver'],
120+
services: [['selenium-standalone', {drivers: {firefox: true, chrome: true}}]],
121121

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

0 commit comments

Comments
 (0)