codeceptjs 4.0.1-beta.22 → 4.0.1-beta.23
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/lib/helper/Playwright.js +6 -24
- package/lib/locator.js +14 -1
- package/package.json +1 -1
package/lib/helper/Playwright.js
CHANGED
|
@@ -4505,32 +4505,14 @@ async function proceedClick(locator, context = null, options = {}) {
|
|
|
4505
4505
|
}
|
|
4506
4506
|
|
|
4507
4507
|
async function findClickable(matcher, locator) {
|
|
4508
|
-
|
|
4509
|
-
|
|
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)
|
|
4515
4510
|
|
|
4516
|
-
|
|
4511
|
+
locator = new Locator(locator)
|
|
4512
|
+
if (!locator.isFuzzy()) return findElements.call(this, matcher, locator)
|
|
4517
4513
|
|
|
4518
4514
|
let els
|
|
4519
|
-
const literal = xpathLocator.literal(
|
|
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)
|
|
4534
4516
|
|
|
4535
4517
|
els = await findElements.call(this, matcher, Locator.clickable.narrow(literal))
|
|
4536
4518
|
if (els.length) return els
|
|
@@ -4545,7 +4527,7 @@ async function findClickable(matcher, locator) {
|
|
|
4545
4527
|
// Do nothing
|
|
4546
4528
|
}
|
|
4547
4529
|
|
|
4548
|
-
return findElements.call(this, matcher,
|
|
4530
|
+
return findElements.call(this, matcher, locator.value) // by css or xpath
|
|
4549
4531
|
}
|
|
4550
4532
|
|
|
4551
4533
|
async function proceedSee(assertType, text, context, strict = false) {
|
package/lib/locator.js
CHANGED
|
@@ -6,6 +6,9 @@ const require = createRequire(import.meta.url)
|
|
|
6
6
|
let cssToXPath
|
|
7
7
|
|
|
8
8
|
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']
|
|
9
12
|
/** @class */
|
|
10
13
|
class Locator {
|
|
11
14
|
/**
|
|
@@ -114,6 +117,16 @@ class Locator {
|
|
|
114
117
|
this.locator = locator
|
|
115
118
|
const keys = Object.keys(locator)
|
|
116
119
|
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
|
+
|
|
117
130
|
this.type = type
|
|
118
131
|
this.value = keys.length > 1 ? locator : locator[type]
|
|
119
132
|
Locator.filters.forEach(f => f(locator, this))
|
|
@@ -500,7 +513,7 @@ Locator.clickable = {
|
|
|
500
513
|
`.//*[@aria-label = ${literal}]`,
|
|
501
514
|
`.//*[@title = ${literal}]`,
|
|
502
515
|
`.//*[@aria-labelledby = //*[@id][normalize-space(string(.)) = ${literal}]/@id ]`,
|
|
503
|
-
`.//*[@role='link'
|
|
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}]`,
|
|
504
517
|
]),
|
|
505
518
|
|
|
506
519
|
/**
|