Skip to content

feat: strict mode for all helpers + improved MultipleElementsFound error#5491

Merged
DavertMik merged 3 commits into4.xfrom
feat/strict-mode-all-helpers
Mar 17, 2026
Merged

feat: strict mode for all helpers + improved MultipleElementsFound error#5491
DavertMik merged 3 commits into4.xfrom
feat/strict-mode-all-helpers

Conversation

@DavertMik
Copy link
Contributor

Summary

  • Add strict mode support to Puppeteer and WebDriver helpers (previously Playwright-only)
  • Refactor MultipleElementsFound error to use WebElement[] with detailed async fetchDetails() showing absolute XPath + minified outerHTML per element
  • Add toAbsoluteXPath() and toOuterHTML() methods to WebElement class (works across all 3 helpers)
  • Auto-call fetchDetails() in CLI error display (lib/mocha/cli.js)
  • Fix [object Object] bug in error message when using object locators
  • Add shared strict mode tests in test/helper/webapi.js (4 tests, verified passing for Playwright and Puppeteer)

Test plan

  • Strict mode tests pass for Playwright (npx mocha test/helper/Playwright_test.js --grep "strict mode")
  • Strict mode tests pass for Puppeteer (npx mocha test/helper/Puppeteer_test.js --grep "strict mode")
  • Existing click/fillField/clearField tests still pass for both helpers
  • WebDriver strict mode tests (requires Selenium server)

🤖 Generated with Claude Code

DavertMik and others added 3 commits March 17, 2026 03:24
…helpers

Add strict mode support to Puppeteer and WebDriver helpers (previously only
Playwright). When `strict: true`, single-element operations (click, fillField,
etc.) throw MultipleElementsFound if more than one element matches.

Refactor MultipleElementsFound to use WebElement[] with async fetchDetails()
that shows absolute XPath and minified outerHTML for each matched element.
Add toAbsoluteXPath() and toOuterHTML() to WebElement class. Auto-call
fetchDetails() in CLI error display.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
…fiedHTML to WebElement

Move HTML simplification logic (removeNonInteractiveElements + unwrap + truncate)
into a reusable simplifyHtmlElement() function in lib/html.js. Add toSimplifiedHTML()
method to WebElement that combines toOuterHTML() with simplifyHtmlElement().
MultipleElementsFound.fetchDetails() now uses webEl.toSimplifiedHTML() directly.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
…nd fix HTML unwrap regex

WebdriverIO $$ returns a special collection, not a plain array. Using
Array.from() before .map() ensures WebElement[] is a real array with .length.
Also fix simplifyHtmlElement regex to handle cases where <head> tag is absent
in the parse5 output.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
@DavertMik DavertMik merged commit 9c9f5b6 into 4.x Mar 17, 2026
10 of 11 checks passed
@DavertMik DavertMik deleted the feat/strict-mode-all-helpers branch March 17, 2026 02:33
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant