Skip to content

Commit c2d7914

Browse files
authored
Aria selector slowness (#517)
* add stackoverflow * update wdio.conf.js * add puppeteer * tidy up * setup browser adaptable conf * fix puppeteer * update package.json * npm uninstall puppeteer * add files * browser choice * package changes * move files * increase timeout * fix tests * Revert "increase timeout" This reverts commit 21828ed. * Remove deprecated calls to switchToFrame * Revert "Remove deprecated calls to switchToFrame" This reverts commit db8f48f. * update package.json
1 parent 0585690 commit c2d7914

8 files changed

Lines changed: 3310 additions & 74 deletions

File tree

.github/workflows/test.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ jobs:
1616
- queryElements
1717
- overwriteCommand
1818
- selectors
19+
- selectorsAria
1920
- getting-started
2021
- setup
2122
- testDownloadBehavior

.gitignore

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -105,4 +105,4 @@ dist
105105

106106
*.png
107107

108-
testDownloadBehavior/package.json
108+
downloads/package.json

package.json

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -28,9 +28,9 @@
2828
"customMatchers": "cross-env TS_NODE_PROJECT=./customMatchers/tsconfig.json EXAMPLE_RECIPE=customMatchers wdio run ./wdio.conf.js --spec ./customMatchers/example.ts",
2929
"deleteCookies": "cross-env EXAMPLE_RECIPE=deleteCookies wdio run ./wdio.conf.js --spec ./deleteCookies/example.js",
3030
"testDownloadBehavior": "run-s testDownload:*",
31-
"testDownload:chrome": "cross-env BROWSER=chrome wdio run ./testDownloadBehavior/wdio.conf.js --spec ./testDownloadBehavior/example.js",
32-
"testDownload:firefox": "cross-env BROWSER=firefox wdio run ./testDownloadBehavior/wdio.conf.js --spec ./testDownloadBehavior/example.js",
33-
"testDownload:edge": "cross-env BROWSER=edge wdio run ./testDownloadBehavior/wdio.conf.js --spec ./testDownloadBehavior/example.js",
31+
"testDownload:chrome": "cross-env BROWSER=chrome wdio run ./wdio.browserChoice.conf.js --spec ./testDownloadBehavior/example.js",
32+
"testDownload:firefox": "cross-env BROWSER=firefox wdio run ./wdio.browserChoice.conf.js --spec ./testDownloadBehavior/example.js",
33+
"testDownload:edge": "cross-env BROWSER=edge wdio run ./wdio.browserChoice.conf.js --spec ./testDownloadBehavior/example.js",
3434
"emulate": "cross-env EXAMPLE_RECIPE=emulate wdio run ./wdio.conf.js --spec ./emulate/example.js",
3535
"getting-started": "node ./getting-started/run-in-script.js",
3636
"keys": "cross-env EXAMPLE_RECIPE=keys wdio run ./wdio.conf.js --spec ./keys/keys.js",
@@ -56,6 +56,9 @@
5656
"selectors:ariaRole": "cross-env EXAMPLE_RECIPE=selectors wdio run ./wdio.conf.js --spec ./selectors/example.js --mochaOpts.grep 'by role attribute'",
5757
"selectors:js": "cross-env EXAMPLE_RECIPE=selectors wdio run ./wdio.conf.js --spec ./selectors/example.js --mochaOpts.grep 'js function'",
5858
"selectors:deep": "cross-env EXAMPLE_RECIPE=selectors wdio run ./wdio.conf.js --spec ./selectors/example.js --mochaOpts.grep 'deep selector'",
59+
"selectorsAria": "run-s selectorsAria:*",
60+
"selectorsAria:chrome": "cross-env EXAMPLE_RECIPE=selectorsAria BROWSER=chrome wdio run ./wdio.browserChoice.conf.js --spec ./selectorsAria/example.js --mochaOpts.timeout 90000",
61+
"selectorsAria:firefox": "cross-env EXAMPLE_RECIPE=selectorsAria BROWSER=firefox wdio run ./wdio.browserChoice.conf.js --spec ./selectorsAria/example.js --mochaOpts.timeout 90000",
5962
"setup": "run-s setup:*",
6063
"setup:webdriver": "node ./setup/webdriver.js",
6164
"setup:devtools": "node ./setup/devtools.js",

selectorsAria/example.js

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
import { browser, expect } from '@wdio/globals'
2+
3+
describe('ARIA example on a larger page', () => {
4+
before(() => browser.url('/stackoverflow.html'))
5+
6+
it('aria query for span=questions', async () => {
7+
const el = await browser.$('aria/Questions')
8+
const html = await el.getHTML()
9+
expect(html).toBe('<span class="-link--channel-name pl8">Questions</span>')
10+
})
11+
12+
it('aria query for button=Accept all cookies', async () => {
13+
const el = await browser.$('aria/Accept all cookies')
14+
const html = await el.getHTML()
15+
expect(html).toBe('<button id="onetrust-accept-btn-handler">Accept all cookies</button>')
16+
})
17+
})

selectorsAria/stackoverflow.html

Lines changed: 3201 additions & 0 deletions
Large diffs are not rendered by default.

testDownloadBehavior/helper.js

Lines changed: 2 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,8 @@
11
import fs from "fs"
2-
import path from "path"
3-
import {fileURLToPath} from "url"
4-
5-
const __filename = fileURLToPath(import.meta.url)
6-
7-
// Ensure that the download directory specified here
8-
// matches the directory you've set in capabilities.
9-
const downloadDirectory = path.dirname(__filename)
2+
import { downloadsDir } from "../wdio.browserChoice.conf"
103

114
const expectedFileName = "package.json"
12-
const filePath = `${downloadDirectory}/${expectedFileName}`
5+
const filePath = `${downloadsDir}/${expectedFileName}`
136

147
const deleteFileIfExists = () => {
158
try {

testDownloadBehavior/wdio.conf.js

Lines changed: 0 additions & 61 deletions
This file was deleted.

wdio.browserChoice.conf.js

Lines changed: 82 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,82 @@
1+
import path from 'path'
2+
import { fileURLToPath } from 'url'
3+
import fs from 'fs'
4+
import { config as baseConfig } from './wdio.conf.js'
5+
6+
// Create downloads directory if it doesn't exist
7+
export const downloadsDir = path.join(path.dirname(fileURLToPath(import.meta.url)), 'downloads')
8+
if (!fs.existsSync(downloadsDir)){
9+
fs.mkdirSync(downloadsDir);
10+
}
11+
12+
// Get custom Firefox binary path from environment variable if set
13+
const { FIREFOX_BINARY_PATH } = process.env
14+
15+
const chromeOptions = {
16+
capabilities: {
17+
browserName: 'chrome',
18+
"goog:chromeOptions": {
19+
args: process.env.CI ? ['headless', 'disable-gpu'] : ['disable-gpu'],
20+
prefs: {
21+
"download.default_directory": downloadsDir
22+
}
23+
}
24+
}
25+
}
26+
27+
const firefoxOptions = {
28+
capabilities: {
29+
browserName: 'firefox',
30+
"moz:debuggerAddress": true,
31+
"moz:firefoxOptions": {
32+
args: process.env.CI ? ['-headless'] : [],
33+
prefs: {
34+
"browser.download.dir": downloadsDir,
35+
"browser.download.folderList": 2,
36+
"browser.download.manager.showWhenStarting": false,
37+
"browser.helperApps.neverAsk.saveToDisk": "*/*"
38+
}
39+
}
40+
}
41+
}
42+
43+
// Set custom Firefox binary path if provided, e.g., for using Nightly or a specific version
44+
if (FIREFOX_BINARY_PATH) {
45+
firefoxOptions.capabilities['moz:firefoxOptions'].binary = FIREFOX_BINARY_PATH;
46+
}
47+
48+
const edgeOptions = {
49+
capabilities: {
50+
browserName: 'edge',
51+
"ms:edgeOptions": {
52+
args: process.env.CI ? ['--headless'] : [],
53+
prefs: {
54+
"download.default_directory": downloadsDir
55+
}
56+
}
57+
}
58+
}
59+
60+
const safariOptions = {
61+
capabilities: {
62+
browserName: 'safari'
63+
}
64+
}
65+
66+
const browserCapabilities = {
67+
chrome: chromeOptions.capabilities,
68+
firefox: firefoxOptions.capabilities,
69+
edge: edgeOptions.capabilities,
70+
safari: safariOptions.capabilities
71+
}
72+
73+
const capabilities = [
74+
process.env.BROWSER && browserCapabilities[process.env.BROWSER]
75+
? browserCapabilities[process.env.BROWSER]
76+
: browserCapabilities['chrome']
77+
]
78+
79+
export const config = {
80+
...baseConfig,
81+
capabilities
82+
}

0 commit comments

Comments
 (0)