feat: strict mode for all helpers + improved MultipleElementsFound error#5491
Merged
feat: strict mode for all helpers + improved MultipleElementsFound error#5491
Conversation
…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>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
strictmode support to Puppeteer and WebDriver helpers (previously Playwright-only)MultipleElementsFounderror to useWebElement[]with detailed asyncfetchDetails()showing absolute XPath + minified outerHTML per elementtoAbsoluteXPath()andtoOuterHTML()methods toWebElementclass (works across all 3 helpers)fetchDetails()in CLI error display (lib/mocha/cli.js)[object Object]bug in error message when using object locatorstest/helper/webapi.js(4 tests, verified passing for Playwright and Puppeteer)Test plan
npx mocha test/helper/Playwright_test.js --grep "strict mode")npx mocha test/helper/Puppeteer_test.js --grep "strict mode")🤖 Generated with Claude Code