Skip to content

Commit 81acd0d

Browse files
authored
Merge pull request #23 from LambdaTest/stage
Release v1.0.3
2 parents 08b32bd + f20e7b7 commit 81acd0d

File tree

13 files changed

+252
-5
lines changed

13 files changed

+252
-5
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.3",
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: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
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, name, options) {
6+
if (!page) throw new Error('A Playwright `page` object is required.');
7+
if (!name || typeof name !== 'string') throw new Error('The `name` argument is required.');
8+
if (!(await utils.isSmartUIRunning())) throw new Error('Cannot find SmartUI server.');
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+
let { body } = await utils.postSnapshot({
26+
dom,
27+
url: page.url(),
28+
name,
29+
options
30+
}, pkgName);
31+
32+
log.info(`Snapshot captured: ${name}`);
33+
34+
if (body && body.data && body.data.warnings?.length !== 0) body.data.warnings.map(e => log.warn(e));
35+
} catch (err) {
36+
throw err;
37+
}
38+
}
39+
40+
module.exports = {
41+
smartuiSnapshot
42+
}

packages/puppeteer/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/puppeteer/package.json

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
{
2+
"name": "@lambdatest/puppeteer-driver",
3+
"version": "1.0.3",
4+
"description": "Puppeteer 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/puppeteer"
13+
},
14+
"keywords": [
15+
"lambdatest",
16+
"puppeteer",
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+
"dependencies": {
26+
"@lambdatest/sdk-utils": "workspace:^"
27+
}
28+
}

packages/puppeteer/src/smartui.js

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
const utils = require('@lambdatest/sdk-utils');
2+
const pkgName = require('../package.json').name;
3+
4+
5+
async function smartuiSnapshot(page, name, options = {}) {
6+
if (!page) throw new Error('puppeteer `page` argument is required.');
7+
if (!name || typeof name !== 'string') throw new Error('The `name` argument is required.');
8+
if (!(await utils.isSmartUIRunning())) throw new Error('Cannot find SmartUI server.');
9+
10+
let log = utils.logger(pkgName);
11+
12+
try {
13+
// Fetch the DOM serializer from the SmartUI server.
14+
let resp = await utils.fetchDOMSerializer();
15+
16+
// Inject the DOM serializer into the page.
17+
await page.evaluate(resp.body.data.dom);
18+
19+
// Serialize the DOM
20+
let { dom, url } = await page.evaluate(options => ({
21+
dom: SmartUIDOM.serialize(options),
22+
url: document.URL
23+
}), {});
24+
25+
26+
// Post it to the SmartUI server.
27+
let { body } = await utils.postSnapshot({
28+
dom,
29+
url,
30+
name,
31+
options
32+
}, pkgName);
33+
34+
log.info(`Snapshot captured: ${name}`);
35+
36+
if (body && body.data && body.data.warnings?.length !== 0) body.data.warnings.map(e => log.warn(e));
37+
} catch (error) {
38+
throw new Error(error);
39+
}
40+
}
41+
42+
module.exports = {
43+
smartuiSnapshot
44+
};

packages/sdk-utils/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@lambdatest/sdk-utils",
3-
"version": "1.0.2",
3+
"version": "1.0.3",
44
"description": "",
55
"main": "index.js",
66
"repository": {

packages/sdk-utils/src/lib/utils.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
function getSmartUIServerAddress() {
2-
return process.env.SMARTUI_SERVER_ADDRESS || 'http://localhost:8080'
2+
if (!process.env.SMARTUI_SERVER_ADDRESS) throw new Error('SmartUI server address not found');
3+
return process.env.SMARTUI_SERVER_ADDRESS
34
}
45

56
module.exports = {

packages/selenium-driver/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@lambdatest/selenium-driver",
3-
"version": "1.0.2",
3+
"version": "1.0.3",
44
"description": "Selenium driver for all Lambdatest functionalities",
55
"main": "index.js",
66
"repository": {

packages/selenium-driver/src/smartui.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,8 @@ const pkgName = require('../package.json').name;
44
async function smartuiSnapshot(driver, name, options = {}) {
55
// TODO: check if driver is selenium webdriver object
66
if (!driver) throw new Error('An instance of the selenium driver object is required.');
7-
if (!name) throw new Error('The `name` argument is required.');
8-
if (!(await utils.isSmartUIRunning())) throw new Error('SmartUI server is not running.');
7+
if (!name || typeof name !== 'string') throw new Error('The `name` argument is required.');
8+
if (!(await utils.isSmartUIRunning())) throw new Error('Cannot find SmartUI server.');
99
let log = utils.logger(pkgName);
1010

1111
try {

packages/testcafe/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/testcafe/package.json

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
{
2+
"name": "@lambdatest/testcafe-driver",
3+
"version": "1.0.3",
4+
"description": "Testcafe SDK for LambdaTest smart UI",
5+
"repository": {
6+
"type": "git",
7+
"url": "git+https://github.com/LambdaTest/lambdatest-js-sdk.git",
8+
"directory": "packages/testcafe"
9+
},
10+
"main": "index.js",
11+
"scripts": {
12+
"test": "echo \"Error: no test specified\" && exit 1"
13+
},
14+
"keywords": [
15+
"lambdatest",
16+
"testcafe",
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+
25+
"homepage": "https://github.com/LambdaTest/lambdatest-js-sdk#readme",
26+
"devDependencies": {
27+
"testcafe": "^3.4.0"
28+
},
29+
"peerDependencies": {
30+
"testcafe": ">=1"
31+
},
32+
"dependencies": {
33+
"@lambdatest/sdk-utils": "workspace:^"
34+
}
35+
}

packages/testcafe/src/smartui.js

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
const utils = require('@lambdatest/sdk-utils');
2+
const pkgName = require('../package.json').name;
3+
4+
async function smartuiSnapshot(t, name, options) {
5+
if (!t) throw new Error("The test function's `t` argument is required.");
6+
if (!name || typeof name !== 'string') throw new Error('The `name` argument is required.');
7+
if (!(await utils.isSmartUIRunning())) throw new Error('Cannot find SmartUI server.');
8+
9+
let log = utils.logger(pkgName);
10+
11+
try {
12+
// Inject the DOM serialization script
13+
/* eslint-disable-next-line no-new-func */
14+
const resp = await utils.fetchDOMSerializer();
15+
16+
await t.eval(new Function(resp.body.data.dom), { boundTestRun: t });
17+
18+
// Serialize and capture the DOM
19+
/* istanbul ignore next: no instrumenting injected code */
20+
let { dom, url } = await t.eval((options) => ({
21+
/* eslint-disable-next-line no-undef */
22+
dom: SmartUIDOM.serialize(options),
23+
url: window.location.href || document.URL,
24+
}), { boundTestRun: t, dependencies: {} });
25+
26+
let { body } = await utils.postSnapshot({
27+
dom: dom,
28+
url,
29+
name,
30+
options
31+
}, pkgName);
32+
33+
log.info(`Snapshot captured: ${name}`);
34+
35+
if (body && body.data && body.data.warnings?.length !== 0) body.data.warnings.map(e => log.warn(e));
36+
} catch (error) {
37+
// Handle errors
38+
throw error;
39+
}
40+
}
41+
42+
module.exports = {
43+
smartuiSnapshot
44+
}

0 commit comments

Comments
 (0)