@lambdatest/smartui-cli 4.1.29 → 4.1.31

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (2) hide show
  1. package/dist/index.cjs +143 -2
  2. package/package.json +1 -1
package/dist/index.cjs CHANGED
@@ -779,6 +779,14 @@ var ConfigSchema = {
779
779
  useLambdaInternal: {
780
780
  type: "boolean",
781
781
  errorMessage: "Invalid config; useLambdaInternal must be true/false"
782
+ },
783
+ useExtendedViewport: {
784
+ type: "boolean",
785
+ errorMessage: "Invalid config; useExtendedViewport must be true/false"
786
+ },
787
+ loadDomContent: {
788
+ type: "boolean",
789
+ errorMessage: "Invalid config; loadDomContent must be true/false"
782
790
  }
783
791
  },
784
792
  anyOf: [
@@ -904,6 +912,12 @@ var SnapshotSchema = {
904
912
  items: { type: "string", minLength: 1 },
905
913
  uniqueItems: true,
906
914
  errorMessage: "Invalid snapshot options; ignoreDOM xpath array must have unique and non-empty items"
915
+ },
916
+ coordinates: {
917
+ type: "array",
918
+ items: { type: "string", minLength: 1 },
919
+ uniqueItems: true,
920
+ errorMessage: "Invalid snapshot options; ignoreDOM coordinates array must have unique and non-empty items"
907
921
  }
908
922
  }
909
923
  },
@@ -933,6 +947,12 @@ var SnapshotSchema = {
933
947
  items: { type: "string", minLength: 1 },
934
948
  uniqueItems: true,
935
949
  errorMessage: "Invalid snapshot options; selectDOM xpath array must have unique and non-empty items"
950
+ },
951
+ coordinates: {
952
+ type: "array",
953
+ items: { type: "string", minLength: 1 },
954
+ uniqueItems: true,
955
+ errorMessage: "Invalid snapshot options; selectDOM coordinates array must have unique and non-empty items"
936
956
  }
937
957
  }
938
958
  },
@@ -1024,6 +1044,10 @@ var SnapshotSchema = {
1024
1044
  timeout: {
1025
1045
  type: "number",
1026
1046
  errorMessage: "Invalid snapshot options; timeout must be a number"
1047
+ },
1048
+ useExtendedViewport: {
1049
+ type: "boolean",
1050
+ errorMessage: "Invalid snapshot options; useExtendedViewport must be a boolean"
1027
1051
  }
1028
1052
  },
1029
1053
  additionalProperties: false
@@ -1840,6 +1864,56 @@ function getPageNumber(screenshotName) {
1840
1864
  const parts = screenshotName.split("#");
1841
1865
  return parts.length > 1 ? parts[1] : "1";
1842
1866
  }
1867
+ function validateCoordinates(coordString, pageHeight, pageWidth, snapshotName) {
1868
+ const coords = coordString.split(",").map(Number);
1869
+ if (coords.length !== 4) {
1870
+ return {
1871
+ valid: false,
1872
+ error: `for snapshot ${snapshotName}, invalid coordinates format: ${coordString}. Expected: top,bottom,left,right`
1873
+ };
1874
+ }
1875
+ const [top, bottom, left, right] = coords;
1876
+ if (coords.some(isNaN)) {
1877
+ return {
1878
+ valid: false,
1879
+ error: `for snapshot ${snapshotName}, invalid coordinate values: ${coordString}. All values must be numbers`
1880
+ };
1881
+ }
1882
+ if (top < 0 || left < 0 || bottom < 0 || right < 0) {
1883
+ return {
1884
+ valid: false,
1885
+ error: `for snapshot ${snapshotName}, invalid coordinate bounds: ${coordString}. top,left,bottom,right must be >= 0`
1886
+ };
1887
+ }
1888
+ if (top >= bottom) {
1889
+ return {
1890
+ valid: false,
1891
+ error: `for snapshot ${snapshotName}, invalid coordinate bounds: ${coordString}. top must be < bottom`
1892
+ };
1893
+ }
1894
+ if (left >= right) {
1895
+ return {
1896
+ valid: false,
1897
+ error: `for snapshot ${snapshotName}, invalid coordinate bounds: ${coordString}. left must be < right`
1898
+ };
1899
+ }
1900
+ if (bottom > pageHeight) {
1901
+ return {
1902
+ valid: false,
1903
+ error: `for snapshot ${snapshotName}, coordinates exceed viewport bounds: ${coordString}. bottom (${bottom}) exceeds viewport height (${pageHeight})`
1904
+ };
1905
+ }
1906
+ if (right > pageWidth) {
1907
+ return {
1908
+ valid: false,
1909
+ error: `for snapshot ${snapshotName}, coordinates exceed viewport bounds: ${coordString}. right (${right}) exceeds viewport width (${pageWidth})`
1910
+ };
1911
+ }
1912
+ return {
1913
+ valid: true,
1914
+ coords: { top, bottom, left, right }
1915
+ };
1916
+ }
1843
1917
 
