@lambdatest/smartui-cli 3.0.2 → 3.0.4

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.
@@ -332,32 +332,35 @@
332
332
  for (let video of dom.querySelectorAll('video')) {
333
333
  let videoId = video.getAttribute('data-smartui-element-id');
334
334
  let cloneEl = clone.querySelector(`[data-smartui-element-id="${videoId}"]`);
335
- // if the video already has a poster image, no work for us to do
336
- if (video.getAttribute('poster')) {
337
- cloneEl.removeAttribute('src');
338
- continue;
339
- }
340
- let canvas = document.createElement('canvas');
341
- let width = canvas.width = video.videoWidth;
342
- let height = canvas.height = video.videoHeight;
343
- let dataUrl;
344
- canvas.getContext('2d').drawImage(video, 0, 0, width, height);
345
- try {
346
- dataUrl = canvas.toDataURL();
347
- } catch (e) {
348
- warnings.add(`data-smartui-element-id="${videoId}" : ${e.toString()}`);
349
- }
350
335
 
351
- // if the canvas produces a blank image, skip
352
- if (!dataUrl || dataUrl === 'data:,') continue;
336
+ // remove video sources
337
+ cloneEl.removeAttribute('src');
338
+ const sourceEls = cloneEl.querySelectorAll('source');
339
+ if (sourceEls.length) sourceEls.forEach((sourceEl) => sourceEl.remove());
340
+
341
+ // if the video doesn't have a poster image
342
+ if (!video.getAttribute('poster')) {
343
+ let canvas = document.createElement('canvas');
344
+ let width = canvas.width = video.videoWidth;
345
+ let height = canvas.height = video.videoHeight;
346
+ let dataUrl;
347
+ canvas.getContext('2d').drawImage(video, 0, 0, width, height);
348
+ try {
349
+ dataUrl = canvas.toDataURL();
350
+ } catch (e) {
351
+ warnings.add(`data-smartui-element-id="${videoId}" : ${e.toString()}`);
352
+ }
353
353
 
354
- // create a resource from the serialized data url
355
- // let resource = resourceFromDataURL(videoId, dataUrl);
356
- // resources.add(resource);
354
+ // if the canvas produces a blank image, skip
355
+ if (!dataUrl || dataUrl === 'data:,') continue;
357
356
 
358
- // use a data attribute to avoid making a real request
359
- cloneEl.removeAttribute('src');
360
- cloneEl.setAttribute('poster', dataUrl);
357
+ // create a resource from the serialized data url
358
+ let resource = resourceFromDataURL(videoId, dataUrl);
359
+ resources.add(resource);
360
+
361
+ // set poster attribute to resource url to avoid making a real request
362
+ cloneEl.setAttribute('poster', resource.url);
363
+ }
361
364
  }
362
365
  }
363
366
 
