Skip to content

Commit e530b6f

Browse files
committed
playwright
1 parent 56f2a56 commit e530b6f

File tree

4 files changed

+88
-4
lines changed

4 files changed

+88
-4
lines changed

packages/playwright/index.js

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
const { smartuiSnapshot } = require('./src/smartui');
2+
3+
module.exports = {
4+
smartuiSnapshot
5+
}

packages/playwright/package.json

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
{
2+
"name": "@lambdatest/playwright-driver",
3+
"version": "1.0.0",
4+
"description": "Playwright SDK for smart UI",
5+
"main": "index.js",
6+
"scripts": {
7+
"test": "echo \"Error: no test specified\" && exit 1"
8+
},
9+
"repository": {
10+
"type": "git",
11+
"url": "git+https://github.com/LambdaTest/lambdatest-js-sdk.git",
12+
"directory": "packages/playwright"
13+
},
14+
"keywords": [
15+
"lambdatest",
16+
"playwright",
17+
"smartui"
18+
],
19+
"author": "LambdaTest <[email protected]>",
20+
"license": "MIT",
21+
"bugs": {
22+
"url": "https://github.com/LambdaTest/lambdatest-js-sdk/issues"
23+
},
24+
"homepage": "https://github.com/LambdaTest/lambdatest-js-sdk#readme",
25+
26+
"peerDependencies": {
27+
"playwright-core": ">=1"
28+
},
29+
"devDependencies": {
30+
"@playwright/test": "^1.24.2",
31+
"playwright": "^1.24.2"
32+
},
33+
"dependencies": {
34+
"@lambdatest/sdk-utils": "workspace:^"
35+
}
36+
37+
}
38+

packages/playwright/src/smartui.js

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
const utils = require('@lambdatest/sdk-utils');
2+
const pkgName = require('../package.json').name;
3+
4+
// Take a DOM snapshot and post it to the snapshot endpoint
5+
async function smartuiSnapshot(page, snapshotName, options) {
6+
if (!page) throw new Error('A Playwright `page` object is required.');
7+
if (!snapshotName) throw new Error('The `name` argument is required.');
8+
if (!(await utils.isSmartUIRunning())) throw new Error('SmartUI server is not running.');
9+
10+
let log = utils.logger(pkgName);
11+
12+
try {
13+
// Inject the DOM serialization script
14+
const resp = await utils.fetchDOMSerializer();
15+
await page.evaluate(resp.body.data.dom);
16+
17+
// Serialize and capture the DOM
18+
/* istanbul ignore next: no instrumenting injected code */
19+
let { dom } = await page.evaluate((options) => ({
20+
/* eslint-disable-next-line no-undef */
21+
dom: SmartUIDOM.serialize(options)
22+
}), {});
23+
24+
// Post the DOM to the snapshot endpoint with snapshot options and other info
25+
await utils.postSnapshot({
26+
dom: dom.html,
27+
url: page.url(),
28+
name: snapshotName,
29+
options
30+
}, pkgName);
31+
32+
log.info(`Snapshot captured: ${snapshotName}`);
33+
} catch (err) {
34+
throw err;
35+
}
36+
}
37+
38+
module.exports = {
39+
smartuiSnapshot
40+
}

packages/testcafe/package.json

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,13 +4,13 @@
44
"description": "Testcafe SDK for LambdaTest smart UI",
55
"repository": {
66
"type": "git",
7-
"url": "git+https://github.com/LambdaTest/lambdatest-js-sdk.git"
7+
"url": "git+https://github.com/LambdaTest/lambdatest-js-sdk.git",
8+
"directory": "packages/testcafe"
89
},
910
"main": "index.js",
1011
"scripts": {
11-
"build": "gulp build",
12-
"test": "gulp test"
13-
},
12+
"test": "echo \"Error: no test specified\" && exit 1"
13+
},
1414
"keywords": [
1515
"lambdatest",
1616
"testcafe",
@@ -22,6 +22,7 @@
2222
"url": "https://github.com/LambdaTest/lambdatest-js-sdk/issues"
2323
},
2424

25+
"homepage": "https://github.com/LambdaTest/lambdatest-js-sdk#readme",
2526
"devDependencies": {
2627
"testcafe": "^3.4.0"
2728
},

0 commit comments

Comments
 (0)