Skip to content

Commit 56f2a56

Browse files
committed
testcafe changes
1 parent d840d32 commit 56f2a56

File tree

3 files changed

+81
-0
lines changed

3 files changed

+81
-0
lines changed

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: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
{
2+
"name": "@lambdatest/testcafe-driver",
3+
"version": "1.0.0",
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+
},
9+
"main": "index.js",
10+
"scripts": {
11+
"build": "gulp build",
12+
"test": "gulp test"
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+
"devDependencies": {
26+
"testcafe": "^3.4.0"
27+
},
28+
"peerDependencies": {
29+
"testcafe": ">=1"
30+
},
31+
"dependencies": {
32+
"@lambdatest/sdk-utils": "workspace:^"
33+
}
34+
}

packages/testcafe/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+
async function smartuiSnapshot(t, snapshotName, options) {
5+
if (!t) throw new Error("The test function's `t` argument is required.");
6+
if (!snapshotName) throw new Error('The `name` argument is required.');
7+
if (!(await utils.isSmartUIRunning())) throw new Error('SmartUI server is not running.');
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+
await utils.postSnapshot({
27+
dom: dom,
28+
url,
29+
name: snapshotName,
30+
options
31+
}, pkgName);
32+
33+
log.info(`Snapshot captured: ${snapshotName}`);
34+
} catch (error) {
35+
// Handle errors
36+
throw error;
37+
}
38+
}
39+
40+
module.exports = {
41+
smartuiSnapshot
42+
}

0 commit comments

Comments
 (0)