Skip to content

Commit

Permalink
Merge pull request #23 from LambdaTest/stage
Browse files Browse the repository at this point in the history
Release v1.0.3
  • Loading branch information
sushobhit-lt committed Jan 31, 2024
2 parents 08b32bd + f20e7b7 commit 81acd0d
Show file tree
Hide file tree
Showing 13 changed files with 252 additions and 5 deletions.
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.3",
"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:^"
}

}

42 changes: 42 additions & 0 deletions packages/playwright/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;

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

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
let { body } = await utils.postSnapshot({
dom,
url: page.url(),
name,
options
}, pkgName);

log.info(`Snapshot captured: ${name}`);

if (body && body.data && body.data.warnings?.length !== 0) body.data.warnings.map(e => log.warn(e));
} catch (err) {
throw err;
}
}

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

module.exports = {
smartuiSnapshot
}
28 changes: 28 additions & 0 deletions packages/puppeteer/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
{
"name": "@lambdatest/puppeteer-driver",
"version": "1.0.3",
"description": "Puppeteer 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/puppeteer"
},
"keywords": [
"lambdatest",
"puppeteer",
"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",
"dependencies": {
"@lambdatest/sdk-utils": "workspace:^"
}
}
44 changes: 44 additions & 0 deletions packages/puppeteer/src/smartui.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
const utils = require('@lambdatest/sdk-utils');
const pkgName = require('../package.json').name;


async function smartuiSnapshot(page, name, options = {}) {
if (!page) throw new Error('puppeteer `page` argument is required.');
if (!name || typeof name !== 'string') throw new Error('The `name` argument is required.');
if (!(await utils.isSmartUIRunning())) throw new Error('Cannot find SmartUI server.');

let log = utils.logger(pkgName);

try {
// Fetch the DOM serializer from the SmartUI server.
let resp = await utils.fetchDOMSerializer();

// Inject the DOM serializer into the page.
await page.evaluate(resp.body.data.dom);

// Serialize the DOM
let { dom, url } = await page.evaluate(options => ({
dom: SmartUIDOM.serialize(options),
url: document.URL
}), {});


// Post it to the SmartUI server.
let { body } = await utils.postSnapshot({
dom,
url,
name,
options
}, pkgName);

log.info(`Snapshot captured: ${name}`);

if (body && body.data && body.data.warnings?.length !== 0) body.data.warnings.map(e => log.warn(e));
} catch (error) {
throw new Error(error);
}
}

module.exports = {
smartuiSnapshot
};
2 changes: 1 addition & 1 deletion packages/sdk-utils/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@lambdatest/sdk-utils",
"version": "1.0.2",
"version": "1.0.3",
"description": "",
"main": "index.js",
"repository": {
Expand Down
3 changes: 2 additions & 1 deletion packages/sdk-utils/src/lib/utils.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
function getSmartUIServerAddress() {
return process.env.SMARTUI_SERVER_ADDRESS || 'http://localhost:8080'
if (!process.env.SMARTUI_SERVER_ADDRESS) throw new Error('SmartUI server address not found');
return process.env.SMARTUI_SERVER_ADDRESS
}

module.exports = {
Expand Down
2 changes: 1 addition & 1 deletion packages/selenium-driver/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@lambdatest/selenium-driver",
"version": "1.0.2",
"version": "1.0.3",
"description": "Selenium driver for all Lambdatest functionalities",
"main": "index.js",
"repository": {
Expand Down
4 changes: 2 additions & 2 deletions packages/selenium-driver/src/smartui.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@ const pkgName = require('../package.json').name;
async function smartuiSnapshot(driver, name, options = {}) {
// TODO: check if driver is selenium webdriver object
if (!driver) throw new Error('An instance of the selenium driver object is required.');
if (!name) throw new Error('The `name` argument is required.');
if (!(await utils.isSmartUIRunning())) throw new Error('SmartUI server is not running.');
if (!name || typeof name !== 'string') throw new Error('The `name` argument is required.');
if (!(await utils.isSmartUIRunning())) throw new Error('Cannot find SmartUI server.');
let log = utils.logger(pkgName);

try {
Expand Down
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.3",
"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:^"
}
}
44 changes: 44 additions & 0 deletions packages/testcafe/src/smartui.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
const utils = require('@lambdatest/sdk-utils');
const pkgName = require('../package.json').name;

async function smartuiSnapshot(t, name, options) {
if (!t) throw new Error("The test function's `t` argument is required.");
if (!name || typeof name !== 'string') throw new Error('The `name` argument is required.');
if (!(await utils.isSmartUIRunning())) throw new Error('Cannot find SmartUI server.');

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: {} });

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

log.info(`Snapshot captured: ${name}`);

if (body && body.data && body.data.warnings?.length !== 0) body.data.warnings.map(e => log.warn(e));
} catch (error) {
// Handle errors
throw error;
}
}

module.exports = {
smartuiSnapshot
}

0 comments on commit 81acd0d

Please sign in to comment.