mirror of
https://github.com/vitest-dev/vitest.git
synced 2025-12-08 18:26:03 +00:00
fix(browser): support webdriverio 9 (#7553)
This commit is contained in:
parent
365ffe6b4c
commit
b1949c97c2
@ -60,6 +60,7 @@
|
||||
"*.d.ts",
|
||||
"context.js",
|
||||
"dist",
|
||||
"dummy.js",
|
||||
"providers"
|
||||
],
|
||||
"scripts": {
|
||||
@ -73,7 +74,7 @@
|
||||
"peerDependencies": {
|
||||
"playwright": "*",
|
||||
"vitest": "workspace:*",
|
||||
"webdriverio": "*"
|
||||
"webdriverio": "^7.0.0 || ^8.0.0 || ^9.0.0"
|
||||
},
|
||||
"peerDependenciesMeta": {
|
||||
"playwright": {
|
||||
@ -103,7 +104,8 @@
|
||||
"@vitest/runner": "workspace:*",
|
||||
"@vitest/ui": "workspace:*",
|
||||
"@vitest/ws-client": "workspace:*",
|
||||
"@wdio/protocols": "^8.40.3",
|
||||
"@wdio/protocols": "^9.7.0",
|
||||
"@wdio/types": "^9.9.0",
|
||||
"birpc": "0.2.19",
|
||||
"flatted": "^3.3.3",
|
||||
"ivya": "^1.1.1",
|
||||
@ -114,6 +116,6 @@
|
||||
"playwright-core": "^1.50.1",
|
||||
"safaridriver": "^1.0.0",
|
||||
"vitest": "workspace:*",
|
||||
"webdriverio": "^8.42.0"
|
||||
"webdriverio": "^9.10.0"
|
||||
}
|
||||
}
|
||||
|
||||
6
packages/browser/providers/webdriverio.d.ts
vendored
6
packages/browser/providers/webdriverio.d.ts
vendored
@ -1,9 +1,11 @@
|
||||
import type { RemoteOptions, ClickOptions, DragAndDropOptions } from 'webdriverio'
|
||||
import type { remote, ClickOptions, DragAndDropOptions } from 'webdriverio'
|
||||
import '../matchers.js'
|
||||
import type {} from "vitest/node"
|
||||
|
||||
declare module 'vitest/node' {
|
||||
export interface BrowserProviderOptions extends Partial<RemoteOptions> {}
|
||||
export interface BrowserProviderOptions extends Partial<
|
||||
Parameters<typeof remote>[0]
|
||||
> {}
|
||||
|
||||
export interface UserEventClickOptions extends ClickOptions {}
|
||||
|
||||
|
||||
@ -95,6 +95,13 @@ export function setupConsoleLogSpy(): void {
|
||||
function stdout(base: (...args: unknown[]) => void) {
|
||||
return (...args: unknown[]) => {
|
||||
base(...args)
|
||||
// ignore shadow root logs from wdio
|
||||
// https://github.com/webdriverio/webdriverio/discussions/14221
|
||||
if (args[0] === '[WDIO]') {
|
||||
if (args[1] === 'newShadowRoot' || args[1] === 'removeShadowRoot') {
|
||||
return
|
||||
}
|
||||
}
|
||||
sendLog('stdout', processLog(args))
|
||||
}
|
||||
}
|
||||
|
||||
@ -1,9 +1,9 @@
|
||||
import type { Capabilities } from '@wdio/types'
|
||||
import type {
|
||||
BrowserProvider,
|
||||
BrowserProviderInitializationOptions,
|
||||
TestProject,
|
||||
} from 'vitest/node'
|
||||
import type { RemoteOptions } from 'webdriverio'
|
||||
|
||||
const webdriverBrowsers = ['firefox', 'chrome', 'edge', 'safari'] as const
|
||||
type WebdriverBrowser = (typeof webdriverBrowsers)[number]
|
||||
@ -22,7 +22,7 @@ export class WebdriverBrowserProvider implements BrowserProvider {
|
||||
private browserName!: WebdriverBrowser
|
||||
private project!: TestProject
|
||||
|
||||
private options?: RemoteOptions
|
||||
private options?: Capabilities.WebdriverIOConfig
|
||||
|
||||
getSupportedBrowsers(): readonly string[] {
|
||||
return webdriverBrowsers
|
||||
@ -34,20 +34,32 @@ export class WebdriverBrowserProvider implements BrowserProvider {
|
||||
): Promise<void> {
|
||||
this.project = ctx
|
||||
this.browserName = browser
|
||||
this.options = options as RemoteOptions
|
||||
this.options = options as Capabilities.WebdriverIOConfig
|
||||
}
|
||||
|
||||
async switchToTestFrame(): Promise<void> {
|
||||
const page = this.browser!
|
||||
const iframe = await page.findElement(
|
||||
'css selector',
|
||||
'iframe[data-vitest]',
|
||||
)
|
||||
await page.switchToFrame(iframe)
|
||||
// support wdio@9
|
||||
if (page.switchFrame) {
|
||||
await page.switchFrame(page.$('iframe[data-vitest]'))
|
||||
}
|
||||
else {
|
||||
const iframe = await page.findElement(
|
||||
'css selector',
|
||||
'iframe[data-vitest]',
|
||||
)
|
||||
await page.switchToFrame(iframe)
|
||||
}
|
||||
}
|
||||
|
||||
async switchToMainFrame(): Promise<void> {
|
||||
await this.browser!.switchToParentFrame()
|
||||
const page = this.browser!
|
||||
if (page.switchFrame) {
|
||||
await page.switchFrame(null)
|
||||
}
|
||||
else {
|
||||
await page.switchToParentFrame()
|
||||
}
|
||||
}
|
||||
|
||||
getCommandsContext(): {
|
||||
@ -86,7 +98,7 @@ export class WebdriverBrowserProvider implements BrowserProvider {
|
||||
}
|
||||
|
||||
private buildCapabilities() {
|
||||
const capabilities: RemoteOptions['capabilities'] = {
|
||||
const capabilities: Capabilities.WebdriverIOConfig['capabilities'] = {
|
||||
...this.options?.capabilities,
|
||||
browserName: this.browserName,
|
||||
}
|
||||
|
||||
760
pnpm-lock.yaml
generated
760
pnpm-lock.yaml
generated
File diff suppressed because it is too large
Load Diff
@ -12,7 +12,8 @@ test('server-url http', async () => {
|
||||
})
|
||||
const url = ctx?.projects[0].browser?.vite.resolvedUrls?.local[0]
|
||||
expect(stderr).toBe('')
|
||||
expect(url).toBe('http://localhost:51133/')
|
||||
expect(url).toBeDefined()
|
||||
expect(new URL(url).port).toBe('51133')
|
||||
})
|
||||
|
||||
test('server-url https', async () => {
|
||||
@ -23,6 +24,7 @@ test('server-url https', async () => {
|
||||
})
|
||||
expect(stderr).toBe('')
|
||||
const url = ctx?.projects[0].browser?.vite.resolvedUrls?.local[0]
|
||||
expect(url).toBe('https://localhost:51122/')
|
||||
expect(url).toBeDefined()
|
||||
expect(new URL(url).port).toBe('51122')
|
||||
expect(stdout).toReportSummaryTestFiles({ passed: instances.length })
|
||||
})
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user