@lambdatest/smartui-cli 4.0.22 → 4.1.0

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 +54 -6
  2. package/package.json +1 -1
package/dist/index.cjs CHANGED
@@ -638,6 +638,17 @@ var WebStaticConfigSchema = {
638
638
  minimum: 0,
639
639
  maximum: 3e4,
640
640
  errorMessage: "waitForTimeout must be > 0 and <= 30000"
641
+ },
642
+ execute: {
643
+ type: "object",
644
+ properties: {
645
+ afterNavigation: {
646
+ type: "string"
647
+ },
648
+ beforeSnapshot: {
649
+ type: "string"
650
+ }
651
+ }
641
652
  }
642
653
  },
643
654
  required: ["name", "url"],
@@ -1389,6 +1400,9 @@ var logger = winston.createLogger({
1389
1400
  case "warn":
1390
1401
  message = chalk__default.default.yellow(message);
1391
1402
  break;
1403
+ case "error":
1404
+ message = chalk__default.default.red(message);
1405
+ break;
1392
1406
  }
1393
1407
  return info.level === "info" ? message : `[${contextString}:${info.level}] ` + message;
1394
1408
  })
@@ -1451,7 +1465,7 @@ var auth_default = (ctx) => {
1451
1465
  };
1452
1466
 
1453
1467
  // package.json
1454
- var version = "4.0.22";
1468
+ var version = "4.1.0";
1455
1469
  var package_default = {
1456
1470
  name: "@lambdatest/smartui-cli",
1457
1471
  version,
@@ -2910,8 +2924,12 @@ configWebFigma.name("config:create-figma-web").description("Create figma config
2910
2924
  createWebFigmaConfig(filepath);
2911
2925
  });
2912
2926
  });
