Skip to content

Commit a2646bc

Browse files
Merge pull request #58 from LambdaTest/revert-54-revert-53-DOT-5046/cli-sync-changes
Revert "Revert "added sync param in options for cli""
2 parents 02682a6 + 9cb05b1 commit a2646bc

File tree

7 files changed

+51
-12
lines changed

7 files changed

+51
-12
lines changed

packages/sdk-utils/index.js

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,10 @@
1-
const { isSmartUIRunning, fetchDOMSerializer, postSnapshot } = require('./src/smartui');
1+
const { isSmartUIRunning, fetchDOMSerializer, postSnapshot, getSnapshotStatus } = require('./src/smartui');
22
const logger = require('./src/lib/logger');
33

44
module.exports = {
55
logger,
66
fetchDOMSerializer,
77
postSnapshot,
8-
isSmartUIRunning
8+
isSmartUIRunning,
9+
getSnapshotStatus
910
}

packages/sdk-utils/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@lambdatest/sdk-utils",
3-
"version": "1.0.7",
3+
"version": "1.0.8",
44
"description": "LambdaTest driver utils",
55
"main": "index.js",
66
"repository": {

packages/sdk-utils/src/lib/httpClient.js

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,4 +47,17 @@ module.exports = new class httpClient {
4747
}
4848
})
4949
}
50+
51+
getSnapshotStatus(contextId, snapshotName, pollTimeout) {
52+
return this.request({
53+
url: `${utils.getSmartUIServerAddress()}/snapshot/status`,
54+
method: 'GET',
55+
params: {
56+
contextId: contextId,
57+
snapshotName: snapshotName,
58+
pollTimeout: pollTimeout
59+
}
60+
});
61+
}
62+
5063
};

packages/sdk-utils/src/smartui.js

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -36,8 +36,18 @@ async function postSnapshot(snapshot, testType) {
3636
}
3737
}
3838

39+
async function getSnapshotStatus(contextId,snapshotName,pollTimeout=600) {
40+
try {
41+
return await client.getSnapshotStatus(contextId,snapshotName,pollTimeout);
42+
} catch (error) {
43+
log.debug(error);
44+
throw new Error(`get snapshot status failed; ${error.message}`);
45+
}
46+
}
47+
3948
module.exports = {
4049
isSmartUIRunning,
4150
fetchDOMSerializer,
42-
postSnapshot
43-
}
51+
postSnapshot,
52+
getSnapshotStatus
53+
}

packages/selenium/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@lambdatest/selenium-driver",
3-
"version": "1.0.7",
3+
"version": "1.0.8",
44
"description": "Selenium driver for all Lambdatest functionalities",
55
"main": "index.js",
66
"repository": {

packages/selenium/src/smartui.js

Lines changed: 20 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
const utils = require('@lambdatest/sdk-utils');
22
const pkgName = require('../package.json').name;
33
const testType = 'js-selenium-driver';
4+
const crypto = require('crypto');
45

56
async function smartuiSnapshot(driver, name, options = {}) {
67
if (!driver) throw new Error('An instance of the selenium driver object is required.');
@@ -24,11 +25,25 @@ async function smartuiSnapshot(driver, name, options = {}) {
2425
dom: SmartUIDOM.serialize(options),
2526
url: document.URL
2627
}), {});
27-
28-
let { body } = await utils.postSnapshot({url, name, dom, options}, pkgName);
29-
if (body && body.data && body.data.warnings?.length !== 0) body.data.warnings.map(e => log.warn(e));
30-
31-
log.info(`Snapshot captured: ${name}`);
28+
29+
if(options?.sync){
30+
options.contextId = crypto.randomUUID();
31+
let { body } = await utils.postSnapshot({url, name, dom, options}, pkgName);
32+
if (body && body.data && body.data.warnings?.length !== 0) body.data.warnings.map(e => log.warn(e));
33+
log.info(`Snapshot captured: ${name}`);
34+
let timeout = options?.timeout || 600;
35+
if(timeout<30||timeout>900){
36+
log.info(`Timeout value must be between 30 and 900 seconds. Using default value of 600 seconds.`);
37+
timeout = 600;
38+
}
39+
let snapshotStatus = await utils.getSnapshotStatus(options.contextId,name,timeout);
40+
return snapshotStatus.body;
41+
}
42+
else{
43+
let { body } = await utils.postSnapshot({url, name, dom, options}, pkgName);
44+
if (body && body.data && body.data.warnings?.length !== 0) body.data.warnings.map(e => log.warn(e));
45+
log.info(`Snapshot captured: ${name}`);
46+
}
3247
} catch (error) {
3348
log.error(`SmartUI snapshot failed "${name}"`);
3449
log.error(error);

pnpm-lock.yaml

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)