(locator)
| 4175 | export default Playwright |
| 4176 | |
| 4177 | export function buildLocatorString(locator) { |
| 4178 | if (locator.isXPath()) { |
| 4179 | // Make XPath relative so it works correctly within scoped contexts (e.g. within()). |
| 4180 | // Playwright's XPath engine auto-converts "//..." to ".//..." when the root is not a Document, |
| 4181 | // but only when the selector starts with "/". Locator methods like at() wrap XPath in |
| 4182 | // parentheses (e.g. "(//...)[position()=1]"), bypassing that auto-conversion. |
| 4183 | // We fix this by prepending "." before the first "//" that follows any leading parentheses. |
| 4184 | const value = locator.value.replace(/^(\(*)\/\//, '$1.//') |
| 4185 | return `xpath=${value}` |
| 4186 | } |
| 4187 | if (locator.isShadow()) { |
| 4188 | // Convert shadow locator to CSS with >> chaining operator |
| 4189 | // Playwright pierces shadow DOM by default, >> chains selectors |
| 4190 | // { shadow: ['my-app', 'my-form', 'button'] } => 'my-app >> my-form >> button' |
| 4191 | return locator.value.join(' >> ') |
| 4192 | } |
| 4193 | return locator.simplify() |
| 4194 | } |
| 4195 | |
| 4196 | /** |
| 4197 | * Handles role locator objects by converting them to Playwright's getByRole() API |
no test coverage detected