test-working-tab-final.js•4.85 kB
#!/usr/bin/env node
/**
* TASK-001: Final Test - Working Tab Interaction
* Now that we know the Composer works with automation, test the interaction
*/
import { chromium } from 'playwright';
async function testWorkingTabFinal() {
console.log('🎯 TASK-001: Final Test - Working Tab Interaction\n');
try {
console.log('1️⃣ Connecting to existing browser...');
const context = await chromium.launchPersistentContext('/tmp/composer-simple', {
headless: false,
timeout: 30000
});
console.log('2️⃣ Getting all pages...');
const pages = context.pages();
console.log(` Found ${pages.length} tabs`);
console.log('3️⃣ Looking for working Composer tab...');
let workingPage = null;
for (let i = 0; i < pages.length; i++) {
const page = pages[i];
const url = page.url();
const title = await page.title();
console.log(` Tab ${i + 1}: "${title}" - ${url.substring(0, 60)}...`);
if (url.includes('composer.euconquisto.com')) {
console.log(` 📋 Found Composer tab!`);
// Check for the "NOVA COMPOSIÇÃO" button we can see in the screenshot
const novaComposicaoCount = await page.locator('text=NOVA COMPOSIÇÃO').count();
console.log(` "NOVA COMPOSIÇÃO" buttons found: ${novaComposicaoCount}`);
if (novaComposicaoCount > 0) {
workingPage = page;
console.log(` ✅ This is the working tab with NOVA COMPOSIÇÃO button!`);
break;
}
}
}
if (workingPage) {
console.log('\n4️⃣ Testing interaction with NOVA COMPOSIÇÃO button...');
// Take screenshot before interaction
await workingPage.screenshot({
path: `before-nova-composicao-click-${Date.now()}.png`,
fullPage: true
});
try {
// Click the NOVA COMPOSIÇÃO button
console.log(' 🖱️ Clicking NOVA COMPOSIÇÃO button...');
await workingPage.click('text=NOVA COMPOSIÇÃO');
console.log(' ✅ Button clicked successfully!');
// Wait for response
await workingPage.waitForTimeout(3000);
// Take screenshot after click
await workingPage.screenshot({
path: `after-nova-composicao-click-${Date.now()}.png`,
fullPage: true
});
// Check if URL changed or new content appeared
const newURL = workingPage.url();
console.log(` 📍 Current URL: ${newURL.substring(0, 80)}...`);
// Look for composition editor interface
const hasEditor = await workingPage.locator('[contenteditable], textarea, input[type="text"]').count();
console.log(` 📝 Editable elements found: ${hasEditor}`);
if (hasEditor > 0 || newURL.includes('composition') || newURL.includes('editor')) {
console.log('\n🎉 TASK-001 SUCCESS: New composition creation working!');
console.log(' ✅ Found working Composer interface');
console.log(' ✅ Successfully clicked NOVA COMPOSIÇÃO');
console.log(' ✅ Composition editor interface appeared');
// Test metadata editing
console.log('\n5️⃣ Testing composition metadata editing...');
// Look for title field
const titleSelectors = [
'input[placeholder*="título"]',
'input[placeholder*="title"]',
'[data-testid="title"]',
'input[type="text"]'
];
for (const selector of titleSelectors) {
try {
const titleField = await workingPage.waitForSelector(selector, { timeout: 3000 });
if (titleField) {
console.log(` 📝 Found title field with: ${selector}`);
await titleField.fill('Test Composition from MCP');
console.log(' ✅ Title filled successfully!');
break;
}
} catch (error) {
// Try next selector
}
}
} else {
console.log('\n⚠️ Button clicked but no editor interface detected');
console.log(' The click was successful but may need more time or different detection');
}
} catch (error) {
console.log(` ❌ Click failed: ${error.message}`);
}
} else {
console.log('\n❌ No working Composer tab found');
console.log(' Please ensure the Composer tab is open and loaded');
}
console.log('\n⏳ Test complete. Browser remains open for inspection.');
} catch (error) {
console.error('❌ Test failed:', error.message);
}
}
testWorkingTabFinal().catch(console.error);