package/dist/index.cjs CHANGED
@@ -114,6 +114,11 @@ var constants_default = {
114
114
  EDGE: "edge",
115
115
  EDGE_CHANNEL: "msedge",
116
116
  WEBKIT: "webkit",
117
+ // user agents
118
+ CHROME_USER_AGENT: "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/123.0.6312.107 Safari/537.3",
119
+ FIREFOX_USER_AGENT: "Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:112.0) Gecko/20100101 Firefox/112.0",
120
+ SAFARI_USER_AGENT: "Mozilla/5.0 (Macintosh; Intel Mac OS X 13_3) AppleWebKit/605.1.15 (KHTML, like Gecko) Version/16.4 Safari/605.1.15",
121
+ EDGE_USER_AGENT: "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/113.0.0.0 Safari/537.36 Edg/113.0.1774.35",
117
122
  // viewports
118
123
  MIN_VIEWPORT_HEIGHT: 1080,
119
124
  // mobile
@@ -421,13 +426,16 @@ var processSnapshot_default = (snapshot, ctx) => __async(void 0, null, function*
421
426
  ctx.log.debug(`Processing snapshot ${snapshot.name}`);
422
427
  if (!ctx.browser)
423
428
  ctx.browser = yield test.chromium.launch({ headless: true });
424
- const context = yield ctx.browser.newContext();
429
+ const context = yield ctx.browser.newContext({ userAgent: constants_default.CHROME_USER_AGENT });
425
430
  const page = yield context.newPage();
426
431
  let cache = {};
427
432
  yield page.route("**/*", (route, request) => __async(void 0, null, function* () {
428
433
  const requestUrl = request.url();
429
434
  const requestHostname = new URL(requestUrl).hostname;
430
435
  try {
436
+ if (/\.(mp3|mp4|wav|ogg|webm)$/i.test(request.url())) {
437
+ throw new Error("resource type mp3/mp4/wav/ogg/webm");
438
+ }
431
439
  ctx.config.allowedHostnames.push(new URL(snapshot.url).hostname);
432
440
  if (ctx.config.enableJavaScript)
433
441
  ALLOWED_RESOURCES.push("script");
@@ -534,14 +542,21 @@ var processSnapshot_default = (snapshot, ctx) => __async(void 0, null, function*
534
542
  yield page.setViewportSize({ width: viewport.width, height: viewport.height || MIN_VIEWPORT_HEIGHT });
535
543
  ctx.log.debug(`Page resized to ${viewport.width}x${viewport.height || MIN_VIEWPORT_HEIGHT}`);
536
544
  if (!navigated) {
537
- yield page.goto(snapshot.url);
545
+ yield page.goto(snapshot.url, { waitUntil: "domcontentloaded" });
546
+ yield new Promise((r) => setTimeout(r, 1250));
547
+ if (ctx.config.waitForTimeout)
548
+ yield page.waitForTimeout(ctx.config.waitForTimeout);
538
549
  navigated = true;
539
550
  ctx.log.debug(`Navigated to ${snapshot.url}`);
540
551
  }
541
552
  if (fullPage)
542
553
  yield page.evaluate(scrollToBottomAndBackToTop);
543
- yield page.waitForLoadState("networkidle");
544
- ctx.log.debug("Network idle 500ms");
554
+ try {
555
+ yield page.waitForLoadState("networkidle", { timeout: 5e3 });
556
+ ctx.log.debug("Network idle 500ms");
557
+ } catch (error) {
558
+ ctx.log.debug(`Network idle failed due to ${error}`);
559
+ }
545
560
  if (processedOptions.element) {
546
561
  let l = yield page.locator(processedOptions.element).all();
547
562
  if (l.length === 0) {
@@ -575,6 +590,14 @@ var processSnapshot_default = (snapshot, ctx) => __async(void 0, null, function*
575
590
  }
576
591
  yield page.close();
577
592
  yield context.close();
593
+ if (snapshot.dom.resources.length) {
594
+ for (let resource of snapshot.dom.resources) {
595
+ cache[resource.url] = {
596
+ body: resource.content,
597
+ type: resource.mimetype
598
+ };
599
+ }
600
+ }
578
601
  return {
579
602
  processedSnapshot: {
580
603
  name: snapshot.name,
@@ -975,7 +998,7 @@ var auth_default = (ctx) => {
975
998
  };
976
999
 
977
1000
  // package.json
978
- var version = "3.0.2";
1001
+ var version = "3.0.4";
979
1002
  var package_default = {
980
1003
  name: "@lambdatest/smartui-cli",
981
1004
  version,
@@ -1436,10 +1459,19 @@ function captureScreenshotsForConfig(_0, _1, _2, _3, _4) {
1436
1459
  let pageOptions = { waitUntil: process.env.SMARTUI_PAGE_WAIT_UNTIL_EVENT || "load" };
1437
1460
  let ssId = name.toLowerCase().replace(/\s/g, "_");
1438
1461
  let context;
1462
+ let contextOptions = {};
1439
1463
  let page;
1464
+ if (browserName == constants_default.CHROME)
1465
+ contextOptions.userAgent = constants_default.CHROME_USER_AGENT;
1466
+ else if (browserName == constants_default.FIREFOX)
1467
+ contextOptions.userAgent = constants_default.FIREFOX_USER_AGENT;
1468
+ else if (browserName == constants_default.SAFARI)
1469
+ contextOptions.userAgent = constants_default.SAFARI_USER_AGENT;
1470
+ else if (browserName == constants_default.EDGE)
1471
+ contextOptions.userAgent = constants_default.EDGE_USER_AGENT;
1440
1472
  try {
1441
1473
  const browser = browsers[browserName];
1442
- context = yield browser == null ? void 0 : browser.newContext();
1474
+ context = yield browser == null ? void 0 : browser.newContext(contextOptions);
1443
1475
  page = yield context == null ? void 0 : context.newPage();
1444
1476
  yield page == null ? void 0 : page.goto(url.trim(), pageOptions);
1445
1477
  for (let { viewport, viewportString, fullPage } of renderViewports) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@lambdatest/smartui-cli",
3
- "version": "3.0.2",
3
+ "version": "3.0.4",
4
4
  "description": "A command line interface (CLI) to run SmartUI tests on LambdaTest",
5
5
  "files": [
6
6
  "dist/**/*"