Skip to content

Commit 33655b6

Browse files
Merge pull request #461 from LambdaTest/stage
Stage
2 parents 66f93e5 + bc92cd6 commit 33655b6

File tree

2 files changed

+31
-2
lines changed

2 files changed

+31
-2
lines changed

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@lambdatest/smartui-cli",
3-
"version": "4.1.53",
3+
"version": "4.1.54-beta.0",
44
"description": "A command line interface (CLI) to run SmartUI tests on LambdaTest",
55
"files": [
66
"dist/**/*"

src/lib/screenshot.ts

Lines changed: 30 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,17 @@ import constants from './constants.js'
77
import chalk from 'chalk';
88
import sharp from 'sharp';
99

10+
async function humanLikeScroll(page: Page) {
11+
// Move mouse in human like manner
12+
await page.waitForTimeout(2000);
13+
await page.mouse.move(100, 100);
14+
await page.waitForTimeout(300);
15+
await page.mouse.move(300, 200);
16+
await page.waitForTimeout(300);
17+
await page.mouse.move(500, 300);
18+
await page.waitForTimeout(2000);
19+
}
20+
1021
async function captureScreenshotsForConfig(
1122
ctx: Context,
1223
browsers: Record<string, Browser>,
@@ -253,7 +264,25 @@ async function captureScreenshotsForConfig(
253264
}
254265
let ssPath = `screenshots/${ssId}/${`${browserName}-${viewport.width}x${viewport.height}`}-${ssId}.png`;
255266
await page?.setViewportSize({ width: viewport.width, height: viewport.height || constants.MIN_VIEWPORT_HEIGHT });
256-
if (fullPage) await page?.evaluate(utils.scrollToBottomAndBackToTop);
267+
// again load page to apply viewport size properly
268+
await page?.goto(url.trim(), pageOptions);
269+
ctx.log.debug(`Capturing screenshot for URL: ${url} on ${browserName} with viewport: ${viewportString} (fullPage: ${fullPage})`);
270+
if (page && ctx.config.lazyLoadConfiguration) {
271+
await humanLikeScroll(page);
272+
}
273+
if (fullPage) {
274+
if (ctx.config.lazyLoadConfiguration && ctx.config.lazyLoadConfiguration.enabled) {
275+
let stepValue = ctx.config.lazyLoadConfiguration.scrollStep || 250;
276+
let delayValue = ctx.config.lazyLoadConfiguration.scrollDelay || 300;
277+
let maxScrollsValue = ctx.config.lazyLoadConfiguration.maxScrolls || 50;
278+
let jumpBackToTopValue = ctx.config.lazyLoadConfiguration.jumpBackToTop !== false;
279+
ctx.log.debug('Capture: Starting lazy load scrolling with configuration: ' + JSON.stringify({ step: stepValue, delay: delayValue, maxScrolls: maxScrollsValue, jumpBackToTop: jumpBackToTopValue }));
280+
await page?.evaluate(utils.smoothScrollToBottom, { step: stepValue, delay: delayValue, maxScrolls: maxScrollsValue, jumpBackToTop: jumpBackToTopValue });
281+
ctx.log.debug('Capture: Completed lazy load scrolling');
282+
} else {
283+
await page?.evaluate(utils.scrollToBottomAndBackToTop, { frequency: 100, timing: ctx.config.scrollTime });
284+
}
285+
}
257286
await page?.waitForTimeout(waitForTimeout || 0);
258287
await executeDocumentScripts(ctx, page, "beforeSnapshot", beforeSnapshotScript)
259288

0 commit comments

Comments
 (0)