-
-
Notifications
You must be signed in to change notification settings - Fork 1.2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(browser): support
click
event (#5777)
- Loading branch information
1 parent
041b9c4
commit 839c39f
Showing
13 changed files
with
180 additions
and
158 deletions.
There are no files selected for viewing
This file contains 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
This file contains 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
This file contains 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
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
import type { Page } from 'playwright' | ||
import type { UserEvent } from '../../../context' | ||
import type { UserEventCommand } from './utils' | ||
|
||
export const click: UserEventCommand<UserEvent['click']> = async ( | ||
{ provider }, | ||
element, | ||
options = {}, | ||
) => { | ||
if (provider.name === 'playwright') { | ||
const page = (provider as any).page as Page | ||
await page.frameLocator('iframe[data-vitest]').locator(`xpath=${element}`).click(options) | ||
return | ||
} | ||
if (provider.name === 'webdriverio') { | ||
const page = (provider as any).browser as WebdriverIO.Browser | ||
const frame = await page.findElement('css selector', 'iframe[data-vitest]') | ||
await page.switchToFrame(frame) | ||
const xpath = `//${element}` | ||
await (await page.$(xpath)).click(options) | ||
return | ||
} | ||
throw new Error(`Provider "${provider.name}" doesn't support click command`) | ||
} |
This file contains 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
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
import type { BrowserCommand } from 'vitest/node' | ||
|
||
export type UserEventCommand<T extends (...args: any) => any> = BrowserCommand< | ||
ConvertUserEventParameters<Parameters<T>> | ||
> | ||
|
||
type ConvertElementToLocator<T> = T extends Element ? string : T | ||
type ConvertUserEventParameters<T extends unknown[]> = { | ||
[K in keyof T]: ConvertElementToLocator<T[K]> | ||
} |
This file contains 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
This file contains 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
This file contains 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
This file contains 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
Oops, something went wrong.