Skip to main content
Glama

Better Playwright MCP

by livoras
test-v3.tsโ€ข3.47 kB
/** * Test script for v3 architecture * Tests the new Microsoft-based snapshot system with ref identifiers */ import { PlaywrightClient } from './dist/client/playwright-client.js'; async function test() { const client = new PlaywrightClient('http://localhost:3103'); try { console.log('๐Ÿงช Testing v3 Architecture\n'); console.log('='.repeat(50)); // Test 1: Create page console.log('\n๐Ÿ“‹ Test 1: Create Page'); const { pageId, snapshot } = await client.createPage( 'test-page', 'Test page for v3', 'https://example.com' ); console.log(`โœ… Page created: ${pageId}`); console.log(`๐Ÿ“ URL: ${snapshot.url}`); console.log(`๐Ÿ“„ Title: ${snapshot.title}`); // Test 2: Check snapshot format console.log('\n๐Ÿ“‹ Test 2: Snapshot Format'); console.log('Snapshot preview (first 500 chars):'); console.log(snapshot.snapshot.substring(0, 500)); // Test 3: Parse refs from snapshot console.log('\n๐Ÿ“‹ Test 3: Ref Parsing'); const refMatches = snapshot.snapshot.match(/\[ref=([^\]]+)\]/g); if (refMatches) { console.log(`โœ… Found ${refMatches.length} refs:`); refMatches.slice(0, 5).forEach(ref => { console.log(` ${ref}`); }); } else { console.log('โŒ No refs found in snapshot'); } // Test 4: Click using ref (if found) if (refMatches && refMatches.length > 0) { console.log('\n๐Ÿ“‹ Test 4: Click Action'); // Extract ref ID from first match const firstRef = refMatches[0].match(/\[ref=([^\]]+)\]/)?.[1]; if (firstRef) { console.log(`๐Ÿ–ฑ๏ธ Attempting to click ref: ${firstRef}`); try { const clickResult = await client.click(pageId, firstRef, 'First element'); console.log(`โœ… Click successful`); console.log(`๐Ÿ“ New URL: ${clickResult.url}`); } catch (error: any) { console.log(`โš ๏ธ Click failed: ${error.message}`); } } } // Test 5: Navigate console.log('\n๐Ÿ“‹ Test 5: Navigation'); const navResult = await client.navigate(pageId, 'https://www.google.com'); console.log(`โœ… Navigated to: ${navResult.url}`); console.log(`๐Ÿ“„ New title: ${navResult.title}`); // Test 6: Get fresh snapshot console.log('\n๐Ÿ“‹ Test 6: Fresh Snapshot'); const freshSnapshot = await client.getSnapshot(pageId); const freshRefs = freshSnapshot.snapshot.match(/\[ref=([^\]]+)\]/g); if (freshRefs) { console.log(`โœ… Fresh snapshot has ${freshRefs.length} refs`); } // Test 7: Screenshot console.log('\n๐Ÿ“‹ Test 7: Screenshot'); const screenshot = await client.screenshot(pageId); console.log(`โœ… Screenshot captured (${screenshot.length} bytes base64)`); // Test 8: List pages console.log('\n๐Ÿ“‹ Test 8: List Pages'); const pages = await client.listPages(); console.log(`โœ… Found ${pages.length} page(s):`); pages.forEach(p => { console.log(` - ${p.name}: ${p.url}`); }); // Test 9: Close page console.log('\n๐Ÿ“‹ Test 9: Close Page'); await client.closePage(pageId); console.log('โœ… Page closed'); console.log('\n' + '='.repeat(50)); console.log('โœ… All tests completed successfully!'); } catch (error: any) { console.error('\nโŒ Test failed:', error.message); process.exit(1); } } // Run tests test().catch(console.error);

MCP directory API

We provide all the information about MCP servers via our MCP API.

curl -X GET 'https://glama.ai/api/mcp/v1/servers/livoras/better-playwright-mcp'

If you have feedback or need assistance with the MCP directory API, please join our Discord server