simple-test.js 3.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192
  1. const { chromium } = require('playwright');
  2. (async () => {
  3. const browser = await chromium.launch({ headless: true });
  4. const context = await browser.newContext();
  5. const page = await context.newPage();
  6. console.log('=== 视频生成功能测试 ===\n');
  7. const errors = [];
  8. page.on('console', msg => {
  9. if (msg.type() === 'error') {
  10. errors.push(msg.text());
  11. }
  12. });
  13. try {
  14. // 1. 测试列表页面
  15. console.log('1. 测试列表页面...');
  16. await page.goto('http://localhost:5173/#/pages/video-generator/index', {
  17. waitUntil: 'networkidle',
  18. timeout: 30000
  19. });
  20. await page.waitForTimeout(3000);
  21. await page.screenshot({ path: 'test1-list.png', fullPage: true });
  22. const hasListContent = await page.locator('text=视频生成').first().isVisible();
  23. const hasCreateBtn = await page.locator('text=创建新视频').first().isVisible();
  24. console.log(' - 页面标题:', hasListContent ? '✅' : '❌');
  25. console.log(' - 创建按钮:', hasCreateBtn ? '✅' : '❌');
  26. // 2. 进入创建页面
  27. console.log('\n2. 测试创建页面...');
  28. await page.goto('http://localhost:5173/#/pages/video-generator/create', {
  29. waitUntil: 'networkidle',
  30. timeout: 30000
  31. });
  32. await page.waitForTimeout(2000);
  33. await page.screenshot({ path: 'test2-create.png', fullPage: true });
  34. const hasTitleInput = await page.locator('input[placeholder="给视频起个标题"]').first().isVisible();
  35. const hasImageBtn = await page.locator('text=添加图片').first().isVisible();
  36. const hasAudioBtn = await page.locator('text=添加音频').first().isVisible();
  37. const hasNextBtn = await page.locator('text=下一步').first().isVisible();
  38. console.log(' - 标题输入框:', hasTitleInput ? '✅' : '❌');
  39. console.log(' - 添加图片按钮:', hasImageBtn ? '✅' : '❌');
  40. console.log(' - 添加音频按钮:', hasAudioBtn ? '✅' : '❌');
  41. console.log(' - 下一步按钮:', hasNextBtn ? '✅' : '❌');
  42. // 3. 测试API
  43. console.log('\n3. 测试后端API...');
  44. const apiRes = await page.evaluate(async () => {
  45. try {
  46. const res = await fetch('http://localhost:3000/api/video/projects');
  47. const data = await res.json();
  48. return { ok: res.ok, status: res.status, data };
  49. } catch (e) {
  50. return { error: e.message };
  51. }
  52. });
  53. if (apiRes.error) {
  54. console.log(' ❌ API错误:', apiRes.error);
  55. } else {
  56. console.log(' ✅ API正常');
  57. console.log(' - 状态:', apiRes.status);
  58. console.log(' - 项目数:', apiRes.data?.data?.items?.length || 0);
  59. }
  60. // 4. 检查错误
  61. console.log('\n4. 检查JavaScript错误...');
  62. if (errors.length > 0) {
  63. console.log(' ⚠️ 发现', errors.length, '个错误:');
  64. errors.slice(0, 5).forEach((err, i) => {
  65. console.log(` ${i + 1}. ${err.substring(0, 100)}`);
  66. });
  67. } else {
  68. console.log(' ✅ 无JavaScript错误');
  69. }
  70. console.log('\n✅ 测试完成!');
  71. console.log('截图已保存: test1-list.png, test2-create.png');
  72. } catch (error) {
  73. console.error('\n❌ 测试失败:', error.message);
  74. await page.screenshot({ path: 'test-error.png', fullPage: true });
  75. }
  76. await browser.close();
  77. process.exit(0);
  78. })();