Skip to content

Commit 493df00

Browse files
author
DavertMik
committed
Reverted clickable in Playwright
1 parent 7d1791d commit 493df00

File tree

3 files changed

+21
-26
lines changed

3 files changed

+21
-26
lines changed

lib/helper/Playwright.js

Lines changed: 6 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -4505,32 +4505,14 @@ async function proceedClick(locator, context = null, options = {}) {
45054505
}
45064506

45074507
async function findClickable(matcher, locator) {
4508-
// Convert to Locator first to handle JSON strings properly
4509-
const matchedLocator = new Locator(locator)
4510-
4511-
// Handle role locators from Locator
4512-
if (matchedLocator.isRole()) {
4513-
return findByRole(matcher, matchedLocator)
4514-
}
4508+
if (locator.react) return findReact(matcher, locator)
4509+
if (locator.vue) return findVue(matcher, locator)
45154510

4516-
if (!matchedLocator.isFuzzy()) return findElements.call(this, matcher, matchedLocator)
4511+
locator = new Locator(locator)
4512+
if (!locator.isFuzzy()) return findElements.call(this, matcher, locator)
45174513

45184514
let els
4519-
const literal = xpathLocator.literal(matchedLocator.value)
4520-
4521-
try {
4522-
els = await matcher.getByRole('button', { name: matchedLocator.value }).all()
4523-
if (els.length) return els
4524-
} catch (err) {
4525-
// getByRole not supported or failed
4526-
}
4527-
4528-
try {
4529-
els = await matcher.getByRole('link', { name: matchedLocator.value }).all()
4530-
if (els.length) return els
4531-
} catch (err) {
4532-
// getByRole not supported or failed
4533-
}
4515+
const literal = xpathLocator.literal(locator.value)
45344516

45354517
els = await findElements.call(this, matcher, Locator.clickable.narrow(literal))
45364518
if (els.length) return els
@@ -4545,7 +4527,7 @@ async function findClickable(matcher, locator) {
45454527
// Do nothing
45464528
}
45474529

4548-
return findElements.call(this, matcher, matchedLocator.value) // by css or xpath
4530+
return findElements.call(this, matcher, locator.value) // by css or xpath
45494531
}
45504532

45514533
async function proceedSee(assertType, text, context, strict = false) {

lib/locator.js

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,9 @@ const require = createRequire(import.meta.url)
66
let cssToXPath
77

88
const locatorTypes = ['css', 'by', 'xpath', 'id', 'name', 'fuzzy', 'frame', 'shadow', 'role']
9+
10+
// Roles that can be used as shorthand locators: { button: 'text' } -> { role: 'button', text: 'text' }
11+
const shorthandRoles = ['button', 'link', 'textbox', 'checkbox', 'radio', 'combobox', 'listbox', 'heading', 'listitem', 'menuitem', 'tab', 'option', 'searchbox', 'alert', 'dialog']
912
/** @class */
1013
class Locator {
1114
/**
@@ -114,6 +117,16 @@ class Locator {
114117
this.locator = locator
115118
const keys = Object.keys(locator)
116119
const [type] = keys
120+
121+
// Transform shorthand role locators: { button: 'text' } -> { role: 'button', text: 'text' }
122+
if (keys.length === 1 && shorthandRoles.includes(type)) {
123+
this.locator = { role: type, text: locator[type] }
124+
this.type = 'role'
125+
this.value = this.locator
126+
Locator.filters.forEach(f => f(this.locator, this))
127+
return
128+
}
129+
117130
this.type = type
118131
this.value = keys.length > 1 ? locator : locator[type]
119132
Locator.filters.forEach(f => f(locator, this))
@@ -500,7 +513,7 @@ Locator.clickable = {
500513
`.//*[@aria-label = ${literal}]`,
501514
`.//*[@title = ${literal}]`,
502515
`.//*[@aria-labelledby = //*[@id][normalize-space(string(.)) = ${literal}]/@id ]`,
503-
`.//*[@role='button'][normalize-space(.)=${literal}]`,
516+
`.//*[@role='button' or @role='link' or @role='tab' or @role='menuitem' or @role='menuitemcheckbox' or @role='menuitemradio' or @role='option' or @role='radio' or @role='checkbox' or @role='switch' or @role='treeitem' or @role='gridcell' or @role='columnheader' or @role='rowheader' or @role='scrollbar' or @role='slider' or @role='spinbutton'][normalize-space(.)=${literal}]`,
504517
]),
505518

506519
/**

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "codeceptjs",
3-
"version": "4.0.1-beta.21",
3+
"version": "4.0.1-beta.23",
44
"type": "module",
55
"description": "Supercharged End 2 End Testing Framework for NodeJS",
66
"keywords": [

0 commit comments

Comments
 (0)