cbrowser 6.5.0 → 7.1.0
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.
- package/dist/browser.d.ts +63 -2
- package/dist/browser.d.ts.map +1 -1
- package/dist/browser.js +988 -0
- package/dist/browser.js.map +1 -1
- package/dist/cli.js +362 -2
- package/dist/cli.js.map +1 -1
- package/dist/types.d.ts +221 -13
- package/dist/types.d.ts.map +1 -1
- package/package.json +7 -3
package/dist/browser.js
CHANGED
|
@@ -41,6 +41,19 @@ exports.calculateCoverageAnalysis = calculateCoverageAnalysis;
|
|
|
41
41
|
exports.generateCoverageMap = generateCoverageMap;
|
|
42
42
|
exports.formatCoverageReport = formatCoverageReport;
|
|
43
43
|
exports.generateCoverageHtmlReport = generateCoverageHtmlReport;
|
|
44
|
+
exports.loadVisualBaselines = loadVisualBaselines;
|
|
45
|
+
exports.captureVisualBaseline = captureVisualBaseline;
|
|
46
|
+
exports.listVisualBaselines = listVisualBaselines;
|
|
47
|
+
exports.getVisualBaseline = getVisualBaseline;
|
|
48
|
+
exports.deleteVisualBaseline = deleteVisualBaseline;
|
|
49
|
+
exports.runVisualRegression = runVisualRegression;
|
|
50
|
+
exports.runVisualRegressionSuite = runVisualRegressionSuite;
|
|
51
|
+
exports.formatVisualRegressionReport = formatVisualRegressionReport;
|
|
52
|
+
exports.generateVisualRegressionHtmlReport = generateVisualRegressionHtmlReport;
|
|
53
|
+
exports.runCrossBrowserTest = runCrossBrowserTest;
|
|
54
|
+
exports.runCrossBrowserSuite = runCrossBrowserSuite;
|
|
55
|
+
exports.formatCrossBrowserReport = formatCrossBrowserReport;
|
|
56
|
+
exports.generateCrossBrowserHtmlReport = generateCrossBrowserHtmlReport;
|
|
44
57
|
const playwright_1 = require("playwright");
|
|
45
58
|
const fs_1 = require("fs");
|
|
46
59
|
const path_1 = require("path");
|
|
@@ -5212,4 +5225,979 @@ function generateCoverageProgressBar(percent, width = 30) {
|
|
|
5212
5225
|
const empty = width - filled;
|
|
5213
5226
|
return "█".repeat(filled) + "░".repeat(empty);
|
|
5214
5227
|
}
|
|
5228
|
+
// =========================================================================
|
|
5229
|
+
// Tier 7: AI Visual Regression (v7.0.0)
|
|
5230
|
+
// =========================================================================
|
|
5231
|
+
/**
|
|
5232
|
+
* Get the path to visual baselines storage
|
|
5233
|
+
*/
|
|
5234
|
+
function getVisualBaselinesPath() {
|
|
5235
|
+
const baseDir = process.env.CBROWSER_DATA_DIR || (0, path_1.join)(process.cwd(), ".cbrowser");
|
|
5236
|
+
const baselinesDir = (0, path_1.join)(baseDir, "visual-baselines");
|
|
5237
|
+
if (!(0, fs_1.existsSync)(baselinesDir)) {
|
|
5238
|
+
(0, fs_1.mkdirSync)(baselinesDir, { recursive: true });
|
|
5239
|
+
}
|
|
5240
|
+
return baselinesDir;
|
|
5241
|
+
}
|
|
5242
|
+
/**
|
|
5243
|
+
* Get the path to visual baseline screenshots
|
|
5244
|
+
*/
|
|
5245
|
+
function getVisualScreenshotsPath() {
|
|
5246
|
+
const baselinesDir = getVisualBaselinesPath();
|
|
5247
|
+
const screenshotsDir = (0, path_1.join)(baselinesDir, "screenshots");
|
|
5248
|
+
if (!(0, fs_1.existsSync)(screenshotsDir)) {
|
|
5249
|
+
(0, fs_1.mkdirSync)(screenshotsDir, { recursive: true });
|
|
5250
|
+
}
|
|
5251
|
+
return screenshotsDir;
|
|
5252
|
+
}
|
|
5253
|
+
/**
|
|
5254
|
+
* Load all visual baselines from storage
|
|
5255
|
+
*/
|
|
5256
|
+
function loadVisualBaselines() {
|
|
5257
|
+
const baselinesPath = getVisualBaselinesPath();
|
|
5258
|
+
const indexPath = (0, path_1.join)(baselinesPath, "baselines.json");
|
|
5259
|
+
if (!(0, fs_1.existsSync)(indexPath)) {
|
|
5260
|
+
return [];
|
|
5261
|
+
}
|
|
5262
|
+
try {
|
|
5263
|
+
const data = JSON.parse((0, fs_1.readFileSync)(indexPath, "utf-8"));
|
|
5264
|
+
return data.baselines || [];
|
|
5265
|
+
}
|
|
5266
|
+
catch {
|
|
5267
|
+
return [];
|
|
5268
|
+
}
|
|
5269
|
+
}
|
|
5270
|
+
/**
|
|
5271
|
+
* Save visual baselines to storage
|
|
5272
|
+
*/
|
|
5273
|
+
function saveVisualBaselines(baselines) {
|
|
5274
|
+
const baselinesPath = getVisualBaselinesPath();
|
|
5275
|
+
const indexPath = (0, path_1.join)(baselinesPath, "baselines.json");
|
|
5276
|
+
(0, fs_1.writeFileSync)(indexPath, JSON.stringify({ baselines, updated: new Date().toISOString() }, null, 2));
|
|
5277
|
+
}
|
|
5278
|
+
/**
|
|
5279
|
+
* Capture a visual baseline screenshot
|
|
5280
|
+
*/
|
|
5281
|
+
async function captureVisualBaseline(url, name, options = {}) {
|
|
5282
|
+
const browser = new CBrowser({
|
|
5283
|
+
device: options.device,
|
|
5284
|
+
viewportWidth: options.viewport?.width || 1920,
|
|
5285
|
+
viewportHeight: options.viewport?.height || 1080,
|
|
5286
|
+
});
|
|
5287
|
+
try {
|
|
5288
|
+
await browser.launch();
|
|
5289
|
+
await browser.navigate(url);
|
|
5290
|
+
// Wait if specified
|
|
5291
|
+
if (options.waitFor) {
|
|
5292
|
+
if (typeof options.waitFor === "number") {
|
|
5293
|
+
await new Promise(resolve => setTimeout(resolve, options.waitFor));
|
|
5294
|
+
}
|
|
5295
|
+
else {
|
|
5296
|
+
const page = await browser.getPage();
|
|
5297
|
+
await page.waitForSelector(options.waitFor, { timeout: 10000 }).catch(() => { });
|
|
5298
|
+
}
|
|
5299
|
+
}
|
|
5300
|
+
// Take screenshot
|
|
5301
|
+
const screenshotsPath = getVisualScreenshotsPath();
|
|
5302
|
+
const id = `${name.toLowerCase().replace(/[^a-z0-9]+/g, "-")}-${Date.now()}`;
|
|
5303
|
+
const screenshotPath = (0, path_1.join)(screenshotsPath, `${id}.png`);
|
|
5304
|
+
const page = await browser.getPage();
|
|
5305
|
+
if (options.selector) {
|
|
5306
|
+
const element = page.locator(options.selector).first();
|
|
5307
|
+
await element.screenshot({ path: screenshotPath });
|
|
5308
|
+
}
|
|
5309
|
+
else {
|
|
5310
|
+
await page.screenshot({ path: screenshotPath, fullPage: false });
|
|
5311
|
+
}
|
|
5312
|
+
// Get dimensions
|
|
5313
|
+
const viewport = page.viewportSize() || { width: 1920, height: 1080 };
|
|
5314
|
+
const baseline = {
|
|
5315
|
+
id,
|
|
5316
|
+
name,
|
|
5317
|
+
url,
|
|
5318
|
+
screenshotPath,
|
|
5319
|
+
dimensions: viewport,
|
|
5320
|
+
viewport,
|
|
5321
|
+
device: options.device,
|
|
5322
|
+
timestamp: new Date().toISOString(),
|
|
5323
|
+
selector: options.selector,
|
|
5324
|
+
};
|
|
5325
|
+
// Save to index
|
|
5326
|
+
const baselines = loadVisualBaselines();
|
|
5327
|
+
// Remove existing baseline with same name (update)
|
|
5328
|
+
const filtered = baselines.filter(b => b.name !== name);
|
|
5329
|
+
filtered.push(baseline);
|
|
5330
|
+
saveVisualBaselines(filtered);
|
|
5331
|
+
return baseline;
|
|
5332
|
+
}
|
|
5333
|
+
finally {
|
|
5334
|
+
await browser.close();
|
|
5335
|
+
}
|
|
5336
|
+
}
|
|
5337
|
+
/**
|
|
5338
|
+
* List all visual baselines
|
|
5339
|
+
*/
|
|
5340
|
+
function listVisualBaselines() {
|
|
5341
|
+
return loadVisualBaselines();
|
|
5342
|
+
}
|
|
5343
|
+
/**
|
|
5344
|
+
* Get a visual baseline by name
|
|
5345
|
+
*/
|
|
5346
|
+
function getVisualBaseline(name) {
|
|
5347
|
+
const baselines = loadVisualBaselines();
|
|
5348
|
+
return baselines.find(b => b.name === name);
|
|
5349
|
+
}
|
|
5350
|
+
/**
|
|
5351
|
+
* Delete a visual baseline
|
|
5352
|
+
*/
|
|
5353
|
+
function deleteVisualBaseline(name) {
|
|
5354
|
+
const baselines = loadVisualBaselines();
|
|
5355
|
+
const baseline = baselines.find(b => b.name === name);
|
|
5356
|
+
if (!baseline) {
|
|
5357
|
+
return false;
|
|
5358
|
+
}
|
|
5359
|
+
// Delete screenshot file
|
|
5360
|
+
if ((0, fs_1.existsSync)(baseline.screenshotPath)) {
|
|
5361
|
+
(0, fs_1.unlinkSync)(baseline.screenshotPath);
|
|
5362
|
+
}
|
|
5363
|
+
// Update index
|
|
5364
|
+
const filtered = baselines.filter(b => b.name !== name);
|
|
5365
|
+
saveVisualBaselines(filtered);
|
|
5366
|
+
return true;
|
|
5367
|
+
}
|
|
5368
|
+
/**
|
|
5369
|
+
* Analyze visual differences using AI
|
|
5370
|
+
*/
|
|
5371
|
+
async function analyzeVisualDifferences(baselinePath, currentPath, options = {}) {
|
|
5372
|
+
// Read both images as base64
|
|
5373
|
+
const baselineImage = (0, fs_1.readFileSync)(baselinePath).toString("base64");
|
|
5374
|
+
const currentImage = (0, fs_1.readFileSync)(currentPath).toString("base64");
|
|
5375
|
+
// Build the AI prompt for analysis
|
|
5376
|
+
const sensitivityDesc = {
|
|
5377
|
+
low: "Only flag significant, obvious changes that would clearly impact users",
|
|
5378
|
+
medium: "Flag notable changes in layout, content, or style",
|
|
5379
|
+
high: "Flag any visible differences, including subtle spacing or color changes",
|
|
5380
|
+
};
|
|
5381
|
+
const prompt = `You are a visual regression testing AI. Compare these two screenshots and identify any differences.
|
|
5382
|
+
|
|
5383
|
+
BASELINE IMAGE: The first/reference screenshot
|
|
5384
|
+
CURRENT IMAGE: The second/new screenshot
|
|
5385
|
+
|
|
5386
|
+
Sensitivity level: ${options.sensitivity || "medium"} - ${sensitivityDesc[options.sensitivity || "medium"]}
|
|
5387
|
+
|
|
5388
|
+
${options.ignoreRegions?.length ? `Ignore changes in these regions: ${JSON.stringify(options.ignoreRegions)}` : ""}
|
|
5389
|
+
|
|
5390
|
+
Analyze the visual differences and respond in this exact JSON format:
|
|
5391
|
+
{
|
|
5392
|
+
"overallStatus": "pass" | "warning" | "fail",
|
|
5393
|
+
"summary": "Brief 1-2 sentence summary of changes found",
|
|
5394
|
+
"changes": [
|
|
5395
|
+
{
|
|
5396
|
+
"type": "layout" | "content" | "style" | "missing" | "added" | "moved",
|
|
5397
|
+
"severity": "breaking" | "warning" | "info" | "acceptable",
|
|
5398
|
+
"region": { "x": 0, "y": 0, "width": 100, "height": 100 },
|
|
5399
|
+
"description": "What changed",
|
|
5400
|
+
"reasoning": "Why this matters",
|
|
5401
|
+
"confidence": 0.95,
|
|
5402
|
+
"suggestion": "Optional suggestion to fix or accept"
|
|
5403
|
+
}
|
|
5404
|
+
],
|
|
5405
|
+
"similarityScore": 0.85,
|
|
5406
|
+
"productionReady": true | false,
|
|
5407
|
+
"confidence": 0.9
|
|
5408
|
+
}
|
|
5409
|
+
|
|
5410
|
+
Change severity guidelines:
|
|
5411
|
+
- "breaking": Layout shifts, missing critical elements, broken functionality indicators
|
|
5412
|
+
- "warning": Noticeable content changes, significant style differences
|
|
5413
|
+
- "info": Minor spacing changes, subtle color adjustments
|
|
5414
|
+
- "acceptable": Expected dynamic content (timestamps, ads), minor rendering differences
|
|
5415
|
+
|
|
5416
|
+
For overallStatus:
|
|
5417
|
+
- "pass": No changes or only acceptable/info-level changes
|
|
5418
|
+
- "warning": Some warning-level changes that should be reviewed
|
|
5419
|
+
- "fail": Any breaking changes detected
|
|
5420
|
+
|
|
5421
|
+
Respond ONLY with the JSON, no other text.`;
|
|
5422
|
+
// Use Claude to analyze the images
|
|
5423
|
+
// For now, we'll use a simulated response since we don't have direct API access
|
|
5424
|
+
// In production, this would call the Anthropic API with vision
|
|
5425
|
+
try {
|
|
5426
|
+
// Try to use the inference tool if available
|
|
5427
|
+
const { execSync } = await import("child_process");
|
|
5428
|
+
const inferenceScript = (0, path_1.join)(process.env.HOME || "", ".claude/skills/Tools/Inference.ts");
|
|
5429
|
+
if ((0, fs_1.existsSync)(inferenceScript)) {
|
|
5430
|
+
// Create a temporary file with the images and prompt
|
|
5431
|
+
const tempDir = (0, path_1.join)(getVisualBaselinesPath(), "temp");
|
|
5432
|
+
if (!(0, fs_1.existsSync)(tempDir)) {
|
|
5433
|
+
(0, fs_1.mkdirSync)(tempDir, { recursive: true });
|
|
5434
|
+
}
|
|
5435
|
+
const requestPath = (0, path_1.join)(tempDir, `analysis-${Date.now()}.json`);
|
|
5436
|
+
(0, fs_1.writeFileSync)(requestPath, JSON.stringify({
|
|
5437
|
+
prompt,
|
|
5438
|
+
images: [
|
|
5439
|
+
{ type: "base64", media_type: "image/png", data: baselineImage },
|
|
5440
|
+
{ type: "base64", media_type: "image/png", data: currentImage },
|
|
5441
|
+
],
|
|
5442
|
+
}));
|
|
5443
|
+
// For now, perform a heuristic comparison since we can't easily call Claude with images
|
|
5444
|
+
// This can be enhanced when proper API integration is available
|
|
5445
|
+
const analysis = performHeuristicAnalysis(baselinePath, currentPath, options);
|
|
5446
|
+
// Clean up
|
|
5447
|
+
if ((0, fs_1.existsSync)(requestPath)) {
|
|
5448
|
+
(0, fs_1.unlinkSync)(requestPath);
|
|
5449
|
+
}
|
|
5450
|
+
return analysis;
|
|
5451
|
+
}
|
|
5452
|
+
}
|
|
5453
|
+
catch {
|
|
5454
|
+
// Fall back to heuristic analysis
|
|
5455
|
+
}
|
|
5456
|
+
// Fallback: Heuristic analysis based on file comparison
|
|
5457
|
+
return performHeuristicAnalysis(baselinePath, currentPath, options);
|
|
5458
|
+
}
|
|
5459
|
+
/**
|
|
5460
|
+
* Perform heuristic visual analysis when AI is not available
|
|
5461
|
+
*/
|
|
5462
|
+
function performHeuristicAnalysis(baselinePath, currentPath, options = {}) {
|
|
5463
|
+
const baselineStats = (0, fs_1.statSync)(baselinePath);
|
|
5464
|
+
const currentStats = (0, fs_1.statSync)(currentPath);
|
|
5465
|
+
// Simple heuristic: compare file sizes
|
|
5466
|
+
const sizeDiff = Math.abs(baselineStats.size - currentStats.size);
|
|
5467
|
+
const sizeRatio = sizeDiff / baselineStats.size;
|
|
5468
|
+
const changes = [];
|
|
5469
|
+
let overallStatus = "pass";
|
|
5470
|
+
let similarityScore = 1.0;
|
|
5471
|
+
// Size-based heuristics
|
|
5472
|
+
if (sizeRatio > 0.3) {
|
|
5473
|
+
changes.push({
|
|
5474
|
+
type: "layout",
|
|
5475
|
+
severity: "breaking",
|
|
5476
|
+
region: { x: 0, y: 0, width: 1920, height: 1080 },
|
|
5477
|
+
description: "Significant visual change detected (>30% size difference)",
|
|
5478
|
+
reasoning: "Large file size difference indicates substantial visual changes",
|
|
5479
|
+
confidence: 0.7,
|
|
5480
|
+
suggestion: "Review the visual changes manually",
|
|
5481
|
+
});
|
|
5482
|
+
overallStatus = "fail";
|
|
5483
|
+
similarityScore = 0.5;
|
|
5484
|
+
}
|
|
5485
|
+
else if (sizeRatio > 0.1) {
|
|
5486
|
+
changes.push({
|
|
5487
|
+
type: "content",
|
|
5488
|
+
severity: "warning",
|
|
5489
|
+
region: { x: 0, y: 0, width: 1920, height: 1080 },
|
|
5490
|
+
description: "Moderate visual change detected (10-30% size difference)",
|
|
5491
|
+
reasoning: "Moderate file size difference suggests some visual changes",
|
|
5492
|
+
confidence: 0.6,
|
|
5493
|
+
suggestion: "Review to confirm changes are expected",
|
|
5494
|
+
});
|
|
5495
|
+
overallStatus = "warning";
|
|
5496
|
+
similarityScore = 0.75;
|
|
5497
|
+
}
|
|
5498
|
+
else if (sizeRatio > 0.02) {
|
|
5499
|
+
changes.push({
|
|
5500
|
+
type: "style",
|
|
5501
|
+
severity: "info",
|
|
5502
|
+
region: { x: 0, y: 0, width: 1920, height: 1080 },
|
|
5503
|
+
description: "Minor visual change detected (2-10% size difference)",
|
|
5504
|
+
reasoning: "Small file size difference indicates minor rendering differences",
|
|
5505
|
+
confidence: 0.5,
|
|
5506
|
+
});
|
|
5507
|
+
similarityScore = 0.9;
|
|
5508
|
+
}
|
|
5509
|
+
// Apply sensitivity adjustments
|
|
5510
|
+
if (options.sensitivity === "low" && overallStatus === "warning") {
|
|
5511
|
+
overallStatus = "pass";
|
|
5512
|
+
}
|
|
5513
|
+
else if (options.sensitivity === "high" && changes.length === 0 && sizeRatio > 0.005) {
|
|
5514
|
+
changes.push({
|
|
5515
|
+
type: "style",
|
|
5516
|
+
severity: "info",
|
|
5517
|
+
region: { x: 0, y: 0, width: 1920, height: 1080 },
|
|
5518
|
+
description: "Very minor visual change detected",
|
|
5519
|
+
reasoning: "Slight file size difference at high sensitivity",
|
|
5520
|
+
confidence: 0.4,
|
|
5521
|
+
});
|
|
5522
|
+
similarityScore = 0.95;
|
|
5523
|
+
}
|
|
5524
|
+
return {
|
|
5525
|
+
overallStatus,
|
|
5526
|
+
summary: changes.length === 0
|
|
5527
|
+
? "No significant visual changes detected"
|
|
5528
|
+
: `Found ${changes.length} visual change(s) with ${overallStatus} status`,
|
|
5529
|
+
changes,
|
|
5530
|
+
similarityScore,
|
|
5531
|
+
productionReady: overallStatus !== "fail",
|
|
5532
|
+
confidence: 0.6, // Lower confidence for heuristic analysis
|
|
5533
|
+
rawAnalysis: "Heuristic analysis based on file comparison (AI analysis not available)",
|
|
5534
|
+
};
|
|
5535
|
+
}
|
|
5536
|
+
/**
|
|
5537
|
+
* Run visual regression test against a baseline
|
|
5538
|
+
*/
|
|
5539
|
+
async function runVisualRegression(url, baselineName, options = {}) {
|
|
5540
|
+
const startTime = Date.now();
|
|
5541
|
+
const baseline = getVisualBaseline(baselineName);
|
|
5542
|
+
if (!baseline) {
|
|
5543
|
+
return {
|
|
5544
|
+
passed: false,
|
|
5545
|
+
baseline: null,
|
|
5546
|
+
currentScreenshotPath: "",
|
|
5547
|
+
analysis: {
|
|
5548
|
+
overallStatus: "fail",
|
|
5549
|
+
summary: `Baseline "${baselineName}" not found`,
|
|
5550
|
+
changes: [],
|
|
5551
|
+
similarityScore: 0,
|
|
5552
|
+
productionReady: false,
|
|
5553
|
+
confidence: 1.0,
|
|
5554
|
+
},
|
|
5555
|
+
duration: Date.now() - startTime,
|
|
5556
|
+
};
|
|
5557
|
+
}
|
|
5558
|
+
// Capture current screenshot with same settings as baseline
|
|
5559
|
+
const browser = new CBrowser({
|
|
5560
|
+
device: baseline.device,
|
|
5561
|
+
viewportWidth: baseline.viewport.width,
|
|
5562
|
+
viewportHeight: baseline.viewport.height,
|
|
5563
|
+
});
|
|
5564
|
+
try {
|
|
5565
|
+
await browser.launch();
|
|
5566
|
+
await browser.navigate(url);
|
|
5567
|
+
// Wait if specified in options
|
|
5568
|
+
if (options.waitBeforeCapture) {
|
|
5569
|
+
await new Promise(resolve => setTimeout(resolve, options.waitBeforeCapture));
|
|
5570
|
+
}
|
|
5571
|
+
// Take screenshot
|
|
5572
|
+
const screenshotsPath = getVisualScreenshotsPath();
|
|
5573
|
+
const currentScreenshotPath = (0, path_1.join)(screenshotsPath, `current-${baseline.id}-${Date.now()}.png`);
|
|
5574
|
+
const page = await browser.getPage();
|
|
5575
|
+
if (baseline.selector) {
|
|
5576
|
+
const element = page.locator(baseline.selector).first();
|
|
5577
|
+
await element.screenshot({ path: currentScreenshotPath });
|
|
5578
|
+
}
|
|
5579
|
+
else {
|
|
5580
|
+
await page.screenshot({ path: currentScreenshotPath, fullPage: false });
|
|
5581
|
+
}
|
|
5582
|
+
// Analyze differences
|
|
5583
|
+
const analysis = await analyzeVisualDifferences(baseline.screenshotPath, currentScreenshotPath, options);
|
|
5584
|
+
// Determine pass/fail based on threshold
|
|
5585
|
+
const threshold = options.threshold ?? 0.9;
|
|
5586
|
+
const passed = analysis.similarityScore >= threshold && analysis.overallStatus !== "fail";
|
|
5587
|
+
// Generate diff image path (if we had pixel-diff capability)
|
|
5588
|
+
const diffImagePath = options.generateDiff
|
|
5589
|
+
? (0, path_1.join)(screenshotsPath, `diff-${baseline.id}-${Date.now()}.png`)
|
|
5590
|
+
: undefined;
|
|
5591
|
+
return {
|
|
5592
|
+
passed,
|
|
5593
|
+
baseline,
|
|
5594
|
+
currentScreenshotPath,
|
|
5595
|
+
diffImagePath,
|
|
5596
|
+
analysis,
|
|
5597
|
+
duration: Date.now() - startTime,
|
|
5598
|
+
};
|
|
5599
|
+
}
|
|
5600
|
+
finally {
|
|
5601
|
+
await browser.close();
|
|
5602
|
+
}
|
|
5603
|
+
}
|
|
5604
|
+
/**
|
|
5605
|
+
* Run visual regression on multiple pages
|
|
5606
|
+
*/
|
|
5607
|
+
async function runVisualRegressionSuite(suite, options = {}) {
|
|
5608
|
+
const startTime = Date.now();
|
|
5609
|
+
const results = [];
|
|
5610
|
+
let passed = 0;
|
|
5611
|
+
let failed = 0;
|
|
5612
|
+
let warnings = 0;
|
|
5613
|
+
console.log(`\n🔍 Running visual regression suite: ${suite.name}`);
|
|
5614
|
+
console.log(` Testing ${suite.pages.length} page(s)...\n`);
|
|
5615
|
+
for (const page of suite.pages) {
|
|
5616
|
+
console.log(` 📸 Testing: ${page.name}...`);
|
|
5617
|
+
const result = await runVisualRegression(page.url, page.baselineName, { ...options, ...page.options });
|
|
5618
|
+
results.push(result);
|
|
5619
|
+
if (result.passed) {
|
|
5620
|
+
if (result.analysis.overallStatus === "warning") {
|
|
5621
|
+
warnings++;
|
|
5622
|
+
console.log(` ⚠️ Warning (similarity: ${(result.analysis.similarityScore * 100).toFixed(1)}%)`);
|
|
5623
|
+
}
|
|
5624
|
+
else {
|
|
5625
|
+
passed++;
|
|
5626
|
+
console.log(` ✅ Passed (similarity: ${(result.analysis.similarityScore * 100).toFixed(1)}%)`);
|
|
5627
|
+
}
|
|
5628
|
+
}
|
|
5629
|
+
else {
|
|
5630
|
+
failed++;
|
|
5631
|
+
console.log(` ❌ Failed: ${result.analysis.summary}`);
|
|
5632
|
+
}
|
|
5633
|
+
}
|
|
5634
|
+
const duration = Date.now() - startTime;
|
|
5635
|
+
console.log(`\n${"─".repeat(60)}`);
|
|
5636
|
+
console.log(` Results: ${passed} passed, ${failed} failed, ${warnings} warnings`);
|
|
5637
|
+
console.log(` Duration: ${(duration / 1000).toFixed(1)}s`);
|
|
5638
|
+
console.log(`${"─".repeat(60)}\n`);
|
|
5639
|
+
return {
|
|
5640
|
+
suite,
|
|
5641
|
+
results,
|
|
5642
|
+
summary: {
|
|
5643
|
+
total: suite.pages.length,
|
|
5644
|
+
passed,
|
|
5645
|
+
failed,
|
|
5646
|
+
warnings,
|
|
5647
|
+
},
|
|
5648
|
+
duration,
|
|
5649
|
+
timestamp: new Date().toISOString(),
|
|
5650
|
+
};
|
|
5651
|
+
}
|
|
5652
|
+
/**
|
|
5653
|
+
* Format visual regression result as text report
|
|
5654
|
+
*/
|
|
5655
|
+
function formatVisualRegressionReport(result) {
|
|
5656
|
+
const lines = [];
|
|
5657
|
+
lines.push("╔══════════════════════════════════════════════════════════════════════════════╗");
|
|
5658
|
+
lines.push("║ AI VISUAL REGRESSION REPORT ║");
|
|
5659
|
+
lines.push("╚══════════════════════════════════════════════════════════════════════════════╝");
|
|
5660
|
+
lines.push("");
|
|
5661
|
+
const statusIcon = result.passed ? "✅" : "❌";
|
|
5662
|
+
const statusText = result.passed ? "PASSED" : "FAILED";
|
|
5663
|
+
lines.push(`${statusIcon} Status: ${statusText}`);
|
|
5664
|
+
lines.push(`📊 Similarity: ${(result.analysis.similarityScore * 100).toFixed(1)}%`);
|
|
5665
|
+
lines.push(`🎯 Confidence: ${(result.analysis.confidence * 100).toFixed(0)}%`);
|
|
5666
|
+
lines.push(`⏱️ Duration: ${(result.duration / 1000).toFixed(2)}s`);
|
|
5667
|
+
lines.push("");
|
|
5668
|
+
if (result.baseline) {
|
|
5669
|
+
lines.push("───────────────────────────────────────────────────────────────────────────────");
|
|
5670
|
+
lines.push("📸 BASELINE INFO");
|
|
5671
|
+
lines.push("───────────────────────────────────────────────────────────────────────────────");
|
|
5672
|
+
lines.push(` Name: ${result.baseline.name}`);
|
|
5673
|
+
lines.push(` URL: ${result.baseline.url}`);
|
|
5674
|
+
lines.push(` Captured: ${result.baseline.timestamp}`);
|
|
5675
|
+
lines.push(` Viewport: ${result.baseline.viewport.width}x${result.baseline.viewport.height}`);
|
|
5676
|
+
if (result.baseline.device) {
|
|
5677
|
+
lines.push(` Device: ${result.baseline.device}`);
|
|
5678
|
+
}
|
|
5679
|
+
lines.push("");
|
|
5680
|
+
}
|
|
5681
|
+
lines.push("───────────────────────────────────────────────────────────────────────────────");
|
|
5682
|
+
lines.push("📝 ANALYSIS SUMMARY");
|
|
5683
|
+
lines.push("───────────────────────────────────────────────────────────────────────────────");
|
|
5684
|
+
lines.push(` ${result.analysis.summary}`);
|
|
5685
|
+
lines.push("");
|
|
5686
|
+
if (result.analysis.changes.length > 0) {
|
|
5687
|
+
lines.push("───────────────────────────────────────────────────────────────────────────────");
|
|
5688
|
+
lines.push("🔄 DETECTED CHANGES");
|
|
5689
|
+
lines.push("───────────────────────────────────────────────────────────────────────────────");
|
|
5690
|
+
for (const change of result.analysis.changes) {
|
|
5691
|
+
const severityIcon = {
|
|
5692
|
+
breaking: "🚨",
|
|
5693
|
+
warning: "⚠️",
|
|
5694
|
+
info: "ℹ️",
|
|
5695
|
+
acceptable: "✓",
|
|
5696
|
+
}[change.severity];
|
|
5697
|
+
lines.push("");
|
|
5698
|
+
lines.push(` ${severityIcon} [${change.severity.toUpperCase()}] ${change.type}`);
|
|
5699
|
+
lines.push(` ${change.description}`);
|
|
5700
|
+
lines.push(` Reasoning: ${change.reasoning}`);
|
|
5701
|
+
if (change.suggestion) {
|
|
5702
|
+
lines.push(` Suggestion: ${change.suggestion}`);
|
|
5703
|
+
}
|
|
5704
|
+
}
|
|
5705
|
+
lines.push("");
|
|
5706
|
+
}
|
|
5707
|
+
lines.push("───────────────────────────────────────────────────────────────────────────────");
|
|
5708
|
+
lines.push(`🚀 Production Ready: ${result.analysis.productionReady ? "YES" : "NO"}`);
|
|
5709
|
+
lines.push("───────────────────────────────────────────────────────────────────────────────");
|
|
5710
|
+
return lines.join("\n");
|
|
5711
|
+
}
|
|
5712
|
+
/**
|
|
5713
|
+
* Generate HTML report for visual regression suite
|
|
5714
|
+
*/
|
|
5715
|
+
function generateVisualRegressionHtmlReport(suiteResult) {
|
|
5716
|
+
const { suite, results, summary, duration, timestamp } = suiteResult;
|
|
5717
|
+
return `<!DOCTYPE html>
|
|
5718
|
+
<html lang="en">
|
|
5719
|
+
<head>
|
|
5720
|
+
<meta charset="UTF-8">
|
|
5721
|
+
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
|
5722
|
+
<title>Visual Regression Report - ${suite.name}</title>
|
|
5723
|
+
<style>
|
|
5724
|
+
* { box-sizing: border-box; margin: 0; padding: 0; }
|
|
5725
|
+
body { font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif; background: #0f172a; color: #e2e8f0; line-height: 1.6; }
|
|
5726
|
+
.container { max-width: 1200px; margin: 0 auto; padding: 2rem; }
|
|
5727
|
+
h1 { font-size: 2rem; margin-bottom: 0.5rem; }
|
|
5728
|
+
h2 { font-size: 1.25rem; margin-bottom: 1rem; color: #94a3b8; }
|
|
5729
|
+
.header { text-align: center; margin-bottom: 2rem; }
|
|
5730
|
+
.summary { display: grid; grid-template-columns: repeat(4, 1fr); gap: 1rem; margin-bottom: 2rem; }
|
|
5731
|
+
.stat { background: #1e293b; padding: 1.5rem; border-radius: 0.5rem; text-align: center; }
|
|
5732
|
+
.stat-value { font-size: 2rem; font-weight: bold; }
|
|
5733
|
+
.stat-label { color: #94a3b8; font-size: 0.875rem; }
|
|
5734
|
+
.passed { color: #22c55e; }
|
|
5735
|
+
.failed { color: #ef4444; }
|
|
5736
|
+
.warning { color: #eab308; }
|
|
5737
|
+
.results { display: flex; flex-direction: column; gap: 1rem; }
|
|
5738
|
+
.result-card { background: #1e293b; border-radius: 0.5rem; overflow: hidden; }
|
|
5739
|
+
.result-header { padding: 1rem; display: flex; justify-content: space-between; align-items: center; border-bottom: 1px solid #334155; }
|
|
5740
|
+
.result-body { padding: 1rem; }
|
|
5741
|
+
.badge { padding: 0.25rem 0.75rem; border-radius: 9999px; font-size: 0.75rem; font-weight: 600; }
|
|
5742
|
+
.badge-pass { background: #166534; color: #22c55e; }
|
|
5743
|
+
.badge-fail { background: #7f1d1d; color: #ef4444; }
|
|
5744
|
+
.badge-warning { background: #713f12; color: #eab308; }
|
|
5745
|
+
.similarity { font-size: 1.5rem; font-weight: bold; }
|
|
5746
|
+
.changes { margin-top: 1rem; }
|
|
5747
|
+
.change { padding: 0.75rem; background: #0f172a; border-radius: 0.25rem; margin-bottom: 0.5rem; }
|
|
5748
|
+
.change-breaking { border-left: 3px solid #ef4444; }
|
|
5749
|
+
.change-warning { border-left: 3px solid #eab308; }
|
|
5750
|
+
.change-info { border-left: 3px solid #3b82f6; }
|
|
5751
|
+
.change-acceptable { border-left: 3px solid #22c55e; }
|
|
5752
|
+
footer { text-align: center; color: #64748b; margin-top: 2rem; padding-top: 2rem; border-top: 1px solid #334155; }
|
|
5753
|
+
</style>
|
|
5754
|
+
</head>
|
|
5755
|
+
<body>
|
|
5756
|
+
<div class="container">
|
|
5757
|
+
<div class="header">
|
|
5758
|
+
<h1>🔍 Visual Regression Report</h1>
|
|
5759
|
+
<h2>${suite.name}</h2>
|
|
5760
|
+
<p style="color: #64748b;">Generated: ${new Date(timestamp).toLocaleString()}</p>
|
|
5761
|
+
</div>
|
|
5762
|
+
|
|
5763
|
+
<div class="summary">
|
|
5764
|
+
<div class="stat">
|
|
5765
|
+
<div class="stat-value">${summary.total}</div>
|
|
5766
|
+
<div class="stat-label">Total Tests</div>
|
|
5767
|
+
</div>
|
|
5768
|
+
<div class="stat">
|
|
5769
|
+
<div class="stat-value passed">${summary.passed}</div>
|
|
5770
|
+
<div class="stat-label">Passed</div>
|
|
5771
|
+
</div>
|
|
5772
|
+
<div class="stat">
|
|
5773
|
+
<div class="stat-value failed">${summary.failed}</div>
|
|
5774
|
+
<div class="stat-label">Failed</div>
|
|
5775
|
+
</div>
|
|
5776
|
+
<div class="stat">
|
|
5777
|
+
<div class="stat-value warning">${summary.warnings}</div>
|
|
5778
|
+
<div class="stat-label">Warnings</div>
|
|
5779
|
+
</div>
|
|
5780
|
+
</div>
|
|
5781
|
+
|
|
5782
|
+
<div class="results">
|
|
5783
|
+
${results.map((result, i) => {
|
|
5784
|
+
const page = suite.pages[i];
|
|
5785
|
+
const statusClass = result.passed ? (result.analysis.overallStatus === "warning" ? "warning" : "passed") : "failed";
|
|
5786
|
+
const badgeClass = result.passed ? (result.analysis.overallStatus === "warning" ? "badge-warning" : "badge-pass") : "badge-fail";
|
|
5787
|
+
const statusText = result.passed ? (result.analysis.overallStatus === "warning" ? "WARNING" : "PASSED") : "FAILED";
|
|
5788
|
+
return `
|
|
5789
|
+
<div class="result-card">
|
|
5790
|
+
<div class="result-header">
|
|
5791
|
+
<div>
|
|
5792
|
+
<strong>${page.name}</strong>
|
|
5793
|
+
<div style="color: #64748b; font-size: 0.875rem;">${page.url}</div>
|
|
5794
|
+
</div>
|
|
5795
|
+
<div style="display: flex; align-items: center; gap: 1rem;">
|
|
5796
|
+
<div class="similarity ${statusClass}">${(result.analysis.similarityScore * 100).toFixed(1)}%</div>
|
|
5797
|
+
<span class="badge ${badgeClass}">${statusText}</span>
|
|
5798
|
+
</div>
|
|
5799
|
+
</div>
|
|
5800
|
+
<div class="result-body">
|
|
5801
|
+
<p>${result.analysis.summary}</p>
|
|
5802
|
+
${result.analysis.changes.length > 0 ? `
|
|
5803
|
+
<div class="changes">
|
|
5804
|
+
${result.analysis.changes.map(change => `
|
|
5805
|
+
<div class="change change-${change.severity}">
|
|
5806
|
+
<strong>[${change.severity.toUpperCase()}] ${change.type}</strong>
|
|
5807
|
+
<p>${change.description}</p>
|
|
5808
|
+
${change.suggestion ? `<p style="color: #94a3b8;"><em>Suggestion: ${change.suggestion}</em></p>` : ""}
|
|
5809
|
+
</div>
|
|
5810
|
+
`).join("")}
|
|
5811
|
+
</div>
|
|
5812
|
+
` : ""}
|
|
5813
|
+
</div>
|
|
5814
|
+
</div>
|
|
5815
|
+
`;
|
|
5816
|
+
}).join("")}
|
|
5817
|
+
</div>
|
|
5818
|
+
|
|
5819
|
+
<footer>
|
|
5820
|
+
Generated by CBrowser v7.1.0 | Suite completed in ${(duration / 1000).toFixed(1)}s
|
|
5821
|
+
</footer>
|
|
5822
|
+
</div>
|
|
5823
|
+
</body>
|
|
5824
|
+
</html>`;
|
|
5825
|
+
}
|
|
5826
|
+
// =========================================================================
|
|
5827
|
+
// Tier 7.1: Cross-Browser Visual Testing (v7.1.0)
|
|
5828
|
+
// =========================================================================
|
|
5829
|
+
/**
|
|
5830
|
+
* Get the path for cross-browser screenshots
|
|
5831
|
+
*/
|
|
5832
|
+
function getCrossBrowserScreenshotsPath() {
|
|
5833
|
+
const baseDir = process.env.CBROWSER_DATA_DIR || (0, path_1.join)(process.cwd(), ".cbrowser");
|
|
5834
|
+
const dir = (0, path_1.join)(baseDir, "cross-browser");
|
|
5835
|
+
if (!(0, fs_1.existsSync)(dir)) {
|
|
5836
|
+
(0, fs_1.mkdirSync)(dir, { recursive: true });
|
|
5837
|
+
}
|
|
5838
|
+
return dir;
|
|
5839
|
+
}
|
|
5840
|
+
/**
|
|
5841
|
+
* Capture screenshot with a specific browser
|
|
5842
|
+
*/
|
|
5843
|
+
async function captureWithBrowser(url, browserType, options = {}) {
|
|
5844
|
+
const startTime = Date.now();
|
|
5845
|
+
const browser = new CBrowser({
|
|
5846
|
+
browser: browserType,
|
|
5847
|
+
viewportWidth: options.viewport?.width || 1920,
|
|
5848
|
+
viewportHeight: options.viewport?.height || 1080,
|
|
5849
|
+
});
|
|
5850
|
+
try {
|
|
5851
|
+
await browser.launch();
|
|
5852
|
+
await browser.navigate(url);
|
|
5853
|
+
// Wait if specified
|
|
5854
|
+
if (options.waitForSelector) {
|
|
5855
|
+
const page = await browser.getPage();
|
|
5856
|
+
await page.waitForSelector(options.waitForSelector, { timeout: 10000 }).catch(() => { });
|
|
5857
|
+
}
|
|
5858
|
+
if (options.waitBeforeCapture) {
|
|
5859
|
+
await new Promise(resolve => setTimeout(resolve, options.waitBeforeCapture));
|
|
5860
|
+
}
|
|
5861
|
+
// Take screenshot
|
|
5862
|
+
const screenshotsPath = getCrossBrowserScreenshotsPath();
|
|
5863
|
+
const filename = `${browserType}-${Date.now()}.png`;
|
|
5864
|
+
const screenshotPath = (0, path_1.join)(screenshotsPath, filename);
|
|
5865
|
+
const page = await browser.getPage();
|
|
5866
|
+
await page.screenshot({ path: screenshotPath, fullPage: false });
|
|
5867
|
+
// Get user agent
|
|
5868
|
+
const userAgent = await page.evaluate(() => navigator.userAgent);
|
|
5869
|
+
const viewport = page.viewportSize() || { width: 1920, height: 1080 };
|
|
5870
|
+
return {
|
|
5871
|
+
browser: browserType,
|
|
5872
|
+
screenshotPath,
|
|
5873
|
+
viewport,
|
|
5874
|
+
userAgent,
|
|
5875
|
+
timestamp: new Date().toISOString(),
|
|
5876
|
+
captureTime: Date.now() - startTime,
|
|
5877
|
+
};
|
|
5878
|
+
}
|
|
5879
|
+
finally {
|
|
5880
|
+
await browser.close();
|
|
5881
|
+
}
|
|
5882
|
+
}
|
|
5883
|
+
/**
|
|
5884
|
+
* Run cross-browser visual test for a single URL
|
|
5885
|
+
*/
|
|
5886
|
+
async function runCrossBrowserTest(url, options = {}) {
|
|
5887
|
+
const startTime = Date.now();
|
|
5888
|
+
const browsers = options.browsers || ["chromium", "firefox", "webkit"];
|
|
5889
|
+
console.log(`\n🌐 Cross-Browser Visual Test`);
|
|
5890
|
+
console.log(` URL: ${url}`);
|
|
5891
|
+
console.log(` Browsers: ${browsers.join(", ")}\n`);
|
|
5892
|
+
// Capture screenshots from each browser
|
|
5893
|
+
const screenshots = [];
|
|
5894
|
+
for (const browserType of browsers) {
|
|
5895
|
+
console.log(` 📸 Capturing ${browserType}...`);
|
|
5896
|
+
try {
|
|
5897
|
+
const screenshot = await captureWithBrowser(url, browserType, options);
|
|
5898
|
+
screenshots.push(screenshot);
|
|
5899
|
+
console.log(` ✅ Captured in ${screenshot.captureTime}ms`);
|
|
5900
|
+
}
|
|
5901
|
+
catch (error) {
|
|
5902
|
+
console.log(` ❌ Failed: ${error instanceof Error ? error.message : "Unknown error"}`);
|
|
5903
|
+
}
|
|
5904
|
+
}
|
|
5905
|
+
if (screenshots.length < 2) {
|
|
5906
|
+
return {
|
|
5907
|
+
url,
|
|
5908
|
+
screenshots,
|
|
5909
|
+
comparisons: [],
|
|
5910
|
+
overallStatus: "major_differences",
|
|
5911
|
+
summary: "Could not capture enough screenshots for comparison",
|
|
5912
|
+
problematicBrowsers: [],
|
|
5913
|
+
duration: Date.now() - startTime,
|
|
5914
|
+
timestamp: new Date().toISOString(),
|
|
5915
|
+
};
|
|
5916
|
+
}
|
|
5917
|
+
// Compare all pairs of browsers
|
|
5918
|
+
const comparisons = [];
|
|
5919
|
+
let hasMinorDifferences = false;
|
|
5920
|
+
let hasMajorDifferences = false;
|
|
5921
|
+
const problematicBrowsers = new Set();
|
|
5922
|
+
console.log(`\n 🔍 Comparing browsers...`);
|
|
5923
|
+
for (let i = 0; i < screenshots.length; i++) {
|
|
5924
|
+
for (let j = i + 1; j < screenshots.length; j++) {
|
|
5925
|
+
const a = screenshots[i];
|
|
5926
|
+
const b = screenshots[j];
|
|
5927
|
+
console.log(` ${a.browser} vs ${b.browser}...`);
|
|
5928
|
+
// Use the existing AI visual analysis
|
|
5929
|
+
const analysis = await analyzeVisualDifferences(a.screenshotPath, b.screenshotPath, { sensitivity: options.sensitivity || "medium" });
|
|
5930
|
+
comparisons.push({
|
|
5931
|
+
browserA: a.browser,
|
|
5932
|
+
browserB: b.browser,
|
|
5933
|
+
analysis,
|
|
5934
|
+
screenshots: {
|
|
5935
|
+
a: a.screenshotPath,
|
|
5936
|
+
b: b.screenshotPath,
|
|
5937
|
+
},
|
|
5938
|
+
});
|
|
5939
|
+
if (analysis.overallStatus === "fail") {
|
|
5940
|
+
hasMajorDifferences = true;
|
|
5941
|
+
problematicBrowsers.add(a.browser);
|
|
5942
|
+
problematicBrowsers.add(b.browser);
|
|
5943
|
+
console.log(` ❌ Major differences (${(analysis.similarityScore * 100).toFixed(1)}%)`);
|
|
5944
|
+
}
|
|
5945
|
+
else if (analysis.overallStatus === "warning") {
|
|
5946
|
+
hasMinorDifferences = true;
|
|
5947
|
+
console.log(` ⚠️ Minor differences (${(analysis.similarityScore * 100).toFixed(1)}%)`);
|
|
5948
|
+
}
|
|
5949
|
+
else {
|
|
5950
|
+
console.log(` ✅ Consistent (${(analysis.similarityScore * 100).toFixed(1)}%)`);
|
|
5951
|
+
}
|
|
5952
|
+
}
|
|
5953
|
+
}
|
|
5954
|
+
const overallStatus = hasMajorDifferences
|
|
5955
|
+
? "major_differences"
|
|
5956
|
+
: hasMinorDifferences
|
|
5957
|
+
? "minor_differences"
|
|
5958
|
+
: "consistent";
|
|
5959
|
+
const summary = overallStatus === "consistent"
|
|
5960
|
+
? "Page renders consistently across all tested browsers"
|
|
5961
|
+
: overallStatus === "minor_differences"
|
|
5962
|
+
? "Minor rendering differences detected between browsers"
|
|
5963
|
+
: "Significant rendering differences detected between browsers";
|
|
5964
|
+
return {
|
|
5965
|
+
url,
|
|
5966
|
+
screenshots,
|
|
5967
|
+
comparisons,
|
|
5968
|
+
overallStatus,
|
|
5969
|
+
summary,
|
|
5970
|
+
problematicBrowsers: Array.from(problematicBrowsers),
|
|
5971
|
+
duration: Date.now() - startTime,
|
|
5972
|
+
timestamp: new Date().toISOString(),
|
|
5973
|
+
};
|
|
5974
|
+
}
|
|
5975
|
+
/**
|
|
5976
|
+
* Run cross-browser test suite
|
|
5977
|
+
*/
|
|
5978
|
+
async function runCrossBrowserSuite(suite) {
|
|
5979
|
+
const startTime = Date.now();
|
|
5980
|
+
const results = [];
|
|
5981
|
+
let consistent = 0;
|
|
5982
|
+
let minorDifferences = 0;
|
|
5983
|
+
let majorDifferences = 0;
|
|
5984
|
+
console.log(`\n🌐 Cross-Browser Visual Test Suite: ${suite.name}`);
|
|
5985
|
+
console.log(` Testing ${suite.urls.length} URL(s)...\n`);
|
|
5986
|
+
for (const url of suite.urls) {
|
|
5987
|
+
const result = await runCrossBrowserTest(url, suite.options);
|
|
5988
|
+
results.push(result);
|
|
5989
|
+
switch (result.overallStatus) {
|
|
5990
|
+
case "consistent":
|
|
5991
|
+
consistent++;
|
|
5992
|
+
break;
|
|
5993
|
+
case "minor_differences":
|
|
5994
|
+
minorDifferences++;
|
|
5995
|
+
break;
|
|
5996
|
+
case "major_differences":
|
|
5997
|
+
majorDifferences++;
|
|
5998
|
+
break;
|
|
5999
|
+
}
|
|
6000
|
+
}
|
|
6001
|
+
return {
|
|
6002
|
+
suite,
|
|
6003
|
+
results,
|
|
6004
|
+
summary: {
|
|
6005
|
+
total: suite.urls.length,
|
|
6006
|
+
consistent,
|
|
6007
|
+
minorDifferences,
|
|
6008
|
+
majorDifferences,
|
|
6009
|
+
},
|
|
6010
|
+
duration: Date.now() - startTime,
|
|
6011
|
+
timestamp: new Date().toISOString(),
|
|
6012
|
+
};
|
|
6013
|
+
}
|
|
6014
|
+
/**
|
|
6015
|
+
* Format cross-browser result as text report
|
|
6016
|
+
*/
|
|
6017
|
+
function formatCrossBrowserReport(result) {
|
|
6018
|
+
const lines = [];
|
|
6019
|
+
lines.push("╔══════════════════════════════════════════════════════════════════════════════╗");
|
|
6020
|
+
lines.push("║ CROSS-BROWSER VISUAL TEST REPORT ║");
|
|
6021
|
+
lines.push("╚══════════════════════════════════════════════════════════════════════════════╝");
|
|
6022
|
+
lines.push("");
|
|
6023
|
+
const statusIcon = {
|
|
6024
|
+
consistent: "✅",
|
|
6025
|
+
minor_differences: "⚠️",
|
|
6026
|
+
major_differences: "❌",
|
|
6027
|
+
}[result.overallStatus];
|
|
6028
|
+
const statusText = {
|
|
6029
|
+
consistent: "CONSISTENT",
|
|
6030
|
+
minor_differences: "MINOR DIFFERENCES",
|
|
6031
|
+
major_differences: "MAJOR DIFFERENCES",
|
|
6032
|
+
}[result.overallStatus];
|
|
6033
|
+
lines.push(`${statusIcon} Status: ${statusText}`);
|
|
6034
|
+
lines.push(`🔗 URL: ${result.url}`);
|
|
6035
|
+
lines.push(`⏱️ Duration: ${(result.duration / 1000).toFixed(2)}s`);
|
|
6036
|
+
lines.push("");
|
|
6037
|
+
lines.push("───────────────────────────────────────────────────────────────────────────────");
|
|
6038
|
+
lines.push("📸 BROWSER SCREENSHOTS");
|
|
6039
|
+
lines.push("───────────────────────────────────────────────────────────────────────────────");
|
|
6040
|
+
for (const screenshot of result.screenshots) {
|
|
6041
|
+
lines.push(` ${screenshot.browser.toUpperCase()}`);
|
|
6042
|
+
lines.push(` Viewport: ${screenshot.viewport.width}x${screenshot.viewport.height}`);
|
|
6043
|
+
lines.push(` Capture time: ${screenshot.captureTime}ms`);
|
|
6044
|
+
lines.push(` Path: ${screenshot.screenshotPath}`);
|
|
6045
|
+
lines.push("");
|
|
6046
|
+
}
|
|
6047
|
+
lines.push("───────────────────────────────────────────────────────────────────────────────");
|
|
6048
|
+
lines.push("🔍 BROWSER COMPARISONS");
|
|
6049
|
+
lines.push("───────────────────────────────────────────────────────────────────────────────");
|
|
6050
|
+
for (const comparison of result.comparisons) {
|
|
6051
|
+
const compIcon = {
|
|
6052
|
+
pass: "✅",
|
|
6053
|
+
warning: "⚠️",
|
|
6054
|
+
fail: "❌",
|
|
6055
|
+
}[comparison.analysis.overallStatus];
|
|
6056
|
+
lines.push(` ${comparison.browserA.toUpperCase()} vs ${comparison.browserB.toUpperCase()}: ${compIcon}`);
|
|
6057
|
+
lines.push(` Similarity: ${(comparison.analysis.similarityScore * 100).toFixed(1)}%`);
|
|
6058
|
+
lines.push(` ${comparison.analysis.summary}`);
|
|
6059
|
+
if (comparison.analysis.changes.length > 0) {
|
|
6060
|
+
for (const change of comparison.analysis.changes) {
|
|
6061
|
+
lines.push(` - [${change.severity.toUpperCase()}] ${change.description}`);
|
|
6062
|
+
}
|
|
6063
|
+
}
|
|
6064
|
+
lines.push("");
|
|
6065
|
+
}
|
|
6066
|
+
if (result.problematicBrowsers.length > 0) {
|
|
6067
|
+
lines.push("───────────────────────────────────────────────────────────────────────────────");
|
|
6068
|
+
lines.push("⚠️ BROWSERS WITH ISSUES");
|
|
6069
|
+
lines.push("───────────────────────────────────────────────────────────────────────────────");
|
|
6070
|
+
for (const browser of result.problematicBrowsers) {
|
|
6071
|
+
lines.push(` • ${browser}`);
|
|
6072
|
+
}
|
|
6073
|
+
lines.push("");
|
|
6074
|
+
}
|
|
6075
|
+
lines.push("───────────────────────────────────────────────────────────────────────────────");
|
|
6076
|
+
lines.push(`📝 SUMMARY: ${result.summary}`);
|
|
6077
|
+
lines.push("───────────────────────────────────────────────────────────────────────────────");
|
|
6078
|
+
return lines.join("\n");
|
|
6079
|
+
}
|
|
6080
|
+
/**
|
|
6081
|
+
* Generate HTML report for cross-browser test suite
|
|
6082
|
+
*/
|
|
6083
|
+
function generateCrossBrowserHtmlReport(suiteResult) {
|
|
6084
|
+
const { suite, results, summary, duration, timestamp } = suiteResult;
|
|
6085
|
+
return `<!DOCTYPE html>
|
|
6086
|
+
<html lang="en">
|
|
6087
|
+
<head>
|
|
6088
|
+
<meta charset="UTF-8">
|
|
6089
|
+
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
|
6090
|
+
<title>Cross-Browser Visual Report - ${suite.name}</title>
|
|
6091
|
+
<style>
|
|
6092
|
+
* { box-sizing: border-box; margin: 0; padding: 0; }
|
|
6093
|
+
body { font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif; background: #0f172a; color: #e2e8f0; line-height: 1.6; }
|
|
6094
|
+
.container { max-width: 1400px; margin: 0 auto; padding: 2rem; }
|
|
6095
|
+
h1 { font-size: 2rem; margin-bottom: 0.5rem; }
|
|
6096
|
+
h2 { font-size: 1.25rem; margin-bottom: 1rem; color: #94a3b8; }
|
|
6097
|
+
.header { text-align: center; margin-bottom: 2rem; }
|
|
6098
|
+
.summary { display: grid; grid-template-columns: repeat(4, 1fr); gap: 1rem; margin-bottom: 2rem; }
|
|
6099
|
+
.stat { background: #1e293b; padding: 1.5rem; border-radius: 0.5rem; text-align: center; }
|
|
6100
|
+
.stat-value { font-size: 2rem; font-weight: bold; }
|
|
6101
|
+
.stat-label { color: #94a3b8; font-size: 0.875rem; }
|
|
6102
|
+
.consistent { color: #22c55e; }
|
|
6103
|
+
.minor { color: #eab308; }
|
|
6104
|
+
.major { color: #ef4444; }
|
|
6105
|
+
.results { display: flex; flex-direction: column; gap: 2rem; }
|
|
6106
|
+
.result-card { background: #1e293b; border-radius: 0.5rem; overflow: hidden; }
|
|
6107
|
+
.result-header { padding: 1rem; border-bottom: 1px solid #334155; display: flex; justify-content: space-between; align-items: center; }
|
|
6108
|
+
.result-body { padding: 1rem; }
|
|
6109
|
+
.screenshots { display: grid; grid-template-columns: repeat(auto-fit, minmax(300px, 1fr)); gap: 1rem; margin-bottom: 1rem; }
|
|
6110
|
+
.screenshot-card { background: #0f172a; border-radius: 0.25rem; padding: 1rem; text-align: center; }
|
|
6111
|
+
.screenshot-card img { max-width: 100%; border-radius: 0.25rem; margin-top: 0.5rem; }
|
|
6112
|
+
.browser-name { font-weight: bold; text-transform: capitalize; }
|
|
6113
|
+
.comparisons { margin-top: 1rem; }
|
|
6114
|
+
.comparison { padding: 0.75rem; background: #0f172a; border-radius: 0.25rem; margin-bottom: 0.5rem; }
|
|
6115
|
+
.comparison-header { display: flex; justify-content: space-between; align-items: center; }
|
|
6116
|
+
.badge { padding: 0.25rem 0.75rem; border-radius: 9999px; font-size: 0.75rem; font-weight: 600; }
|
|
6117
|
+
.badge-consistent { background: #166534; color: #22c55e; }
|
|
6118
|
+
.badge-minor { background: #713f12; color: #eab308; }
|
|
6119
|
+
.badge-major { background: #7f1d1d; color: #ef4444; }
|
|
6120
|
+
footer { text-align: center; color: #64748b; margin-top: 2rem; padding-top: 2rem; border-top: 1px solid #334155; }
|
|
6121
|
+
</style>
|
|
6122
|
+
</head>
|
|
6123
|
+
<body>
|
|
6124
|
+
<div class="container">
|
|
6125
|
+
<div class="header">
|
|
6126
|
+
<h1>🌐 Cross-Browser Visual Report</h1>
|
|
6127
|
+
<h2>${suite.name}</h2>
|
|
6128
|
+
<p style="color: #64748b;">Generated: ${new Date(timestamp).toLocaleString()}</p>
|
|
6129
|
+
</div>
|
|
6130
|
+
|
|
6131
|
+
<div class="summary">
|
|
6132
|
+
<div class="stat">
|
|
6133
|
+
<div class="stat-value">${summary.total}</div>
|
|
6134
|
+
<div class="stat-label">URLs Tested</div>
|
|
6135
|
+
</div>
|
|
6136
|
+
<div class="stat">
|
|
6137
|
+
<div class="stat-value consistent">${summary.consistent}</div>
|
|
6138
|
+
<div class="stat-label">Consistent</div>
|
|
6139
|
+
</div>
|
|
6140
|
+
<div class="stat">
|
|
6141
|
+
<div class="stat-value minor">${summary.minorDifferences}</div>
|
|
6142
|
+
<div class="stat-label">Minor Differences</div>
|
|
6143
|
+
</div>
|
|
6144
|
+
<div class="stat">
|
|
6145
|
+
<div class="stat-value major">${summary.majorDifferences}</div>
|
|
6146
|
+
<div class="stat-label">Major Differences</div>
|
|
6147
|
+
</div>
|
|
6148
|
+
</div>
|
|
6149
|
+
|
|
6150
|
+
<div class="results">
|
|
6151
|
+
${results.map(result => {
|
|
6152
|
+
const statusClass = result.overallStatus === "consistent" ? "consistent" : result.overallStatus === "minor_differences" ? "minor" : "major";
|
|
6153
|
+
const badgeClass = result.overallStatus === "consistent" ? "badge-consistent" : result.overallStatus === "minor_differences" ? "badge-minor" : "badge-major";
|
|
6154
|
+
const statusText = result.overallStatus === "consistent" ? "Consistent" : result.overallStatus === "minor_differences" ? "Minor Differences" : "Major Differences";
|
|
6155
|
+
return `
|
|
6156
|
+
<div class="result-card">
|
|
6157
|
+
<div class="result-header">
|
|
6158
|
+
<div>
|
|
6159
|
+
<strong>${result.url}</strong>
|
|
6160
|
+
<div style="color: #64748b; font-size: 0.875rem;">${result.summary}</div>
|
|
6161
|
+
</div>
|
|
6162
|
+
<span class="badge ${badgeClass}">${statusText}</span>
|
|
6163
|
+
</div>
|
|
6164
|
+
<div class="result-body">
|
|
6165
|
+
<h3 style="margin-bottom: 1rem; color: #94a3b8;">Screenshots</h3>
|
|
6166
|
+
<div class="screenshots">
|
|
6167
|
+
${result.screenshots.map(s => `
|
|
6168
|
+
<div class="screenshot-card">
|
|
6169
|
+
<div class="browser-name">${s.browser}</div>
|
|
6170
|
+
<div style="color: #64748b; font-size: 0.75rem;">${s.viewport.width}x${s.viewport.height} • ${s.captureTime}ms</div>
|
|
6171
|
+
</div>
|
|
6172
|
+
`).join("")}
|
|
6173
|
+
</div>
|
|
6174
|
+
|
|
6175
|
+
<h3 style="margin: 1rem 0; color: #94a3b8;">Comparisons</h3>
|
|
6176
|
+
<div class="comparisons">
|
|
6177
|
+
${result.comparisons.map(c => {
|
|
6178
|
+
const cBadgeClass = c.analysis.overallStatus === "pass" ? "badge-consistent" : c.analysis.overallStatus === "warning" ? "badge-minor" : "badge-major";
|
|
6179
|
+
return `
|
|
6180
|
+
<div class="comparison">
|
|
6181
|
+
<div class="comparison-header">
|
|
6182
|
+
<span>${c.browserA} vs ${c.browserB}</span>
|
|
6183
|
+
<span class="badge ${cBadgeClass}">${(c.analysis.similarityScore * 100).toFixed(1)}%</span>
|
|
6184
|
+
</div>
|
|
6185
|
+
<p style="color: #94a3b8; font-size: 0.875rem; margin-top: 0.5rem;">${c.analysis.summary}</p>
|
|
6186
|
+
</div>
|
|
6187
|
+
`;
|
|
6188
|
+
}).join("")}
|
|
6189
|
+
</div>
|
|
6190
|
+
</div>
|
|
6191
|
+
</div>
|
|
6192
|
+
`;
|
|
6193
|
+
}).join("")}
|
|
6194
|
+
</div>
|
|
6195
|
+
|
|
6196
|
+
<footer>
|
|
6197
|
+
Generated by CBrowser v7.1.0 | Test completed in ${(duration / 1000).toFixed(1)}s
|
|
6198
|
+
</footer>
|
|
6199
|
+
</div>
|
|
6200
|
+
</body>
|
|
6201
|
+
</html>`;
|
|
6202
|
+
}
|
|
5215
6203
|
//# sourceMappingURL=browser.js.map
|