-
-
Notifications
You must be signed in to change notification settings - Fork 365
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add functionality to run same test in multiple browsers
- Loading branch information
Showing
4 changed files
with
38 additions
and
29 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 |
---|---|---|
@@ -1,19 +1,28 @@ | ||
/* eslint-disable ava/no-ignored-test-files */ | ||
import process from 'node:process'; | ||
import type {ExecutionContext, Implementation} from 'ava'; | ||
import {chromium, type Page} from 'playwright-chromium'; | ||
import test from 'ava'; | ||
import {chromium, firefox, webkit, type BrowserType, type Page} from 'playwright'; | ||
import type {ExecutionContext} from 'ava'; | ||
|
||
type Run = (t: ExecutionContext, page: Page) => Promise<void>; | ||
|
||
const PWDEBUG = Boolean(process.env['PWDEBUG']); | ||
const DEFAULT_BROWSERS = [chromium, firefox, webkit]; | ||
|
||
export const withPage: Implementation<any[]> = async (t: ExecutionContext, run: Run): Promise<void> => { | ||
const browser = await chromium.launch({ | ||
devtools: PWDEBUG, | ||
}); | ||
const page = await browser.newPage(); | ||
try { | ||
await run(t, page); | ||
} finally { | ||
await browser.close(); | ||
export const browserTest = (title: string, browserTypes: BrowserType[], run: Run) => { | ||
for (const browserType of browserTypes) { | ||
test.serial(`${browserType.name()} - ${title}`, async t => { | ||
const browser = await browserType.launch({devtools: PWDEBUG}); | ||
const page = await browser.newPage(); | ||
try { | ||
await run(t, page); | ||
} finally { | ||
await browser.close(); | ||
} | ||
}); | ||
} | ||
}; | ||
|
||
export const defaultBrowsersTest = (title: string, run: Run) => { | ||
browserTest(title, DEFAULT_BROWSERS, run); | ||
}; |