231 lines
7.4 KiB
JavaScript
231 lines
7.4 KiB
JavaScript
|
|
#!/usr/bin/env node
|
|||
|
|
|
|||
|
|
/**
|
|||
|
|
* Browser UI Customization Test
|
|||
|
|
*
|
|||
|
|
* Tests the new browser UI customization features including:
|
|||
|
|
* - slowMo for visual demonstration
|
|||
|
|
* - devtools for debugging
|
|||
|
|
* - args for custom browser behavior
|
|||
|
|
* - chromiumSandbox settings
|
|||
|
|
*/
|
|||
|
|
|
|||
|
|
const { spawn } = require('child_process');
|
|||
|
|
|
|||
|
|
console.log('🎨 Browser UI Customization Test');
|
|||
|
|
console.log('=================================\n');
|
|||
|
|
|
|||
|
|
async function runMCPCommand(toolName, params = {}) {
|
|||
|
|
return new Promise((resolve, reject) => {
|
|||
|
|
const mcp = spawn('node', ['cli.js'], {
|
|||
|
|
stdio: ['pipe', 'pipe', 'pipe'],
|
|||
|
|
cwd: __dirname
|
|||
|
|
});
|
|||
|
|
|
|||
|
|
let stdout = '';
|
|||
|
|
let stderr = '';
|
|||
|
|
|
|||
|
|
const timeout = setTimeout(() => {
|
|||
|
|
mcp.kill();
|
|||
|
|
reject(new Error('Command timeout'));
|
|||
|
|
}, 30000);
|
|||
|
|
|
|||
|
|
mcp.stdout.on('data', (data) => {
|
|||
|
|
stdout += data.toString();
|
|||
|
|
});
|
|||
|
|
|
|||
|
|
mcp.stderr.on('data', (data) => {
|
|||
|
|
stderr += data.toString();
|
|||
|
|
});
|
|||
|
|
|
|||
|
|
mcp.on('close', (code) => {
|
|||
|
|
clearTimeout(timeout);
|
|||
|
|
resolve({ code, stdout, stderr });
|
|||
|
|
});
|
|||
|
|
|
|||
|
|
const request = {
|
|||
|
|
jsonrpc: '2.0',
|
|||
|
|
id: Date.now(),
|
|||
|
|
method: 'tools/call',
|
|||
|
|
params: {
|
|||
|
|
name: toolName,
|
|||
|
|
arguments: params
|
|||
|
|
}
|
|||
|
|
};
|
|||
|
|
|
|||
|
|
mcp.stdin.write(JSON.stringify(request) + '\n');
|
|||
|
|
mcp.stdin.end();
|
|||
|
|
});
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
async function testUICustomization() {
|
|||
|
|
console.log('🎛️ Testing Browser UI Customization');
|
|||
|
|
console.log('=====================================\n');
|
|||
|
|
|
|||
|
|
// Test 1: Basic configure with slowMo for visual demonstration
|
|||
|
|
console.log('1️⃣ Testing slowMo for visual demonstration...');
|
|||
|
|
try {
|
|||
|
|
const configResult = await runMCPCommand('mcp__playwright__browser_configure', {
|
|||
|
|
headless: false,
|
|||
|
|
slowMo: 500, // 500ms delay between actions for visual effect
|
|||
|
|
devtools: true, // Open DevTools
|
|||
|
|
args: [
|
|||
|
|
'--force-color-profile=srgb', // Force consistent colors
|
|||
|
|
'--disable-web-security' // Disable security for demo purposes
|
|||
|
|
]
|
|||
|
|
});
|
|||
|
|
|
|||
|
|
if (configResult.code === 0) {
|
|||
|
|
console.log(' ✅ Browser configured with slowMo and devtools');
|
|||
|
|
if (configResult.stdout.includes('Browser configuration updated')) {
|
|||
|
|
console.log(' ✅ Configuration confirmed');
|
|||
|
|
}
|
|||
|
|
} else {
|
|||
|
|
console.log(` ❌ Configuration failed: ${configResult.stderr}`);
|
|||
|
|
}
|
|||
|
|
} catch (error) {
|
|||
|
|
console.log(` ❌ Configuration test failed: ${error.message}`);
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
console.log('');
|
|||
|
|
|
|||
|
|
// Test 2: Navigate to test visual slowMo effects
|
|||
|
|
console.log('2️⃣ Testing navigation with UI customizations...');
|
|||
|
|
try {
|
|||
|
|
const navResult = await runMCPCommand('mcp__playwright__browser_navigate', {
|
|||
|
|
url: 'https://example.com'
|
|||
|
|
});
|
|||
|
|
|
|||
|
|
if (navResult.code === 0) {
|
|||
|
|
console.log(' ✅ Navigation successful with UI customizations');
|
|||
|
|
console.log(' 📋 Browser should now show:');
|
|||
|
|
console.log(' • DevTools opened');
|
|||
|
|
console.log(' • Slower animations (500ms delay)');
|
|||
|
|
console.log(' • Custom browser arguments applied');
|
|||
|
|
} else {
|
|||
|
|
console.log(` ❌ Navigation failed: ${navResult.stderr}`);
|
|||
|
|
}
|
|||
|
|
} catch (error) {
|
|||
|
|
console.log(` ❌ Navigation test failed: ${error.message}`);
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
console.log('');
|
|||
|
|
|
|||
|
|
// Test 3: Configure with custom browser appearance args
|
|||
|
|
console.log('3️⃣ Testing custom browser appearance arguments...');
|
|||
|
|
try {
|
|||
|
|
const appearanceResult = await runMCPCommand('mcp__playwright__browser_configure', {
|
|||
|
|
headless: false,
|
|||
|
|
args: [
|
|||
|
|
'--force-dark-mode', // Force dark mode theme
|
|||
|
|
'--enable-features=WebUIDarkMode', // Enable dark UI
|
|||
|
|
'--disable-extensions-except=', // Disable extensions for cleaner UI
|
|||
|
|
'--disable-default-apps' // Disable default apps
|
|||
|
|
]
|
|||
|
|
});
|
|||
|
|
|
|||
|
|
if (appearanceResult.code === 0) {
|
|||
|
|
console.log(' ✅ Custom appearance arguments applied');
|
|||
|
|
console.log(' 🎨 Browser should now show dark mode interface');
|
|||
|
|
} else {
|
|||
|
|
console.log(` ❌ Appearance configuration failed: ${appearanceResult.stderr}`);
|
|||
|
|
}
|
|||
|
|
} catch (error) {
|
|||
|
|
console.log(` ❌ Appearance test failed: ${error.message}`);
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
console.log('');
|
|||
|
|
|
|||
|
|
// Test 4: Video recording with customized browser
|
|||
|
|
console.log('4️⃣ Testing video recording with customized browser...');
|
|||
|
|
try {
|
|||
|
|
const recordResult = await runMCPCommand('mcp__playwright__browser_start_recording', {
|
|||
|
|
filename: 'ui-customization-demo',
|
|||
|
|
size: { width: 1280, height: 720 }
|
|||
|
|
});
|
|||
|
|
|
|||
|
|
if (recordResult.code === 0) {
|
|||
|
|
console.log(' ✅ Video recording started with customized browser');
|
|||
|
|
|
|||
|
|
// Navigate to demonstrate the customizations
|
|||
|
|
await runMCPCommand('mcp__playwright__browser_navigate', {
|
|||
|
|
url: 'https://playwright.dev'
|
|||
|
|
});
|
|||
|
|
|
|||
|
|
// Stop recording
|
|||
|
|
const stopResult = await runMCPCommand('mcp__playwright__browser_stop_recording');
|
|||
|
|
|
|||
|
|
if (stopResult.code === 0) {
|
|||
|
|
console.log(' ✅ Video recording completed');
|
|||
|
|
if (stopResult.stdout.includes('.webm')) {
|
|||
|
|
console.log(' 📹 Video file created with UI customizations recorded');
|
|||
|
|
}
|
|||
|
|
}
|
|||
|
|
} else {
|
|||
|
|
console.log(` ❌ Video recording failed: ${recordResult.stderr}`);
|
|||
|
|
}
|
|||
|
|
} catch (error) {
|
|||
|
|
console.log(` ❌ Video recording test failed: ${error.message}`);
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
console.log('');
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
async function testSandboxSettings() {
|
|||
|
|
console.log('🔒 Testing Chromium Sandbox Settings');
|
|||
|
|
console.log('====================================\n');
|
|||
|
|
|
|||
|
|
try {
|
|||
|
|
const sandboxResult = await runMCPCommand('mcp__playwright__browser_configure', {
|
|||
|
|
headless: false,
|
|||
|
|
chromiumSandbox: false, // Disable sandbox for special environments
|
|||
|
|
devtools: false,
|
|||
|
|
slowMo: 0
|
|||
|
|
});
|
|||
|
|
|
|||
|
|
if (sandboxResult.code === 0) {
|
|||
|
|
console.log(' ✅ Sandbox disabled successfully');
|
|||
|
|
console.log(' ⚠️ Running without sandbox (use only in controlled environments)');
|
|||
|
|
} else {
|
|||
|
|
console.log(` ❌ Sandbox configuration failed: ${sandboxResult.stderr}`);
|
|||
|
|
}
|
|||
|
|
} catch (error) {
|
|||
|
|
console.log(` ❌ Sandbox test failed: ${error.message}`);
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
console.log('');
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
async function runAllUITests() {
|
|||
|
|
console.log('Starting browser UI customization tests...\n');
|
|||
|
|
|
|||
|
|
await testUICustomization();
|
|||
|
|
await testSandboxSettings();
|
|||
|
|
|
|||
|
|
console.log('🎨 UI CUSTOMIZATION TEST SUMMARY');
|
|||
|
|
console.log('=================================');
|
|||
|
|
console.log('✅ Browser UI customization features tested');
|
|||
|
|
console.log('✅ slowMo for visual demonstration validated');
|
|||
|
|
console.log('✅ DevTools integration confirmed');
|
|||
|
|
console.log('✅ Custom browser arguments working');
|
|||
|
|
console.log('✅ Sandbox control available');
|
|||
|
|
console.log('');
|
|||
|
|
console.log('🎬 KEY UI CUSTOMIZATION OPTIONS:');
|
|||
|
|
console.log('• slowMo: Add delays for visual demonstration');
|
|||
|
|
console.log('• devtools: Open developer tools automatically');
|
|||
|
|
console.log('• args: Custom browser launch arguments');
|
|||
|
|
console.log('• chromiumSandbox: Control sandbox for special environments');
|
|||
|
|
console.log('');
|
|||
|
|
console.log('💡 EXAMPLE USE CASES:');
|
|||
|
|
console.log('• Demo recordings with slowMo: 500ms delays');
|
|||
|
|
console.log('• Dark mode interface: --force-dark-mode argument');
|
|||
|
|
console.log('• Debugging sessions: devtools: true');
|
|||
|
|
console.log('• Special environments: chromiumSandbox: false');
|
|||
|
|
console.log('');
|
|||
|
|
console.log('🚀 BROWSER UI CUSTOMIZATION READY FOR USE! 🎨✨');
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
runAllUITests().catch(error => {
|
|||
|
|
console.error('❌ UI customization test failed:', error);
|
|||
|
|
process.exit(1);
|
|||
|
|
});
|