/**
* Manual test for screenshot download and analysis
* Run this to verify screenshot tools work with real Zebrunner URLs
*
* Usage:
* npm run build && node dist/tests/manual-screenshot-test.js
*/
import { ZebrunnerReportingClient } from '../src/api/reporting-client.js';
import { analyzeScreenshot, saveScreenshotToTemp } from '../src/utils/screenshot-analyzer.js';
import { config } from 'dotenv';
config();
async function testScreenshotTools() {
console.log('๐งช Testing Screenshot Download and Analysis\n');
const baseUrl = process.env.ZEBRUNNER_URL || 'https://your-workspace.zebrunner.com';
const token = process.env.ZEBRUNNER_TOKEN;
if (!token) {
console.error('โ ZEBRUNNER_TOKEN not set in environment');
process.exit(1);
}
const client = new ZebrunnerReportingClient({
baseUrl,
accessToken: token,
debug: true
});
// Test screenshot URL from the user's example
const testScreenshotUrl = 'https://your-workspace.zebrunner.com/files/19a3c384-a06a-10d7-1aa1-cf9c3244b021';
console.log(`๐ธ Test Screenshot URL: ${testScreenshotUrl}\n`);
try {
// Test 1: Download Screenshot
console.log('1๏ธโฃ Testing screenshot download...');
const imageBuffer = await client.downloadScreenshot(testScreenshotUrl);
console.log(`โ
Downloaded ${imageBuffer.length} bytes\n`);
// Test 2: Save to file
console.log('2๏ธโฃ Saving screenshot to file...');
const filePath = await saveScreenshotToTemp(imageBuffer, 'test_screenshot.png');
console.log(`โ
Saved to: ${filePath}\n`);
// Test 3: Basic Analysis (no OCR)
console.log('3๏ธโฃ Running basic analysis (no OCR)...');
const basicAnalysis = await analyzeScreenshot(imageBuffer, { enableOCR: false });
console.log('โ
Basic Analysis Results:');
console.log(` - Dimensions: ${basicAnalysis.metadata.width}x${basicAnalysis.metadata.height}`);
console.log(` - Format: ${basicAnalysis.metadata.format}`);
console.log(` - Size: ${Math.round(basicAnalysis.metadata.size / 1024)} KB`);
console.log(` - Orientation: ${basicAnalysis.metadata.orientation}`);
console.log(` - Aspect Ratio: ${basicAnalysis.metadata.aspectRatio}\n`);
// Test 4: Analysis with OCR (slower)
console.log('4๏ธโฃ Running analysis with OCR (this may take 5-10 seconds)...');
const ocrAnalysis = await analyzeScreenshot(imageBuffer, { enableOCR: true });
console.log('โ
OCR Analysis Results:');
console.log(` - Text confidence: ${Math.round(ocrAnalysis.ocrText?.confidence || 0)}%`);
console.log(` - Lines extracted: ${ocrAnalysis.ocrText?.lines.length || 0}`);
if (ocrAnalysis.ocrText && ocrAnalysis.ocrText.lines.length > 0) {
console.log(' - First 5 lines:');
ocrAnalysis.ocrText.lines.slice(0, 5).forEach((line, idx) => {
if (line.trim()) {
console.log(` ${idx + 1}. ${line}`);
}
});
}
console.log('');
// Test 5: Device Detection
if (ocrAnalysis.deviceInfo?.detectedDevice) {
console.log('5๏ธโฃ Device Detection:');
console.log(` - Device: ${ocrAnalysis.deviceInfo.detectedDevice}`);
console.log('');
}
// Test 6: UI Elements
if (ocrAnalysis.uiElements) {
console.log('6๏ธโฃ UI Elements Detected:');
if (ocrAnalysis.uiElements.hasEmptyState) console.log(' - โ
Empty State');
if (ocrAnalysis.uiElements.hasLoadingIndicator) console.log(' - โณ Loading Indicator');
if (ocrAnalysis.uiElements.hasErrorDialog) console.log(' - โ Error Dialog');
if (ocrAnalysis.uiElements.hasNavigationBar) console.log(' - ๐งญ Navigation Bar');
console.log('');
}
console.log('๐ All tests passed!\n');
console.log('๐ Summary:');
console.log(' โ
Screenshot download: Working');
console.log(' โ
File saving: Working');
console.log(' โ
Metadata extraction: Working');
console.log(' โ
OCR text extraction: Working');
console.log(' โ
Device detection: Working');
console.log(' โ
UI element detection: Working\n');
console.log('๐ก Next steps:');
console.log(' 1. Test with analyze_screenshot MCP tool in Claude Desktop');
console.log(' 2. Use "detailed" analysis type to pass image to Claude Vision');
console.log(' 3. Integrate with analyze_test_failure for automatic screenshot analysis\n');
} catch (error) {
console.error('โ Test failed:', error);
process.exit(1);
}
}
// Run the test
testScreenshotTools().catch(console.error);