forked from MarcusFelling/demo.playwright
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathexample.spec.ts
34 lines (30 loc) · 1.21 KB
/
example.spec.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
/**
* In this test we get a handle to the background page
* of an extension whose source is located in ./my-extension
* @see https://playwright.dev/docs/chrome-extensions
* NOTE: there is not currently support to test extension pop-ups
* Feature request: https://github.com/microsoft/playwright/issues/5593
*/
import {test, chromium, BrowserContext} from '@playwright/test';
test.describe('chrome extension tests', () => {
let browserContext: BrowserContext;
test.beforeEach(async ({}, testInfo) => {
const pathToExtension = require('path').join(__dirname, '../my-extension');
const userDataDir = testInfo.outputPath('test-user-data-dir');
browserContext = await chromium.launchPersistentContext(userDataDir, {
args: [
`--disable-extensions-except=${pathToExtension}`,
`--load-extension=${pathToExtension}`,
],
});
});
test.afterEach(async () => {
// Don't forget to close the created context.
// Closing persistent context will close the browser.
await browserContext.close();
});
test('Should get handle to background page of extension', async () => {
browserContext.backgroundPages()[0];
// Test the background page as you would any other page.
});
});