1844
1918
  // src/lib/server.ts
1845
1919
  var uploadDomToS3ViaEnv = process.env.USE_LAMBDA_INTERNAL || false;
@@ -2221,7 +2295,7 @@ var authExec_default = (ctx) => {
2221
2295
  };
2222
2296
 
2223
2297
  // package.json
2224
- var version = "4.1.29";
2298
+ var version = "4.1.31";
2225
2299
  var package_default = {
2226
2300
  name: "@lambdatest/smartui-cli",
2227
2301
  version,
@@ -2949,6 +3023,8 @@ var ctx_default = (options) => {
2949
3023
  let buildNameObj;
2950
3024
  let allowDuplicateSnapshotNames = false;
2951
3025
  let useLambdaInternal = false;
3026
+ let useExtendedViewport = false;
3027
+ let loadDomContent = false;
2952
3028
  try {
2953
3029
  if (options.config) {
2954
3030
  config = JSON.parse(fs5__default.default.readFileSync(options.config, "utf-8"));
@@ -3016,6 +3092,12 @@ var ctx_default = (options) => {
3016
3092
  if (config.useLambdaInternal) {
3017
3093
  useLambdaInternal = true;
3018
3094
  }
3095
+ if (config.useExtendedViewport) {
3096
+ useExtendedViewport = true;
3097
+ }
3098
+ if (config.loadDomContent) {
3099
+ loadDomContent = true;
3100
+ }
3019
3101
  if (config.waitForPageRender && config.waitForPageRender < 3e4) {
3020
3102
  config.waitForPageRender = 3e4;
3021
3103
  }
@@ -3044,7 +3126,9 @@ var ctx_default = (options) => {
3044
3126
  userAgent: config.userAgent || "",
3045
3127
  requestHeaders: config.requestHeaders || {},
3046
3128
  allowDuplicateSnapshotNames,
3047
- useLambdaInternal
3129
+ useLambdaInternal,
3130
+ useExtendedViewport,
3131
+ loadDomContent
3048
3132
  },
3049
3133
  uploadFilePath: "",
3050
3134
  webStaticConfig: [],
@@ -3510,6 +3594,9 @@ function prepareSnapshot(snapshot, ctx) {
3510
3594
  if (options.loadDomContent) {
3511
3595
  processedOptions.loadDomContent = true;
3512
3596
  }
3597
+ if (options.useExtendedViewport) {
3598
+ processedOptions.useExtendedViewport = true;
3599
+ }
3513
3600
  if (options.sessionId) {
3514
3601
  const sessionId = options.sessionId;
3515
3602
  processedOptions.sessionId = sessionId;
@@ -3578,6 +3665,9 @@ function prepareSnapshot(snapshot, ctx) {
3578
3665
  case "cssSelector":
3579
3666
  selectors.push(...value);
3580
3667
  break;
3668
+ case "coordinates":
3669
+ selectors.push(...value.map((e) => `coordinates=${e}`));
3670
+ break;
3581
3671
  }
3582
3672
  }
3583
3673
  }
@@ -3592,6 +3682,12 @@ function prepareSnapshot(snapshot, ctx) {
3592
3682
  ctx.log.debug(`Tunnel address added to processedOptions: ${tunnelAddress}`);
3593
3683
  }
3594
3684
  }
3685
+ if (ctx.config.loadDomContent) {
3686
+ processedOptions.loadDomContent = true;
3687
+ }
3688
+ if (ctx.config.useExtendedViewport) {
3689
+ processedOptions.useExtendedViewport = true;
3690
+ }
3595
3691
  processedOptions.allowedAssets = ctx.config.allowedAssets;
3596
3692
  processedOptions.selectors = selectors;
3597
3693
  processedOptions.ignoreDOM = options == null ? void 0 : options.ignoreDOM;
@@ -3920,6 +4016,9 @@ function processSnapshot(snapshot, ctx) {
3920
4016
  case "cssSelector":
3921
4017
  selectors.push(...value);
3922
4018
  break;
4019
+ case "coordinates":
4020
+ selectors.push(...value.map((e) => `coordinates=${e}`));
4021
+ break;
3923
4022
  }
3924
4023
  }
3925
4024
  }
@@ -3934,6 +4033,12 @@ function processSnapshot(snapshot, ctx) {
3934
4033
  ctx.log.debug(`Tunnel address added to processedOptions: ${tunnelAddress}`);
3935
4034
  }
3936
4035
  }
4036
+ if (ctx.config.loadDomContent) {
4037
+ processedOptions.loadDomContent = true;
4038
+ }
4039
+ if (ctx.config.useExtendedViewport) {
4040
+ processedOptions.useExtendedViewport = true;
4041
+ }
3937
4042
  let navigated = false;
3938
4043
  let previousDeviceType = null;
3939
4044
  let renderViewports;
@@ -4057,6 +4162,31 @@ function processSnapshot(snapshot, ctx) {
4057
4162
  if (!Array.isArray(processedOptions[ignoreOrSelectBoxes][viewportString]))
4058
4163
  processedOptions[ignoreOrSelectBoxes][viewportString] = [];
4059
4164
  for (const selector of selectors) {
4165
+ if (selector.startsWith("coordinates=")) {
4166
+ const coordString = selector.replace("coordinates=", "");
4167
+ let pageHeight = height;
4168
+ if (viewport.height) {
4169
+ pageHeight = viewport.height;
4170
+ }
4171
+ const validation = validateCoordinates(
4172
+ coordString,
4173
+ pageHeight,
4174
+ viewport.width,
4175
+ snapshot.name
4176
+ );
4177
+ if (!validation.valid) {
4178
+ optionWarnings.add(validation.error);
4179
+ continue;
4180
+ }
4181
+ if (renderViewports.length > 1) {
4182
+ optionWarnings.add(`for snapshot ${snapshot.name} viewport ${viewportString}, coordinates may not be accurate for multiple viewports`);
4183
+ }
4184
+ const coordinateElement = __spreadValues({
4185
+ type: "coordinates"
4186
+ }, validation.coords);
4187
+ locators.push(coordinateElement);
4188
+ continue;
4189
+ }
4060
4190
  let l = yield page.locator(selector).all();
4061
4191
  if (l.length === 0) {
4062
4192
  optionWarnings.add(`for snapshot ${snapshot.name} viewport ${viewportString}, no element found for selector ${selector}`);
@@ -4065,6 +4195,17 @@ function processSnapshot(snapshot, ctx) {
4065
4195
  locators.push(...l);
4066
4196
  }
4067
4197
  for (const locator of locators) {
4198
+ if (locator && typeof locator === "object" && locator.hasOwnProperty("type") && locator.type === "coordinates") {
4199
+ const coordLocator = locator;
4200
+ const { top, bottom, left, right } = coordLocator;
4201
+ processedOptions[ignoreOrSelectBoxes][viewportString].push({
4202
+ left,
4203
+ top,
4204
+ right,
4205
+ bottom
4206
+ });
4207
+ continue;
4208
+ }
4068
4209
  let bb = yield locator.boundingBox();
4069
4210
  if (bb) {
4070
4211
  const top = bb.y;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@lambdatest/smartui-cli",
3
- "version": "4.1.29",
3
+ "version": "4.1.31",
4
4
  "description": "A command line interface (CLI) to run SmartUI tests on LambdaTest",
5
5
  "files": [
6
6
  "dist/**/*"