Skip to content

puppeteer SDK for smartUI #14

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Jan 25, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

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/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.0",
"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:^"
}
}
42 changes: 42 additions & 0 deletions packages/puppeteer/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(page, name, options = {}) {
if (!page) throw new Error('puppeteer `page` argument is required.');
if (!name) 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 {
// 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.
await utils.postSnapshot({
dom: dom.html,
url,
name,
options
}, pkgName);

log.info(`Snapshot captured: ${name}`);
} catch (error) {
throw new Error(error);
}
}

module.exports = {
smartuiSnapshot
};