Skip to content

Commit f341562

Browse files
authored
Merge pull request #116 from LambdaTest/stage
Release 4.0.1
2 parents b931883 + baf394b commit f341562

File tree

8 files changed

+86
-51
lines changed

8 files changed

+86
-51
lines changed

package.json

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@lambdatest/smartui-cli",
3-
"version": "4.0.0",
3+
"version": "4.0.1",
44
"description": "A command line interface (CLI) to run SmartUI tests on LambdaTest",
55
"files": [
66
"dist/**/*"
@@ -21,10 +21,10 @@
2121
"author": "LambdaTest <[email protected]>",
2222
"license": "MIT",
2323
"dependencies": {
24-
"@playwright/browser-chromium": "^1.40.1",
25-
"@playwright/browser-firefox": "^1.40.1",
26-
"@playwright/browser-webkit": "^1.40.1",
27-
"@playwright/test": "^1.40.1",
24+
"@playwright/browser-chromium": "^1.45.3",
25+
"@playwright/browser-firefox": "^1.45.3",
26+
"@playwright/browser-webkit": "^1.45.3",
27+
"@playwright/test": "^1.45.3",
2828
"@types/cross-spawn": "^6.0.4",
2929
"@types/node": "^20.8.9",
3030
"@types/which": "^3.0.2",

pnpm-lock.yaml

Lines changed: 37 additions & 37 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/lib/constants.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,9 @@ export default {
7171
FILE_EXTENSION_ZIP: '.zip',
7272
FILE_EXTENSION_GIFS: 'gif',
7373

74+
// Default scrollTime
75+
DEFAULT_SCROLL_TIME: 8,
76+
7477
// Magic Numbers
7578
MAGIC_NUMBERS: [
7679
{ ext: 'jpg', magic: Buffer.from([0xFF, 0xD8, 0xFF]) },

src/lib/ctx.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,8 @@ export default (options: Record<string, string>): Context => {
6767
waitForPageRender: config.waitForPageRender || 0,
6868
waitForTimeout: config.waitForTimeout || 0,
6969
enableJavaScript: config.enableJavaScript || false,
70+
cliEnableJavaScript: config.cliEnableJavaScript || true,
71+
scrollTime: config.scrollTime || constants.DEFAULT_SCROLL_TIME,
7072
allowedHostnames: config.allowedHostnames || []
7173
},
7274
uploadFilePath: '',

src/lib/processSnapshot.ts

Lines changed: 21 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import { Snapshot, Context, ProcessedSnapshot } from "../types.js";
22
import { scrollToBottomAndBackToTop, getRenderViewports } from "./utils.js"
3-
import { firefox, Locator } from "@playwright/test"
3+
import { chromium, Locator } from "@playwright/test"
44
import constants from "./constants.js";
55
import { updateLogContext } from '../lib/logger.js'
66

@@ -82,13 +82,13 @@ async function processSnapshot(snapshot: Snapshot, ctx: Context): Promise<Record
8282

8383
let launchOptions: Record<string, any> = { headless: true }
8484
let contextOptions: Record<string, any> = {
85-
javaScriptEnabled: ctx.config.enableJavaScript,
85+
javaScriptEnabled: ctx.config.cliEnableJavaScript,
8686
userAgent: constants.CHROME_USER_AGENT,
8787
}
8888
if (!ctx.browser?.isConnected()) {
8989
if (ctx.env.HTTP_PROXY || ctx.env.HTTPS_PROXY) launchOptions.proxy = { server: ctx.env.HTTP_PROXY || ctx.env.HTTPS_PROXY };
90-
ctx.browser = await firefox.launch(launchOptions);
91-
ctx.log.debug(`Firefox launched with options ${JSON.stringify(launchOptions)}`);
90+
ctx.browser = await chromium.launch(launchOptions);
91+
ctx.log.debug(`Chromium launched with options ${JSON.stringify(launchOptions)}`);
9292
}
9393
const context = await ctx.browser.newContext(contextOptions);
9494
ctx.log.debug(`Browser context created with options ${JSON.stringify(contextOptions)}`);
@@ -198,8 +198,21 @@ async function processSnapshot(snapshot: Snapshot, ctx: Context): Promise<Record
198198

199199
// process for every viewport
200200
let navigated: boolean = false;
201+
let previousDeviceType: string | null = null;
201202
let renderViewports = getRenderViewports(ctx);
202-
for (const { viewport, viewportString, fullPage } of renderViewports) {
203+
204+
for (const { viewport, viewportString, fullPage, device } of renderViewports) {
205+
206+
// Check if this is the first iteration or if the device type has changed from the previous iteration
207+
if (previousDeviceType !== null && previousDeviceType !== device) {
208+
// If the device type has changed, reset `navigated` to false
209+
// This indicates that we haven't navigated to the required page for the new device type yet
210+
navigated = false;
211+
}
212+
213+
// Update `previousDeviceType` to the current device type for comparison in the next iteration
214+
previousDeviceType = device;
215+
203216
await page.setViewportSize({ width: viewport.width, height: viewport.height || MIN_VIEWPORT_HEIGHT });
204217
ctx.log.debug(`Page resized to ${viewport.width}x${viewport.height || MIN_VIEWPORT_HEIGHT}`);
205218

@@ -219,14 +232,16 @@ async function processSnapshot(snapshot: Snapshot, ctx: Context): Promise<Record
219232
}
220233

221234
}
222-
if (ctx.config.enableJavaScript && fullPage) await page.evaluate(scrollToBottomAndBackToTop);
235+
if (ctx.config.cliEnableJavaScript && fullPage) await page.evaluate(scrollToBottomAndBackToTop, { frequency: 100, timing: ctx.config.scrollTime });
223236

224237
try {
225238
await page.waitForLoadState('networkidle', { timeout: 5000 });
226239
ctx.log.debug('Network idle 500ms');
227240
} catch (error) {
228241
ctx.log.debug(`Network idle failed due to ${error}`);
229242
}
243+
244+
await new Promise(r => setTimeout(r, 1000));
230245

231246
// snapshot options
232247
if (processedOptions.element) {

src/lib/schemaValidation.ts

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -109,6 +109,16 @@ const ConfigSchema = {
109109
type: "boolean",
110110
errorMessage: "Invalid config; enableJavaScript must be true/false"
111111
},
112+
cliEnableJavaScript: {
113+
type: "boolean",
114+
errorMessage: "Invalid config; cliEnableJavaScript must be true/false"
115+
},
116+
scrollTime: {
117+
type: "number",
118+
minimum: 1,
119+
maximum: 1000,
120+
errorMessage: "Invalid config; scrollTime must be > 1 and <= 1000"
121+
},
112122
allowedHostnames: {
113123
type: "array",
114124
items: {

src/lib/utils.ts

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -118,10 +118,13 @@ export function getMobileRenderViewports(ctx: Context): Record<string,any> {
118118
}
119119

120120
export function getRenderViewports(ctx: Context): Array<Record<string,any>> {
121-
let mobileRenderViewports = getMobileRenderViewports(ctx)
121+
let mobileRenderViewports = getMobileRenderViewports(ctx);
122+
let webRenderViewports = getWebRenderViewports(ctx);
123+
124+
// Combine arrays ensuring web viewports are first
122125
return [
123-
...getWebRenderViewports(ctx),
126+
...webRenderViewports,
124127
...mobileRenderViewports[constants.MOBILE_OS_IOS],
125128
...mobileRenderViewports[constants.MOBILE_OS_ANDROID]
126129
];
127-
}
130+
}

src/types.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,8 @@ export interface Context {
2020
waitForPageRender: number;
2121
waitForTimeout: number;
2222
enableJavaScript: boolean;
23+
cliEnableJavaScript: boolean;
24+
scrollTime: number;
2325
allowedHostnames: Array<string>;
2426
};
2527
uploadFilePath: string;

0 commit comments

Comments
 (0)