From 772c47d29fad0b57ac411845313d2e5649db1e5a Mon Sep 17 00:00:00 2001 From: Pawan Rai Date: Thu, 25 Jan 2024 10:52:49 +0530 Subject: [PATCH 1/8] puppeteer SDK for smartUI --- packages/puppeteer/index.js | 5 ++++ packages/puppeteer/package.json | 28 +++++++++++++++++++++ packages/puppeteer/src/smartui.js | 42 +++++++++++++++++++++++++++++++ 3 files changed, 75 insertions(+) create mode 100644 packages/puppeteer/index.js create mode 100644 packages/puppeteer/package.json create mode 100644 packages/puppeteer/src/smartui.js diff --git a/packages/puppeteer/index.js b/packages/puppeteer/index.js new file mode 100644 index 0000000..35f348a --- /dev/null +++ b/packages/puppeteer/index.js @@ -0,0 +1,5 @@ +const { smartuiSnapshot } = require('./src/smartui'); + +module.exports = { + smartuiSnapshot +} diff --git a/packages/puppeteer/package.json b/packages/puppeteer/package.json new file mode 100644 index 0000000..eb31f1e --- /dev/null +++ b/packages/puppeteer/package.json @@ -0,0 +1,28 @@ +{ + "name": "@lambdatest/puppeteer", + "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 ", + "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:^" + } +} diff --git a/packages/puppeteer/src/smartui.js b/packages/puppeteer/src/smartui.js new file mode 100644 index 0000000..bdf7e19 --- /dev/null +++ b/packages/puppeteer/src/smartui.js @@ -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 +}; \ No newline at end of file From ebfd9c49e752b6d47c12bdbf8739450dcb42a9e7 Mon Sep 17 00:00:00 2001 From: Pawan Rai Date: Thu, 25 Jan 2024 13:18:00 +0530 Subject: [PATCH 2/8] Changed name --- packages/puppeteer/package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/puppeteer/package.json b/packages/puppeteer/package.json index eb31f1e..7329460 100644 --- a/packages/puppeteer/package.json +++ b/packages/puppeteer/package.json @@ -1,5 +1,5 @@ { - "name": "@lambdatest/puppeteer", + "name": "@lambdatest/puppeteer-driver", "version": "1.0.0", "description": "Puppeteer SDK for smart UI", "main": "index.js", From 56f2a56687e5f548e8dd0d39483c310adfe2b4b4 Mon Sep 17 00:00:00 2001 From: Shahnawaz-Sk Date: Thu, 25 Jan 2024 19:52:25 +0530 Subject: [PATCH 3/8] testcafe changes --- packages/testcafe/index.js | 5 ++++ packages/testcafe/package.json | 34 ++++++++++++++++++++++++++ packages/testcafe/src/smartui.js | 42 ++++++++++++++++++++++++++++++++ 3 files changed, 81 insertions(+) create mode 100644 packages/testcafe/index.js create mode 100644 packages/testcafe/package.json create mode 100644 packages/testcafe/src/smartui.js diff --git a/packages/testcafe/index.js b/packages/testcafe/index.js new file mode 100644 index 0000000..3a034cb --- /dev/null +++ b/packages/testcafe/index.js @@ -0,0 +1,5 @@ +const { smartuiSnapshot } = require('./src/smartui'); + +module.exports = { + smartuiSnapshot +} \ No newline at end of file diff --git a/packages/testcafe/package.json b/packages/testcafe/package.json new file mode 100644 index 0000000..cdec7c8 --- /dev/null +++ b/packages/testcafe/package.json @@ -0,0 +1,34 @@ +{ + "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" + }, + "main": "index.js", + "scripts": { + "build": "gulp build", + "test": "gulp test" + }, + "keywords": [ + "lambdatest", + "testcafe", + "smartui" + ], + "author": "LambdaTest ", + "license": "MIT", + "bugs": { + "url": "https://github.com/LambdaTest/lambdatest-js-sdk/issues" + }, + + "devDependencies": { + "testcafe": "^3.4.0" + }, + "peerDependencies": { + "testcafe": ">=1" + }, + "dependencies": { + "@lambdatest/sdk-utils": "workspace:^" + } +} diff --git a/packages/testcafe/src/smartui.js b/packages/testcafe/src/smartui.js new file mode 100644 index 0000000..48d3824 --- /dev/null +++ b/packages/testcafe/src/smartui.js @@ -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 +} \ No newline at end of file From e530b6fbfdb682276c615f5cc9219f9c3532fd01 Mon Sep 17 00:00:00 2001 From: Shahnawaz-Sk Date: Thu, 25 Jan 2024 20:25:01 +0530 Subject: [PATCH 4/8] playwright --- packages/playwright/index.js | 5 ++++ packages/playwright/package.json | 38 ++++++++++++++++++++++++++++ packages/playwright/src/smartui.js | 40 ++++++++++++++++++++++++++++++ packages/testcafe/package.json | 9 ++++--- 4 files changed, 88 insertions(+), 4 deletions(-) create mode 100644 packages/playwright/index.js create mode 100644 packages/playwright/package.json create mode 100644 packages/playwright/src/smartui.js diff --git a/packages/playwright/index.js b/packages/playwright/index.js new file mode 100644 index 0000000..3a034cb --- /dev/null +++ b/packages/playwright/index.js @@ -0,0 +1,5 @@ +const { smartuiSnapshot } = require('./src/smartui'); + +module.exports = { + smartuiSnapshot +} \ No newline at end of file diff --git a/packages/playwright/package.json b/packages/playwright/package.json new file mode 100644 index 0000000..f5f296d --- /dev/null +++ b/packages/playwright/package.json @@ -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 ", + "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:^" + } + + } + \ No newline at end of file diff --git a/packages/playwright/src/smartui.js b/packages/playwright/src/smartui.js new file mode 100644 index 0000000..6b20a57 --- /dev/null +++ b/packages/playwright/src/smartui.js @@ -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 +} \ No newline at end of file diff --git a/packages/testcafe/package.json b/packages/testcafe/package.json index cdec7c8..c8b1441 100644 --- a/packages/testcafe/package.json +++ b/packages/testcafe/package.json @@ -4,13 +4,13 @@ "description": "Testcafe SDK for LambdaTest smart UI", "repository": { "type": "git", - "url": "git+https://github.com/LambdaTest/lambdatest-js-sdk.git" + "url": "git+https://github.com/LambdaTest/lambdatest-js-sdk.git", + "directory": "packages/testcafe" }, "main": "index.js", "scripts": { - "build": "gulp build", - "test": "gulp test" - }, + "test": "echo \"Error: no test specified\" && exit 1" + }, "keywords": [ "lambdatest", "testcafe", @@ -22,6 +22,7 @@ "url": "https://github.com/LambdaTest/lambdatest-js-sdk/issues" }, + "homepage": "https://github.com/LambdaTest/lambdatest-js-sdk#readme", "devDependencies": { "testcafe": "^3.4.0" }, From 3c8912f6c407c918b41f6671e450629350263c70 Mon Sep 17 00:00:00 2001 From: Shahnawaz-Sk Date: Mon, 29 Jan 2024 18:01:49 +0530 Subject: [PATCH 5/8] fixes --- packages/playwright/src/smartui.js | 2 +- packages/puppeteer/src/smartui.js | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/packages/playwright/src/smartui.js b/packages/playwright/src/smartui.js index 6b20a57..dfe7070 100644 --- a/packages/playwright/src/smartui.js +++ b/packages/playwright/src/smartui.js @@ -23,7 +23,7 @@ async function smartuiSnapshot(page, snapshotName, options) { // Post the DOM to the snapshot endpoint with snapshot options and other info await utils.postSnapshot({ - dom: dom.html, + dom, url: page.url(), name: snapshotName, options diff --git a/packages/puppeteer/src/smartui.js b/packages/puppeteer/src/smartui.js index bdf7e19..89cce64 100644 --- a/packages/puppeteer/src/smartui.js +++ b/packages/puppeteer/src/smartui.js @@ -25,7 +25,7 @@ async function smartuiSnapshot(page, name, options = {}) { // Post it to the SmartUI server. await utils.postSnapshot({ - dom: dom.html, + dom, url, name, options From 70661f833b9f1d4123bb668de144e62253e4acc3 Mon Sep 17 00:00:00 2001 From: Shahnawaz-Sk Date: Tue, 30 Jan 2024 13:46:38 +0530 Subject: [PATCH 6/8] warnings --- packages/playwright/src/smartui.js | 4 +++- packages/puppeteer/src/smartui.js | 4 +++- packages/testcafe/src/smartui.js | 4 +++- 3 files changed, 9 insertions(+), 3 deletions(-) diff --git a/packages/playwright/src/smartui.js b/packages/playwright/src/smartui.js index dfe7070..42f2088 100644 --- a/packages/playwright/src/smartui.js +++ b/packages/playwright/src/smartui.js @@ -22,7 +22,7 @@ async function smartuiSnapshot(page, snapshotName, options) { }), {}); // Post the DOM to the snapshot endpoint with snapshot options and other info - await utils.postSnapshot({ + let { body } = await utils.postSnapshot({ dom, url: page.url(), name: snapshotName, @@ -30,6 +30,8 @@ async function smartuiSnapshot(page, snapshotName, options) { }, pkgName); log.info(`Snapshot captured: ${snapshotName}`); + + if (body && body.data && body.data.warnings?.length !== 0) body.data.warnings.map(e => log.warn(e)); } catch (err) { throw err; } diff --git a/packages/puppeteer/src/smartui.js b/packages/puppeteer/src/smartui.js index 89cce64..8a4a598 100644 --- a/packages/puppeteer/src/smartui.js +++ b/packages/puppeteer/src/smartui.js @@ -24,7 +24,7 @@ async function smartuiSnapshot(page, name, options = {}) { // Post it to the SmartUI server. - await utils.postSnapshot({ + let { body } = await utils.postSnapshot({ dom, url, name, @@ -32,6 +32,8 @@ async function smartuiSnapshot(page, 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); } diff --git a/packages/testcafe/src/smartui.js b/packages/testcafe/src/smartui.js index 48d3824..f7ecc18 100644 --- a/packages/testcafe/src/smartui.js +++ b/packages/testcafe/src/smartui.js @@ -23,7 +23,7 @@ async function smartuiSnapshot(t, snapshotName, options) { url: window.location.href || document.URL, }), { boundTestRun: t, dependencies: {} }); - await utils.postSnapshot({ + let { body } = await utils.postSnapshot({ dom: dom, url, name: snapshotName, @@ -31,6 +31,8 @@ async function smartuiSnapshot(t, snapshotName, options) { }, pkgName); log.info(`Snapshot captured: ${snapshotName}`); + + if (body && body.data && body.data.warnings?.length !== 0) body.data.warnings.map(e => log.warn(e)); } catch (error) { // Handle errors throw error; From ac83b1cf5da0244e038b74aded5cf519e83f1bc0 Mon Sep 17 00:00:00 2001 From: Pinank Solanki Date: Wed, 31 Jan 2024 18:20:52 +0530 Subject: [PATCH 7/8] Remove default smartui server address --- packages/playwright/src/smartui.js | 10 +++++----- packages/puppeteer/src/smartui.js | 4 ++-- packages/sdk-utils/src/lib/utils.js | 3 ++- packages/selenium-driver/src/smartui.js | 4 ++-- packages/testcafe/src/smartui.js | 10 +++++----- 5 files changed, 16 insertions(+), 15 deletions(-) diff --git a/packages/playwright/src/smartui.js b/packages/playwright/src/smartui.js index 42f2088..dee3068 100644 --- a/packages/playwright/src/smartui.js +++ b/packages/playwright/src/smartui.js @@ -2,10 +2,10 @@ 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) { +async function smartuiSnapshot(page, name, 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.'); + 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); @@ -25,11 +25,11 @@ async function smartuiSnapshot(page, snapshotName, options) { let { body } = await utils.postSnapshot({ dom, url: page.url(), - name: snapshotName, + name, options }, pkgName); - log.info(`Snapshot captured: ${snapshotName}`); + log.info(`Snapshot captured: ${name}`); if (body && body.data && body.data.warnings?.length !== 0) body.data.warnings.map(e => log.warn(e)); } catch (err) { diff --git a/packages/puppeteer/src/smartui.js b/packages/puppeteer/src/smartui.js index 8a4a598..4072d36 100644 --- a/packages/puppeteer/src/smartui.js +++ b/packages/puppeteer/src/smartui.js @@ -4,8 +4,8 @@ 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.'); + 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); diff --git a/packages/sdk-utils/src/lib/utils.js b/packages/sdk-utils/src/lib/utils.js index 1e43008..8fc031a 100644 --- a/packages/sdk-utils/src/lib/utils.js +++ b/packages/sdk-utils/src/lib/utils.js @@ -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 = { diff --git a/packages/selenium-driver/src/smartui.js b/packages/selenium-driver/src/smartui.js index a2b3803..a2d34fc 100644 --- a/packages/selenium-driver/src/smartui.js +++ b/packages/selenium-driver/src/smartui.js @@ -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 { diff --git a/packages/testcafe/src/smartui.js b/packages/testcafe/src/smartui.js index f7ecc18..3a57b2c 100644 --- a/packages/testcafe/src/smartui.js +++ b/packages/testcafe/src/smartui.js @@ -1,10 +1,10 @@ const utils = require('@lambdatest/sdk-utils'); const pkgName = require('../package.json').name; -async function smartuiSnapshot(t, snapshotName, options) { +async function smartuiSnapshot(t, name, 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.'); + 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); @@ -26,11 +26,11 @@ async function smartuiSnapshot(t, snapshotName, options) { let { body } = await utils.postSnapshot({ dom: dom, url, - name: snapshotName, + name, options }, pkgName); - log.info(`Snapshot captured: ${snapshotName}`); + log.info(`Snapshot captured: ${name}`); if (body && body.data && body.data.warnings?.length !== 0) body.data.warnings.map(e => log.warn(e)); } catch (error) { From f20e7b765c597a9cfcf832321fee9d7690b4d4f9 Mon Sep 17 00:00:00 2001 From: Pinank Solanki Date: Thu, 1 Feb 2024 00:00:13 +0530 Subject: [PATCH 8/8] Bump version --- packages/playwright/package.json | 2 +- packages/puppeteer/package.json | 2 +- packages/sdk-utils/package.json | 2 +- packages/selenium-driver/package.json | 2 +- packages/testcafe/package.json | 2 +- 5 files changed, 5 insertions(+), 5 deletions(-) diff --git a/packages/playwright/package.json b/packages/playwright/package.json index f5f296d..5ecea02 100644 --- a/packages/playwright/package.json +++ b/packages/playwright/package.json @@ -1,6 +1,6 @@ { "name": "@lambdatest/playwright-driver", - "version": "1.0.0", + "version": "1.0.3", "description": "Playwright SDK for smart UI", "main": "index.js", "scripts": { diff --git a/packages/puppeteer/package.json b/packages/puppeteer/package.json index 7329460..f302dd8 100644 --- a/packages/puppeteer/package.json +++ b/packages/puppeteer/package.json @@ -1,6 +1,6 @@ { "name": "@lambdatest/puppeteer-driver", - "version": "1.0.0", + "version": "1.0.3", "description": "Puppeteer SDK for smart UI", "main": "index.js", "scripts": { diff --git a/packages/sdk-utils/package.json b/packages/sdk-utils/package.json index b08c71d..053b186 100644 --- a/packages/sdk-utils/package.json +++ b/packages/sdk-utils/package.json @@ -1,6 +1,6 @@ { "name": "@lambdatest/sdk-utils", - "version": "1.0.2", + "version": "1.0.3", "description": "", "main": "index.js", "repository": { diff --git a/packages/selenium-driver/package.json b/packages/selenium-driver/package.json index 9a47669..53898da 100644 --- a/packages/selenium-driver/package.json +++ b/packages/selenium-driver/package.json @@ -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": { diff --git a/packages/testcafe/package.json b/packages/testcafe/package.json index c8b1441..02c92a2 100644 --- a/packages/testcafe/package.json +++ b/packages/testcafe/package.json @@ -1,6 +1,6 @@ { "name": "@lambdatest/testcafe-driver", - "version": "1.0.0", + "version": "1.0.3", "description": "Testcafe SDK for LambdaTest smart UI", "repository": { "type": "git",