Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 7 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@lambdatest/smartui-cli",
"version": "4.1.63",
"version": "4.1.64-shri",
"description": "A command line interface (CLI) to run SmartUI tests on LambdaTest",
"files": [
"dist/**/*"
Expand All @@ -20,6 +20,9 @@
"smartui",
"cli"
],
"engines": {
"node": ">=20"
},
"author": "LambdaTest <keys@lambdatest.com>",
"license": "MIT",
"dependencies": {
Expand All @@ -43,6 +46,7 @@
"json-stringify-safe": "^5.0.1",
"listr2": "^7.0.1",
"node-cache": "^5.1.2",
"pnpm": "^10.33.0",
"postcss": "^8.5.6",
"sharp": "^0.33.4",
"uuid": "^11.0.3",
Expand All @@ -54,7 +58,7 @@
},
"devDependencies": {
"find-free-port": "^2.0.0",
"typescript": "^5.3.2",
"tsup": "^8.5.1"
"tsup": "^8.5.1",
"typescript": "^5.3.2"
}
}
35 changes: 35 additions & 0 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

41 changes: 10 additions & 31 deletions src/lib/httpClient.ts
Original file line number Diff line number Diff line change
Expand Up @@ -841,38 +841,17 @@ export default class httpClient {
}

async fetchPdfResults(ctx: Context): Promise<any> {
const params: Record<string, string> = {};

if (ctx.build.projectId) {
params.project_id = ctx.build.projectId;
} else {
throw new Error('Project ID not found to fetch PDF results');
}
params.build_id = ctx.build.id;

const auth = Buffer.from(`${this.username}:${this.accessKey}`).toString('base64');

try {
const response = await axios.request({
url: ctx.env.SMARTUI_UPLOAD_URL + '/smartui/2.0/build/screenshots',
method: 'GET',
params: params,
headers: {
'accept': 'application/json',
'Authorization': `Basic ${auth}`
}
});

ctx.log.debug(`http response: ${JSON.stringify({
status: response.status,
headers: response.headers,
body: response.data
})}`);
const params: Record<string, any> = {
buildId: ctx.build.id,
baseline: false,
buildName: ''
};

return response.data;
} catch (error: any) {
this.handleHttpError(error, ctx.log);
}
return this.request({
url: '/screenshot',
method: 'GET',
params,
}, ctx.log);
}
}

47 changes: 21 additions & 26 deletions src/lib/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -644,44 +644,39 @@ export function startPdfPolling(ctx: Context) {
try {
const response = await ctx.client.fetchPdfResults(ctx);

if (response.screenshots && response.build?.build_status !== constants.BUILD_RUNNING) {
if (response.screenshots && response.build?.build_status_ind !== constants.BUILD_RUNNING) {
clearInterval(interval);

const pdfGroups = groupScreenshotsByPdf(response.screenshots);
const pdfsWithMismatches = countPdfsWithMismatches(pdfGroups);
const pagesWithMismatches = countPagesWithMismatches(response.screenshots);

console.log(chalk.green('\n✓ PDF Test Results:'));
console.log(chalk.green(`Build Name: ${response.build.name}`));
console.log(chalk.green(`Project Name: ${response.project.name}`));
console.log(chalk.green(`Total PDFs: ${Object.keys(pdfGroups).length}`));
console.log(chalk.green(`Total Pages: ${response.screenshots.length}`));
// Flatten screenshots object into array, filtering to only PDF screenshots
const allScreenshots = Array.isArray(response.screenshots)
? response.screenshots
: Object.values(response.screenshots).flat();
const screenshotsArray = allScreenshots.filter(
(s: any) => s.browser_name?.endsWith('.pdf')
);

if (pdfsWithMismatches > 0 || pagesWithMismatches > 0) {
console.log(chalk.yellow(`${pdfsWithMismatches} PDFs and ${pagesWithMismatches} Pages in build ${response.build.name} have changes present.`));
} else {
console.log(chalk.green('All PDFs match the baseline.'));
}
const pdfGroups = groupScreenshotsByPdf(screenshotsArray);

Object.entries(pdfGroups).forEach(([pdfName, pages]) => {
const hasMismatch = pages.some(page => page.mismatch_percentage > 0);
const hasMismatch = pages.some(page => page.status !== 'Approved' && page.status !== 'new');
const statusColor = hasMismatch ? chalk.yellow : chalk.green;

console.log(statusColor(`\n📄 ${pdfName} (${pages.length} pages)`));

pages.forEach(page => {
const pageStatusColor = page.mismatch_percentage > 0 ? chalk.yellow : chalk.green;
console.log(pageStatusColor(` - Page ${getPageNumber(page.screenshot_name)}: ${page.status} (Mismatch: ${page.mismatch_percentage}%)`));
const pageStatusColor = page.status !== 'Approved' && page.status !== 'new' ? chalk.yellow : chalk.green;
const mismatchInfo = page.mismatch_percentage != null ? ` (Mismatch: ${page.mismatch_percentage}%)` : '';
console.log(pageStatusColor(` - Page ${getPageNumber(page.screenshot_name)}: ${page.status}${mismatchInfo}`));
});
});

const formattedResults = {
status: 'success',
data: {
buildId: response.build.id,
buildName: response.build.name,
buildId: response.build.build_id,
buildName: response.build.build_name,
projectName: response.project.name,
buildStatus: response.build.build_satus,
buildStatus: response.build.build_status,
pdfs: formatPdfsForOutput(pdfGroups)
}
};
Expand Down Expand Up @@ -742,7 +737,7 @@ function countPdfsWithMismatches(pdfGroups: Record<string, any[]>): number {
let count = 0;

Object.values(pdfGroups).forEach(pages => {
if (pages.some(page => page.mismatch_percentage > 0)) {
if (pages.some(page => page.status !== 'Approved' && page.status !== 'new')) {
count++;
}
});
Expand All @@ -751,7 +746,7 @@ function countPdfsWithMismatches(pdfGroups: Record<string, any[]>): number {
}

function countPagesWithMismatches(screenshots: any[]): number {
return screenshots.filter(screenshot => screenshot.mismatch_percentage > 0).length;
return screenshots.filter(screenshot => screenshot.status !== 'Approved' && screenshot.status !== 'new').length;
}

function formatPdfsForOutput(pdfGroups: Record<string, any[]>): any[] {
Expand All @@ -761,10 +756,10 @@ function formatPdfsForOutput(pdfGroups: Record<string, any[]>): any[] {
pageCount: pages.length,
pages: pages.map(page => ({
pageNumber: getPageNumber(page.screenshot_name),
screenshotId: page.captured_image_id,
mismatchPercentage: page.mismatch_percentage,
screenshotId: page.captured_image,
...(page.mismatch_percentage != null && { mismatchPercentage: page.mismatch_percentage }),
status: page.status,
screenshotUrl: page.shareable_link
screenshotUrl: page.captured_image
}))
};
});
Expand Down