test-history-batch-delete.js 2.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061
  1. const { chromium } = require('playwright');
  2. (async () => {
  3. console.log('🧪 开始测试批量删除功能...');
  4. const browser = await chromium.launch({ headless: false });
  5. const context = await browser.newContext();
  6. const page = await context.newPage();
  7. try {
  8. console.log('📍 打开历史记录页面...');
  9. await page.goto('http://localhost:5173/#/pages/history/index');
  10. await page.waitForTimeout(3000);
  11. console.log('✅ 页面加载成功!');
  12. console.log('📸 截图保存为 history-page.png');
  13. await page.screenshot({ path: 'history-page.png' });
  14. // 检查是否有"编辑"按钮
  15. console.log('🔍 检查编辑按钮...');
  16. const editButton = page.locator('text=编辑').first();
  17. if (await editButton.isVisible({ timeout: 5000 })) {
  18. console.log('✅ 找到编辑按钮!');
  19. // 点击编辑按钮
  20. console.log('🖱️ 点击编辑按钮...');
  21. await editButton.click();
  22. await page.waitForTimeout(1000);
  23. console.log('📸 编辑模式截图保存为 edit-mode.png');
  24. await page.screenshot({ path: 'edit-mode.png' });
  25. // 检查是否有批量操作按钮
  26. console.log('🔍 检查批量操作按钮...');
  27. const selectAllButton = page.locator('text=全选,text=取消全选').first();
  28. const deleteButton = page.locator('text=删除').first();
  29. const cancelButton = page.locator('text=取消').first();
  30. if (await selectAllButton.isVisible({ timeout: 2000 })) {
  31. console.log('✅ 找到全选/取消全选按钮!');
  32. }
  33. if (await deleteButton.isVisible({ timeout: 2000 })) {
  34. console.log('✅ 找到删除按钮!');
  35. }
  36. if (await cancelButton.isVisible({ timeout: 2000 })) {
  37. console.log('✅ 找到取消按钮!');
  38. }
  39. console.log('🎉 批量删除功能的UI组件都已实现!');
  40. } else {
  41. console.log('⚠️ 未找到编辑按钮,可能需要登录或没有历史记录');
  42. }
  43. } catch (error) {
  44. console.error('❌ 测试出错:', error);
  45. } finally {
  46. console.log('🔚 测试完成,浏览器将在5秒后关闭...');
  47. await page.waitForTimeout(5000);
  48. await browser.close();
  49. }
  50. })();