@lambdatest/smartui-cli 4.1.29 → 4.1.30

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 +105 -1
  2. package/package.json +1 -1
package/dist/index.cjs CHANGED
@@ -904,6 +904,12 @@ var SnapshotSchema = {
904
904
  items: { type: "string", minLength: 1 },
905
905
  uniqueItems: true,
906
906
  errorMessage: "Invalid snapshot options; ignoreDOM xpath array must have unique and non-empty items"
907
+ },
908
+ coordinates: {
909
+ type: "array",
910
+ items: { type: "string", minLength: 1 },
911
+ uniqueItems: true,
912
+ errorMessage: "Invalid snapshot options; ignoreDOM coordinates array must have unique and non-empty items"
907
913
  }
908
914
  }
909
915
  },
@@ -933,6 +939,12 @@ var SnapshotSchema = {
933
939
  items: { type: "string", minLength: 1 },
934
940
  uniqueItems: true,
935
941
  errorMessage: "Invalid snapshot options; selectDOM xpath array must have unique and non-empty items"
942
+ },
943
+ coordinates: {
944
+ type: "array",
945
+ items: { type: "string", minLength: 1 },
946
+ uniqueItems: true,
947
+ errorMessage: "Invalid snapshot options; selectDOM coordinates array must have unique and non-empty items"
936
948
  }
937
949
  }
938
950
  },
@@ -1840,6 +1852,56 @@ function getPageNumber(screenshotName) {
1840
1852
  const parts = screenshotName.split("#");
1841
1853
  return parts.length > 1 ? parts[1] : "1";
1842
1854
  }
1855
+ function validateCoordinates(coordString, pageHeight, pageWidth, snapshotName) {
1856
+ const coords = coordString.split(",").map(Number);
1857
+ if (coords.length !== 4) {
1858
+ return {
1859
+ valid: false,
1860
+ error: `for snapshot ${snapshotName}, invalid coordinates format: ${coordString}. Expected: top,bottom,left,right`
1861
+ };
1862
+ }
1863
+ const [top, bottom, left, right] = coords;
1864
+ if (coords.some(isNaN)) {
1865
+ return {
1866
+ valid: false,
1867
+ error: `for snapshot ${snapshotName}, invalid coordinate values: ${coordString}. All values must be numbers`
1868
+ };
1869
+ }
1870
+ if (top < 0 || left < 0 || bottom < 0 || right < 0) {
1871
+ return {
1872
+ valid: false,
1873
+ error: `for snapshot ${snapshotName}, invalid coordinate bounds: ${coordString}. top,left,bottom,right must be >= 0`
1874
+ };
1875
+ }
1876
+ if (top >= bottom) {
1877
+ return {
1878
+ valid: false,
1879
+ error: `for snapshot ${snapshotName}, invalid coordinate bounds: ${coordString}. top must be < bottom`
1880
+ };
1881
+ }
1882
+ if (left >= right) {
1883
+ return {
1884
+ valid: false,
1885
+ error: `for snapshot ${snapshotName}, invalid coordinate bounds: ${coordString}. left must be < right`
1886
+ };
1887
+ }
1888
+ if (bottom > pageHeight) {
1889
+ return {
1890
+ valid: false,
1891
+ error: `for snapshot ${snapshotName}, coordinates exceed viewport bounds: ${coordString}. bottom (${bottom}) exceeds viewport height (${pageHeight})`
1892
+ };
1893
+ }
1894
+ if (right > pageWidth) {
1895
+ return {
1896
+ valid: false,
1897
+ error: `for snapshot ${snapshotName}, coordinates exceed viewport bounds: ${coordString}. right (${right}) exceeds viewport width (${pageWidth})`
1898
+ };
1899
+ }
1900
+ return {
1901
+ valid: true,
1902
+ coords: { top, bottom, left, right }
1903
+ };
1904
+ }
1843
1905
 
1844
1906
  // src/lib/server.ts
1845
1907
  var uploadDomToS3ViaEnv = process.env.USE_LAMBDA_INTERNAL || false;
@@ -2221,7 +2283,7 @@ var authExec_default = (ctx) => {
2221
2283
  };
2222
2284
 
2223
2285
  // package.json
2224
- var version = "4.1.29";
2286
+ var version = "4.1.30";
2225
2287
  var package_default = {
2226
2288
  name: "@lambdatest/smartui-cli",
2227
2289
  version,
@@ -3578,6 +3640,9 @@ function prepareSnapshot(snapshot, ctx) {
3578
3640
  case "cssSelector":
3579
3641
  selectors.push(...value);
3580
3642
  break;
3643
+ case "coordinates":
3644
+ selectors.push(...value.map((e) => `coordinates=${e}`));
3645
+ break;
3581
3646
  }
3582
3647
  }
3583
3648
  }
@@ -3920,6 +3985,9 @@ function processSnapshot(snapshot, ctx) {
3920
3985
  case "cssSelector":
3921
3986
  selectors.push(...value);
3922
3987
  break;
3988
+ case "coordinates":
3989
+ selectors.push(...value.map((e) => `coordinates=${e}`));
3990
+ break;
3923
3991
  }
3924
3992
  }
3925
3993
  }
@@ -4057,6 +4125,31 @@ function processSnapshot(snapshot, ctx) {
4057
4125
  if (!Array.isArray(processedOptions[ignoreOrSelectBoxes][viewportString]))
4058
4126
  processedOptions[ignoreOrSelectBoxes][viewportString] = [];
4059
4127
  for (const selector of selectors) {
4128
+ if (selector.startsWith("coordinates=")) {
4129
+ const coordString = selector.replace("coordinates=", "");
4130
+ let pageHeight = height;
4131
+ if (viewport.height) {
4132
+ pageHeight = viewport.height;
4133
+ }
4134
+ const validation = validateCoordinates(
4135
+ coordString,
4136
+ pageHeight,
4137
+ viewport.width,
4138
+ snapshot.name
4139
+ );
4140
+ if (!validation.valid) {
4141
+ optionWarnings.add(validation.error);
4142
+ continue;
4143
+ }
4144
+ if (renderViewports.length > 1) {
4145
+ optionWarnings.add(`for snapshot ${snapshot.name} viewport ${viewportString}, coordinates may not be accurate for multiple viewports`);
4146
+ }
4147
+ const coordinateElement = __spreadValues({
4148
+ type: "coordinates"
4149
+ }, validation.coords);
4150
+ locators.push(coordinateElement);
4151
+ continue;
4152
+ }
4060
4153
  let l = yield page.locator(selector).all();
4061
4154
  if (l.length === 0) {
4062
4155
  optionWarnings.add(`for snapshot ${snapshot.name} viewport ${viewportString}, no element found for selector ${selector}`);
@@ -4065,6 +4158,17 @@ function processSnapshot(snapshot, ctx) {
4065
4158
  locators.push(...l);
4066
4159
  }
4067
4160
  for (const locator of locators) {
4161
+ if (locator && typeof locator === "object" && locator.hasOwnProperty("type") && locator.type === "coordinates") {
4162
+ const coordLocator = locator;
4163
+ const { top, bottom, left, right } = coordLocator;
4164
+ processedOptions[ignoreOrSelectBoxes][viewportString].push({
4165
+ left,
4166
+ top,
4167
+ right,
4168
+ bottom
4169
+ });
4170
+ continue;
4171
+ }
4068
4172
  let bb = yield locator.boundingBox();
4069
4173
  if (bb) {
4070
4174
  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.30",
4
4
  "description": "A command line interface (CLI) to run SmartUI tests on LambdaTest",
5
5
  "files": [
6
6
  "dist/**/*"