-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #23 from LambdaTest/stage
Release v1.0.3
- Loading branch information
Showing
13 changed files
with
252 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
const { smartuiSnapshot } = require('./src/smartui'); | ||
|
||
module.exports = { | ||
smartuiSnapshot | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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:^" | ||
} | ||
|
||
} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
const { smartuiSnapshot } = require('./src/smartui'); | ||
|
||
module.exports = { | ||
smartuiSnapshot | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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:^" | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
const { smartuiSnapshot } = require('./src/smartui'); | ||
|
||
module.exports = { | ||
smartuiSnapshot | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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:^" | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
} |