-
Notifications
You must be signed in to change notification settings - Fork 90
/
playwright-extensions-test.js
71 lines (61 loc) · 2.39 KB
/
playwright-extensions-test.js
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
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
const {chromium} = require("playwright");
const {expect} = require("expect");
const cp = require('child_process');
const playwrightClientVersion = cp.execSync('npx playwright --version').toString().trim().split(' ')[1];
(async () => {
let browser;
try {
const capabilities = {
"browserName": "Chrome",
"browserVersion": "latest",
"LT:Options": {
"platform": "Windows 10",
"build": "Playwright Extensions Build",
"name": "Load extension and verify it",
"user": process.env.LT_USERNAME,
"accessKey": process.env.LT_ACCESS_KEY,
"network": true,
"video": true,
"console": true,
'playwrightClientVersion': playwrightClientVersion,
"lambdaLoadExtensions": [
// Add private .zip link(s) of the extension uploaded on LambdaTest
],
"loadExtensions": [
// Add public .zip link(s) of the extension
"https://public-objects-for-test.s3.amazonaws.com/hello-world-1.0.0.zip"
],
},
};
browser = await chromium.connectOverCDP(
`wss://cdp.lambdatest.com/playwright-cdp?capabilities=${encodeURIComponent(JSON.stringify(capabilities))}`
);
const defaultContext = browser.contexts()[0];
const page = defaultContext.pages()[1];
await page.goto("chrome://extensions/")
await page.waitForTimeout(1000)
let [background] = defaultContext.serviceWorkers();
if (!background)
background = await defaultContext.waitForEvent("serviceworker");
const extensionId = background.url().split("/")[2];
console.log("ExtensionId:: ", extensionId);
await page.goto(`chrome-extension://${extensionId}/hello.html`)
await page.waitForTimeout(1000)
let text = await (await page.locator("body > p")).textContent();
try {
expect(text).toEqual('Hello, World!')
// Mark the test as completed or failed
await page.evaluate(_ => {}, `lambdatest_action: ${JSON.stringify({ action: 'setTestStatus', arguments: { status: 'passed', remark: 'Data matched' } })}`)
} catch (e) {
await page.evaluate(_ => {}, `lambdatest_action: ${JSON.stringify({ action: 'setTestStatus', arguments: { status: 'failed', remark: e.stack } })}`)
}
await teardown(page, browser)
} catch (e) {
await teardown(page, browser)
throw e
}
})();
async function teardown(page, browser) {
await page.close();
await browser.close();
}