import { test } from '@playwright/test'; test('简单的访问和截图测试', async ({ page }) => { console.log('\n🚀 开始简单的访问测试\n'); // 1. 访问前端 console.log('📄 访问 http://localhost:3000'); await page.goto('http://localhost:3000', { waitUntil: 'networkidle' }); await page.screenshot({ path: 'screenshots/simple-1-visit.png', fullPage: true }); console.log('✅ 访问页面完成,截图已保存\n'); // 获取页面信息 const title = await page.title(); const url = page.url(); console.log(`📋 页面标题: ${title}`); console.log(`🔗 当前 URL: ${url}\n`); // 查找页面上的文本内容 const pageText = await page.textContent('body'); console.log('📝 页面包含的文本:'); console.log(pageText?.substring(0, 200) + '...\n'); // 查找所有输入框 const inputs = await page.locator('input').all(); console.log(`🔍 找到 ${inputs.length} 个输入框`); // 查找所有按钮 const buttons = await page.locator('button').all(); console.log(`🔍 找到 ${buttons.length} 个按钮\n`); // 尝试找到用户名和密码输入框 const usernameInput = page.locator('input').first(); const passwordInput = page.locator('input').nth(1); const submitButton = page.locator('button').first(); if (await usernameInput.count() > 0) { await usernameInput.fill('testuser'); console.log('✅ 已填写用户名'); } if (await passwordInput.count() > 0) { await passwordInput.fill('Password123@'); console.log('✅ 已填写密码'); } await page.screenshot({ path: 'screenshots/simple-2-filled.png', fullPage: true }); console.log('✅ 表单填写完成,截图已保存\n'); // 等待一下 await page.waitForTimeout(2000); console.log('✨ 测试完成!'); });