verify-qa.tsā¢2.64 kB
import { browserManager } from './browser.js';
import path from 'path';
import fs from 'fs';
async function runDemo() {
console.log('š Starting QA Agent Demo...');
try {
// 1. Navigate
// Resolve path relative to the script location or CWD to be robust
let testPath = path.resolve(process.cwd(), 'test-site/index.html');
if (!fs.existsSync(testPath)) {
// Try looking inside qa-agent-mcp if running from parent
testPath = path.resolve(process.cwd(), 'qa-agent-mcp/test-site/index.html');
}
if (!fs.existsSync(testPath)) {
throw new Error(`Could not find test file at: ${testPath}`);
}
const url = `file://${testPath}`;
console.log(`\n1ļøā£ Navigating to: ${url}`);
await browserManager.navigate(url);
// 2. Type Username
console.log('\n2ļøā£ Typing username...');
await browserManager.type('#username', 'TestUser_001');
// 3. Click Login
console.log('\n3ļøā£ Clicking login button...');
await browserManager.click('#login-btn');
// 4. Verify Result
console.log('\n4ļøā£ Verifying result...');
const text = await browserManager.getText('#result');
console.log(` Found text: "${text}"`);
if (text === 'Welcome back, TestUser_001!') {
console.log(' ā
TEST PASSED: Login successful');
} else {
console.error(' ā TEST FAILED: Unexpected text');
}
// 5. Screenshot
console.log('\n5ļøā£ Taking evidence screenshot...');
const screenshotMsg = await browserManager.screenshot('evidence_success');
console.log(` ${screenshotMsg}`);
// 6. Premium Feature: Mobile Simulation
console.log('\n6ļøā£ [PREMIUM] Testing Mobile Viewport (iPhone 12)...');
await browserManager.setViewport(390, 844, true);
await browserManager.screenshot('evidence_mobile');
console.log(' šø Mobile screenshot saved');
// 7. Premium Feature: Console Logs
console.log('\n7ļøā£ [PREMIUM] Checking Console Logs...');
const logs = await browserManager.getConsoleLogs();
console.log(' š Captured Logs:');
console.log(logs);
console.log('\n⨠Demo completed successfully!');
} catch (error: any) {
console.error('\nā Error:', error.message);
} finally {
// Keep browser open for a moment to see result
await new Promise(resolve => setTimeout(resolve, 3000));
await browserManager.close();
}
}
runDemo();