Skip to content

Commit 02ac35f

Browse files
committed
correct data attribute locators
1 parent eacf563 commit 02ac35f

File tree

3 files changed

+32
-8
lines changed

3 files changed

+32
-8
lines changed

packages/selenium-ide/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@seleniumhq/selenium-ide",
3-
"version": "4.0.0-alpha.35",
3+
"version": "4.0.0-alpha.36",
44
"private": true,
55
"description": "Selenium IDE electron app",
66
"author": "Todd <[email protected]>",

packages/selenium-ide/src/browser/windows/PlaybackWindow/preload/locator-builders.ts

Lines changed: 27 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -286,14 +286,14 @@ export default class LocatorBuilders {
286286
// e.g., 1st listed is top priority
287287

288288
LocatorBuilders.add(
289-
'css:data-attr',
289+
'css:data-test-id',
290290
function (this: LocatorBuilders, e: HTMLElement) {
291-
const dataAttributes = ['data-test', 'data-test-id']
291+
const dataAttributes = ['data-test-id', 'data-test']
292292
for (let i = 0; i < dataAttributes.length; i++) {
293293
const attr = dataAttributes[i]
294294
const value = e.getAttribute(attr)
295-
if (attr) {
296-
return `css=*[${attr}="${value}"]`
295+
if (value) {
296+
return `css=[${attr}="${value}"]`
297297
}
298298
}
299299
return null
@@ -331,6 +331,29 @@ LocatorBuilders.add('name', function (this: LocatorBuilders, _e: HTMLElement) {
331331
return null
332332
})
333333

334+
const dataAttributeFromDatasetProperty = (attr: string) =>
335+
`data-${attr.replace(
336+
/[A-Z]/g,
337+
(letter: string) => `-${letter.toLowerCase()}`
338+
)}`
339+
340+
LocatorBuilders.add(
341+
'css:data-attr',
342+
function (this: LocatorBuilders, e: HTMLElement) {
343+
const dataKeys = Object.keys(e.dataset || {})
344+
if (dataKeys.length) {
345+
const attr = dataKeys[0]
346+
const value = e.dataset[attr]
347+
const htmlAttr = dataAttributeFromDatasetProperty(attr)
348+
if (!value || value === 'true') {
349+
return `css=[${htmlAttr}]`
350+
}
351+
return `css=[${htmlAttr}="${value}"]`
352+
}
353+
return null
354+
}
355+
)
356+
334357
LocatorBuilders.add(
335358
'css:finder',
336359
function (this: LocatorBuilders, e: HTMLElement) {

packages/side-code-export/package.json

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@seleniumhq/side-code-export",
3-
"version": "4.0.0-alpha.2",
3+
"version": "4.0.0-alpha.3",
44
"description": "Utils for code export from Selenium IDE",
55
"repository": "https://github.com/SeleniumHQ/selenium-ide",
66
"keywords": [
@@ -10,8 +10,9 @@
1010
],
1111
"license": "Apache-2.0",
1212
"scripts": {
13-
"build": "babel -d dist src --ignore=__test__",
14-
"watch": "pnpm run build"
13+
"build": "tsc",
14+
"clean": "rm -rf dist tsconfig.tsbuildinfo node_modules",
15+
"watch": "tsc --watch"
1516
},
1617
"bin": {
1718
"side-code-export": "dist/bin.js"

0 commit comments

Comments
 (0)