| 27 | import { __INTERNAL } from 'vitest/internal/browser' |
| 28 | |
| 29 | class WebdriverIOLocator extends Locator { |
| 30 | constructor(protected _pwSelector: string, protected _container?: Element) { |
| 31 | super() |
| 32 | } |
| 33 | |
| 34 | // This exists to avoid calling `this.elements` in `this.selector`'s getter in interactive actions |
| 35 | private withElement(element: Element, error: Error | undefined) { |
| 36 | const pwSelector = selectorEngine.generateSelectorSimple(element) |
| 37 | const cssSelector = convertElementToCssSelector(element) |
| 38 | return new ElementWebdriverIOLocator(cssSelector, error, pwSelector, element) |
| 39 | } |
| 40 | |
| 41 | override get selector(): string { |
| 42 | const selectors = this.elements().map(element => convertElementToCssSelector(element)) |
| 43 | if (!selectors.length) { |
| 44 | throw utils.getElementError(this._pwSelector, this._container || document.body) |
| 45 | } |
| 46 | let hasShadowRoot = false |
| 47 | const newSelectors = selectors.map((selector) => { |
| 48 | if (selector.startsWith('>>>')) { |
| 49 | hasShadowRoot = true |
| 50 | return selector.slice(3) |
| 51 | } |
| 52 | return selector |
| 53 | }) |
| 54 | return (hasShadowRoot ? '>>>' : '') + newSelectors.join(', ') |
| 55 | } |
| 56 | |
| 57 | public override click(options?: UserEventClickOptions): Promise<void> { |
| 58 | return ensureAwaited(async (error) => { |
| 59 | const element = await this.findElement(options) |
| 60 | return this.withElement(element, error).click(processClickOptions(options)) |
| 61 | }) |
| 62 | } |
| 63 | |
| 64 | public override dblClick(options?: UserEventClickOptions): Promise<void> { |
| 65 | return ensureAwaited(async (error) => { |
| 66 | const element = await this.findElement(options) |
| 67 | return this.withElement(element, error).dblClick(processClickOptions(options)) |
| 68 | }) |
| 69 | } |
| 70 | |
| 71 | public override tripleClick(options?: UserEventClickOptions): Promise<void> { |
| 72 | return ensureAwaited(async (error) => { |
| 73 | const element = await this.findElement(options) |
| 74 | return this.withElement(element, error).tripleClick(processClickOptions(options)) |
| 75 | }) |
| 76 | } |
| 77 | |
| 78 | public selectOptions( |
| 79 | value: HTMLElement | HTMLElement[] | Locator | Locator[] | string | string[], |
| 80 | options?: UserEventSelectOptions, |
| 81 | ): Promise<void> { |
| 82 | return ensureAwaited(async (error) => { |
| 83 | const element = await this.findElement(options) |
| 84 | const values = getWebdriverioSelectOptions(element, value) |
| 85 | return triggerCommandWithTrace<void>({ |
| 86 | name: '__vitest_selectOptions', |
nothing calls this directly
no outgoing calls
no test coverage detected