Skip to content

Commit 59c7b25

Browse files
DavertMikclaude
andcommitted
feat: exact: false cancels strict mode per-step
When helper has strict: true, step.opts({ exact: false }) overrides it for that step, allowing multiple element matches without error. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
1 parent 9116dd2 commit 59c7b25

3 files changed

Lines changed: 10 additions & 1 deletion

File tree

lib/helper/Playwright.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4286,7 +4286,8 @@ async function proceedClick(locator, context = null, options = {}) {
42864286
if (opts?.elementIndex != null) {
42874287
element = selectElement(els, locator, this)
42884288
} else {
4289-
if (this.options.strict || opts?.exact === true || opts?.strictMode === true) assertOnlyOneElement(els, locator, this)
4289+
const strict = (opts?.exact === false || opts?.strictMode === false) ? false : (this.options.strict || opts?.exact === true || opts?.strictMode === true)
4290+
if (strict) assertOnlyOneElement(els, locator, this)
42904291
element = els.length > 1 ? (await getVisibleElements(els))[0] : els[0]
42914292
}
42924293

lib/helper/extras/elementSelection.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ function resolveElementIndex(value) {
1111

1212
function isStrictStep(opts, helper) {
1313
if (opts?.exact === true || opts?.strictMode === true) return true
14+
if (opts?.exact === false || opts?.strictMode === false) return false
1415
return helper.options.strict
1516
}
1617

test/helper/webapi.js

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2420,5 +2420,12 @@ export function tests() {
24202420
store.currentStep = { opts: { exact: true } }
24212421
await I.click('#first-link')
24222422
})
2423+
2424+
it('should cancel strict mode with exact: false', async () => {
2425+
await I.amOnPage('/info')
2426+
I.options.strict = true
2427+
store.currentStep = { opts: { exact: false } }
2428+
await I.click('#grab-multiple a')
2429+
})
24232430
})
24242431
}

0 commit comments

Comments
 (0)