Skip to content

Commit 57204b3

Browse files
authored
Merge pull request #385 from LambdaTest/stage
Release PR: 4.1.35
2 parents f425d4a + d756b06 commit 57204b3

File tree

7 files changed

+67
-5
lines changed

7 files changed

+67
-5
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.34",
3+
"version": "4.1.35",
44
"description": "A command line interface (CLI) to run SmartUI tests on LambdaTest",
55
"files": [
66
"dist/**/*"

src/commander/uploadPdf.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ command
1414
.argument('<directory>', 'Path of the directory containing PDFs')
1515
.option('--fetch-results [filename]', 'Fetch results and optionally specify an output file, e.g., <filename>.json')
1616
.option('--buildName <string>', 'Specify the build name')
17+
.option('--markBaseline', 'Mark this build baseline')
1718
.action(async function(directory, _, command) {
1819
const options = command.optsWithGlobals();
1920
if (options.buildName === '') {

src/lib/httpClient.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -675,6 +675,9 @@ export default class httpClient {
675675
if (ctx.build.name !== undefined && ctx.build.name !== '') {
676676
form.append('buildName', buildName);
677677
}
678+
if (ctx.options.markBaseline) {
679+
form.append('markBaseline', ctx.options.markBaseline.toString());
680+
}
678681

679682
try {
680683
const response = await this.axiosInstance.request({

src/lib/processSnapshot.ts

Lines changed: 42 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -243,6 +243,47 @@ export default async function processSnapshot(snapshot: Snapshot, ctx: Context):
243243
ctx.log.debug('No valid cookies to add');
244244
}
245245
}
246+
247+
let options = snapshot.options;
248+
249+
// Custom cookies include those which cannot be captured by javascript function `document.cookie` like httpOnly, secure, sameSite etc.
250+
// These custom cookies will be captured by the user in their automation browser and sent to CLI through the snapshot options using `customCookies` field.
251+
if (options?.customCookies && Array.isArray(options.customCookies) && options.customCookies.length > 0) {
252+
ctx.log.debug(`Setting ${options.customCookies.length} custom cookies`);
253+
254+
const validCustomCookies = options.customCookies.filter(cookie => {
255+
if (!cookie.name || !cookie.value || !cookie.domain) {
256+
ctx.log.debug(`Skipping invalid custom cookie: missing required fields (name, value, or domain)`);
257+
return false;
258+
}
259+
260+
if (cookie.sameSite && !['Strict', 'Lax', 'None'].includes(cookie.sameSite)) {
261+
ctx.log.debug(`Skipping invalid custom cookie: invalid sameSite value '${cookie.sameSite}'`);
262+
return false;
263+
}
264+
265+
return true;
266+
}).map(cookie => ({
267+
name: cookie.name,
268+
value: cookie.value,
269+
domain: cookie.domain,
270+
path: cookie.path || '/',
271+
httpOnly: cookie.httpOnly || false,
272+
secure: cookie.secure || false,
273+
sameSite: cookie.sameSite || 'Lax'
274+
}));
275+
276+
if (validCustomCookies.length > 0) {
277+
try {
278+
await context.addCookies(validCustomCookies);
279+
ctx.log.debug(`Successfully added ${validCustomCookies.length} custom cookies`);
280+
} catch (error) {
281+
ctx.log.debug(`Failed to add custom cookies: ${error}`);
282+
}
283+
} else {
284+
ctx.log.debug('No valid custom cookies to add');
285+
}
286+
}
246287
const page = await context.newPage();
247288

248289
// populate cache with already captured resources
@@ -415,8 +456,6 @@ export default async function processSnapshot(snapshot: Snapshot, ctx: Context):
415456
route.abort();
416457
}
417458
});
418-
419-
let options = snapshot.options;
420459
let optionWarnings: Set<string> = new Set();
421460
let selectors: Array<string> = [];
422461
let ignoreOrSelectDOM: string;
@@ -582,6 +621,7 @@ export default async function processSnapshot(snapshot: Snapshot, ctx: Context):
582621
// adding extra timeout since domcontentloaded event is fired pretty quickly
583622
await new Promise(r => setTimeout(r, 1250));
584623
if (ctx.config.waitForTimeout) await page.waitForTimeout(ctx.config.waitForTimeout);
624+
await page.waitForLoadState("networkidle", { timeout: 10000 }).catch(() => { ctx.log.debug('networkidle event failed to fire within 10s') });
585625
navigated = true;
586626
ctx.log.debug(`Navigated to ${snapshot.url}`);
587627
} catch (error: any) {
@@ -815,7 +855,6 @@ export default async function processSnapshot(snapshot: Snapshot, ctx: Context):
815855

816856
if (hasBrowserErrors) {
817857
discoveryErrors.timestamp = new Date().toISOString();
818-
// ctx.log.warn(discoveryErrors);
819858
}
820859

821860
if (ctx.config.useGlobalCache) {

src/lib/schemaValidation.ts

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -582,6 +582,14 @@ const SnapshotSchema: JSONSchemaType<Snapshot> = {
582582
minimum: 0,
583583
maximum: 100,
584584
errorMessage: "Invalid snapshot options; rejectionThreshold must be a number between 0 and 100"
585+
},
586+
customCookies: {
587+
type: "array",
588+
items: {
589+
type: "object",
590+
minProperties: 1,
591+
},
592+
errorMessage: "Invalid snapshot options; customCookies must be an array of objects with string properties"
585593
}
586594
},
587595
additionalProperties: false

src/lib/utils.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -545,7 +545,7 @@ export function startPdfPolling(ctx: Context) {
545545
try {
546546
const response = await ctx.client.fetchPdfResults(ctx);
547547

548-
if (response.screenshots) {
548+
if (response.screenshots && response.build?.build_status === constants.BUILD_COMPLETE) {
549549
clearInterval(interval);
550550

551551
const pdfGroups = groupScreenshotsByPdf(response.screenshots);

src/types.ts

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -164,6 +164,7 @@ export interface Snapshot {
164164
useExtendedViewport?: boolean;
165165
approvalThreshold?: number;
166166
rejectionThreshold?: number;
167+
customCookies?: CustomCookie[];
167168
}
168169
}
169170

@@ -251,6 +252,16 @@ export interface FigmaWebConfig {
251252
configs: Array<{ figma_file_token: string, figma_ids: Array<string>, screenshot_names:Array<string> }>;
252253
}
253254

255+
export interface CustomCookie {
256+
name: string;
257+
value: string;
258+
domain: string;
259+
path: string;
260+
httpOnly: boolean;
261+
secure: boolean;
262+
sameSite: 'Strict' | 'Lax' | 'None';
263+
}
264+
254265

255266
export interface ViewportErrors {
256267
statusCode: "aborted" | "404" | string;

0 commit comments

Comments
 (0)