Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions packages/playwright/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
const { smartuiSnapshot } = require('./src/smartui');

module.exports = {
smartuiSnapshot
}
38 changes: 38 additions & 0 deletions packages/playwright/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
{
"name": "@lambdatest/playwright-driver",
"version": "1.0.0",
"description": "Playwright SDK for smart UI",
"main": "index.js",
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1"
},
"repository": {
"type": "git",
"url": "git+https://github.com/LambdaTest/lambdatest-js-sdk.git",
"directory": "packages/playwright"
},
"keywords": [
"lambdatest",
"playwright",
"smartui"
],
"author": "LambdaTest <keys@lambdatest.com>",
"license": "MIT",
"bugs": {
"url": "https://github.com/LambdaTest/lambdatest-js-sdk/issues"
},
"homepage": "https://github.com/LambdaTest/lambdatest-js-sdk#readme",

"peerDependencies": {
"playwright-core": ">=1"
},
"devDependencies": {
"@playwright/test": "^1.24.2",
"playwright": "^1.24.2"
},
"dependencies": {
"@lambdatest/sdk-utils": "workspace:^"
}

}

40 changes: 40 additions & 0 deletions packages/playwright/src/smartui.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
const utils = require('@lambdatest/sdk-utils');
const pkgName = require('../package.json').name;

// Take a DOM snapshot and post it to the snapshot endpoint
async function smartuiSnapshot(page, snapshotName, options) {
if (!page) throw new Error('A Playwright `page` object is required.');
if (!snapshotName) throw new Error('The `name` argument is required.');
if (!(await utils.isSmartUIRunning())) throw new Error('SmartUI server is not running.');

let log = utils.logger(pkgName);

try {
// Inject the DOM serialization script
const resp = await utils.fetchDOMSerializer();
await page.evaluate(resp.body.data.dom);

// Serialize and capture the DOM
/* istanbul ignore next: no instrumenting injected code */
let { dom } = await page.evaluate((options) => ({
/* eslint-disable-next-line no-undef */
dom: SmartUIDOM.serialize(options)
}), {});

// Post the DOM to the snapshot endpoint with snapshot options and other info
await utils.postSnapshot({
dom: dom.html,
url: page.url(),
name: snapshotName,
options
}, pkgName);

log.info(`Snapshot captured: ${snapshotName}`);
} catch (err) {
throw err;
}
}

module.exports = {
smartuiSnapshot
}
5 changes: 5 additions & 0 deletions packages/testcafe/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
const { smartuiSnapshot } = require('./src/smartui');

module.exports = {
smartuiSnapshot
}
35 changes: 35 additions & 0 deletions packages/testcafe/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
{
"name": "@lambdatest/testcafe-driver",
"version": "1.0.0",
"description": "Testcafe SDK for LambdaTest smart UI",
"repository": {
"type": "git",
"url": "git+https://github.com/LambdaTest/lambdatest-js-sdk.git",
"directory": "packages/testcafe"
},
"main": "index.js",
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1"
},
"keywords": [
"lambdatest",
"testcafe",
"smartui"
],
"author": "LambdaTest <keys@lambdatest.com>",
"license": "MIT",
"bugs": {
"url": "https://github.com/LambdaTest/lambdatest-js-sdk/issues"
},

"homepage": "https://github.com/LambdaTest/lambdatest-js-sdk#readme",
"devDependencies": {
"testcafe": "^3.4.0"
},
"peerDependencies": {
"testcafe": ">=1"
},
"dependencies": {
"@lambdatest/sdk-utils": "workspace:^"
}
}
42 changes: 42 additions & 0 deletions packages/testcafe/src/smartui.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
const utils = require('@lambdatest/sdk-utils');
const pkgName = require('../package.json').name;

async function smartuiSnapshot(t, snapshotName, options) {
if (!t) throw new Error("The test function's `t` argument is required.");
if (!snapshotName) throw new Error('The `name` argument is required.');
if (!(await utils.isSmartUIRunning())) throw new Error('SmartUI server is not running.');

let log = utils.logger(pkgName);

try {
// Inject the DOM serialization script
/* eslint-disable-next-line no-new-func */
const resp = await utils.fetchDOMSerializer();

await t.eval(new Function(resp.body.data.dom), { boundTestRun: t });

// Serialize and capture the DOM
/* istanbul ignore next: no instrumenting injected code */
let { dom, url } = await t.eval((options) => ({
/* eslint-disable-next-line no-undef */
dom: SmartUIDOM.serialize(options),
url: window.location.href || document.URL,
}), { boundTestRun: t, dependencies: {} });

await utils.postSnapshot({
dom: dom,
url,
name: snapshotName,
options
}, pkgName);

log.info(`Snapshot captured: ${snapshotName}`);
} catch (error) {
// Handle errors
throw error;
}
}

module.exports = {
smartuiSnapshot
}