Skip to content

Commit

Permalink
feat!: add support for webdriverio capabilities
Browse files Browse the repository at this point in the history
  • Loading branch information
haywirez committed Jul 11, 2023
1 parent a90d64f commit d3fa570
Show file tree
Hide file tree
Showing 4 changed files with 219 additions and 29 deletions.
20 changes: 20 additions & 0 deletions docs/guide/browser.md
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,26 @@ npx vitest --browser.name=chrome --browser.headless

In this case, Vitest will run in headless mode using the Chrome browser.

## WebdriverIO Capabilities

If using [WebdriverIO](https://webdriver.io/) (default), you may pass [custom capabilities](https://webdriver.io/docs/capabilities#custom-capabilities) as:

```ts
export default defineConfig({
test: {
browser: {
enabled: true,
headless: true,
},
capabilities: {
'goog:chromeOptions': {
args: ['disable-gpu'],
},
},
},
})
```

## Limitations
### Thread Blocking Dialogs

Expand Down
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@
"@vitest/coverage-istanbul": "workspace:*",
"@vitest/coverage-v8": "workspace:*",
"@vitest/ui": "workspace:*",
"@wdio/types": "^8.10.4",
"bumpp": "^9.1.1",
"esbuild": "^0.18.11",
"eslint": "^8.44.0",
Expand Down
7 changes: 6 additions & 1 deletion packages/vitest/src/node/browser/webdriver.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import type { Awaitable } from '@vitest/utils'
import type { Capabilities } from '@wdio/types'
import type { BrowserProvider, BrowserProviderOptions } from '../../types/browser'
import { ensurePackageInstalled } from '../pkg'
import type { WorkspaceProject } from '../workspace'
Expand All @@ -8,6 +9,7 @@ export type WebdriverBrowser = typeof webdriverBrowsers[number]

export interface WebdriverProviderOptions extends BrowserProviderOptions {
browser: WebdriverBrowser
capabilities?: Capabilities.Capabilities
}

export class WebdriverBrowserProvider implements BrowserProvider {
Expand All @@ -16,15 +18,17 @@ export class WebdriverBrowserProvider implements BrowserProvider {
private cachedBrowser: WebdriverIO.Browser | null = null
private stopSafari: () => void = () => {}
private browser!: WebdriverBrowser
private capabilities?: Capabilities.Capabilities
private ctx!: WorkspaceProject

getSupportedBrowsers() {
return webdriverBrowsers
}

async initialize(ctx: WorkspaceProject, { browser }: WebdriverProviderOptions) {
async initialize(ctx: WorkspaceProject, { browser, capabilities }: WebdriverProviderOptions) {
this.ctx = ctx
this.browser = browser
this.capabilities = capabilities

const root = this.ctx.config.root

Expand Down Expand Up @@ -59,6 +63,7 @@ export class WebdriverBrowserProvider implements BrowserProvider {
capabilities: {
'browserName': this.browser,
'wdio:devtoolsOptions': { headless: options.headless },
...this.capabilities,
},
})

Expand Down
Loading

0 comments on commit d3fa570

Please sign in to comment.