2913
- function captureScreenshotsForConfig(_0, _1, _2, _3, _4) {
2914
- return __async(this, arguments, function* (ctx, browsers, { name, url, waitForTimeout }, browserName, renderViewports) {
2927
+ function captureScreenshotsForConfig(ctx, browsers, urlConfig, browserName, renderViewports) {
2928
+ return __async(this, null, function* () {
2929
+ ctx.log.debug(`*** urlConfig ${JSON.stringify(urlConfig)}`);
2930
+ let { name, url, waitForTimeout, execute } = urlConfig;
2931
+ let afterNavigationScript = execute == null ? void 0 : execute.afterNavigation;
2932
+ let beforeSnapshotScript = execute == null ? void 0 : execute.beforeSnapshot;
2915
2933
  let pageOptions = { waitUntil: process.env.SMARTUI_PAGE_WAIT_UNTIL_EVENT || "load", timeout: ctx.config.waitForPageRender || constants_default.DEFAULT_PAGE_LOAD_TIMEOUT };
2916
2934
  let ssId = name.toLowerCase().replace(/\s/g, "_");
2917
2935
  let context;
@@ -2930,12 +2948,14 @@ function captureScreenshotsForConfig(_0, _1, _2, _3, _4) {
2930
2948
  context = yield browser == null ? void 0 : browser.newContext(contextOptions);
2931
2949
  page = yield context == null ? void 0 : context.newPage();
2932
2950
  yield page == null ? void 0 : page.goto(url.trim(), pageOptions);
2951
+ yield executeDocumentScripts(ctx, page, "afterNavigation", afterNavigationScript);
2933
2952
  for (let { viewport, viewportString, fullPage } of renderViewports) {
2934
2953
  let ssPath = `screenshots/${ssId}/${`${browserName}-${viewport.width}x${viewport.height}`}-${ssId}.png`;
2935
2954
  yield page == null ? void 0 : page.setViewportSize({ width: viewport.width, height: viewport.height || constants_default.MIN_VIEWPORT_HEIGHT });
2936
2955
  if (fullPage)
2937
2956
  yield page == null ? void 0 : page.evaluate(scrollToBottomAndBackToTop);
2938
2957
  yield page == null ? void 0 : page.waitForTimeout(waitForTimeout || 0);
2958
+ yield executeDocumentScripts(ctx, page, "beforeSnapshot", beforeSnapshotScript);
2939
2959
  yield page == null ? void 0 : page.screenshot({ path: ssPath, fullPage });
2940
2960
  yield ctx.client.uploadScreenshot(ctx.build, ssPath, name, browserName, viewportString, ctx.log);
2941
2961
  }
@@ -3012,7 +3032,7 @@ function captureScreenshots(ctx) {
3012
3032
  ctx.task.output = output;
3013
3033
  capturedScreenshots++;
3014
3034
  } catch (error) {
3015
- ctx.log.debug(`screenshot capture failed for ${JSON.stringify(staticConfig)}; error: ${error}`);
3035
+ ctx.log.debug(`captureScreenshots failed for ${JSON.stringify(staticConfig)}; error: ${error}`);
3016
3036
  output += `${chalk__default.default.gray(staticConfig.name)} ${chalk__default.default.red("\u2717")}
3017
3037
  `;
3018
3038
  ctx.task.output = output;
@@ -3207,6 +3227,23 @@ function processChunk(ctx, urlConfig) {
3207
3227
  return { capturedScreenshots, finalOutput };
3208
3228
  });
3209
3229
  }
3230
+ function executeDocumentScripts(ctx, page, actionType, script) {
3231
+ return __async(this, null, function* () {
3232
+ try {
3233
+ if (!page) {
3234
+ throw new Error("Page instance not available");
3235
+ }
3236
+ if (script !== "") {
3237
+ yield page.evaluate((script2) => {
3238
+ new Function(script2)();
3239
+ }, script);
3240
+ }
3241
+ } catch (error) {
3242
+ ctx.log.error(`Error executing script for action ${actionType}: `, error);
3243
+ throw error;
3244
+ }
3245
+ });
3246
+ }
3210
3247
  var captureScreenshots_default = (ctx) => {
3211
3248
  return {
3212
3249
  title: "Capturing screenshots",
@@ -3244,6 +3281,7 @@ var captureScreenshots_default = (ctx) => {
3244
3281
  var command2 = new commander.Command();
3245
3282
  command2.name("capture").description("Capture screenshots of static sites").argument("<file>", "Web static config file").option("-C, --parallel [number]", "Specify the number of instances per browser", parseInt).option("-F, --force", "forcefully apply the specified parallel instances per browser").option("--fetch-results [filename]", "Fetch results and optionally specify an output file, e.g., <filename>.json").option("--buildName <string>", "Specify the build name").action(function(file, _, command7) {
3246
3283
  return __async(this, null, function* () {
3284
+ var _a, _b;
3247
3285
  const options = command7.optsWithGlobals();
3248
3286
  if (options.buildName === "") {
3249
3287
  console.log(`Error: The '--buildName' option cannot be an empty string.`);
@@ -3256,8 +3294,18 @@ command2.name("capture").description("Capture screenshots of static sites").argu
3256
3294
  }
3257
3295
  try {
3258
3296
  ctx.webStaticConfig = JSON.parse(fs6__default.default.readFileSync(file, "utf8"));
3259
- if (!validateWebStaticConfig(ctx.webStaticConfig))
3260
- throw new Error(validateWebStaticConfig.errors[0].message);
3297
+ if (!validateWebStaticConfig(ctx.webStaticConfig)) {
3298
+ ctx.log.debug(JSON.stringify(validateWebStaticConfig.errors, null, 2));
3299
+ (_a = validateWebStaticConfig.errors) == null ? void 0 : _a.forEach((error) => {
3300
+ if (error.keyword === "additionalProperties") {
3301
+ ctx.log.warn(`Additional property "${error.params.additionalProperty}" is not allowed.`);
3302
+ } else {
3303
+ const validationError = error.message;
3304
+ throw new Error(validationError || "Invalid Web Static config found in file : " + file);
3305
+ }
3306
+ });
3307
+ throw new Error((_b = validateWebStaticConfig.errors[0]) == null ? void 0 : _b.message);
3308
+ }
3261
3309
  if (ctx.webStaticConfig && ctx.webStaticConfig.length === 0) {
3262
3310
  ctx.log.error(`No URLs found in the specified config file -> ${file}`);
3263
3311
  return;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@lambdatest/smartui-cli",
3
- "version": "4.0.22",
3
+ "version": "4.1.0",
4
4
  "description": "A command line interface (CLI) to run SmartUI tests on LambdaTest",
5
5
  "files": [
6
6
  "dist/**/*"