content.spec.js 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109
  1. const { test, expect } = require('@playwright/test');
  2. const BASE_URL = 'https://ajy.danclub.cn';
  3. const TEST_ADMIN = { username: 'admin', password: 'admin123' };
  4. test.describe('内容管理测试', () => {
  5. test.beforeEach(async ({ page }) => {
  6. await page.goto(BASE_URL);
  7. await page.waitForLoadState('networkidle');
  8. await page.getByPlaceholder('请输入用户名').fill(TEST_ADMIN.username);
  9. await page.getByPlaceholder('请输入密码').fill(TEST_ADMIN.password);
  10. await page.getByRole('button', { name: '登 录' }).click();
  11. await page.waitForURL(`${BASE_URL}/#/user/app`, { timeout: 10000 });
  12. });
  13. test('CM-001: 查看文章列表', async ({ page }) => {
  14. await page.goto(`${BASE_URL}/#/content`);
  15. await page.waitForLoadState('networkidle');
  16. await page.waitForTimeout(1000);
  17. });
  18. test('CM-002: 按标题搜索文章', async ({ page }) => {
  19. await page.goto(`${BASE_URL}/#/content`);
  20. await page.waitForLoadState('networkidle');
  21. const searchInput = page.getByPlaceholder('请输入文章标题');
  22. if (await searchInput.isVisible()) {
  23. await searchInput.fill('艾灸');
  24. await page.getByRole('button', { name: '查询' }).click();
  25. await page.waitForTimeout(1000);
  26. }
  27. });
  28. test('CM-003: 按分类筛选文章', async ({ page }) => {
  29. await page.goto(`${BASE_URL}/#/content`);
  30. await page.waitForLoadState('networkidle');
  31. });
  32. test('CM-004: 按状态筛选文章', async ({ page }) => {
  33. await page.goto(`${BASE_URL}/#/content`);
  34. await page.waitForLoadState('networkidle');
  35. });
  36. test('CM-010: 新增文章-必填验证', async ({ page }) => {
  37. await page.goto(`${BASE_URL}/#/content`);
  38. await page.waitForLoadState('networkidle');
  39. const addBtn = page.getByRole('button', { name: '新增' });
  40. if (await addBtn.isVisible()) {
  41. await addBtn.click();
  42. await page.waitForTimeout(500);
  43. await page.getByRole('button', { name: '保存' }).click();
  44. await page.waitForTimeout(500);
  45. }
  46. });
  47. test('CM-011: 文章标题超长验证', async ({ page }) => {
  48. await page.goto(`${BASE_URL}/#/content`);
  49. await page.waitForLoadState('networkidle');
  50. });
  51. test('CM-012: 发布文章', async ({ page }) => {
  52. await page.goto(`${BASE_URL}/#/content`);
  53. await page.waitForLoadState('networkidle');
  54. const addBtn = page.getByRole('button', { name: '新增' });
  55. if (await addBtn.isVisible()) {
  56. await addBtn.click();
  57. await page.waitForTimeout(500);
  58. }
  59. });
  60. test('CM-013: 编辑文章', async ({ page }) => {
  61. await page.goto(`${BASE_URL}/#/content`);
  62. await page.waitForLoadState('networkidle');
  63. const editBtn = page.getByRole('button', { name: '编辑' }).first();
  64. if (await editBtn.isVisible()) {
  65. await editBtn.click();
  66. await page.waitForTimeout(500);
  67. }
  68. });
  69. test('CM-014: 删除文章', async ({ page }) => {
  70. await page.goto(`${BASE_URL}/#/content`);
  71. await page.waitForLoadState('networkidle');
  72. });
  73. test('CM-015: 审核文章', async ({ page }) => {
  74. await page.goto(`${BASE_URL}/#/content`);
  75. await page.waitForLoadState('networkidle');
  76. });
  77. test('CM-016: 批量发布文章', async ({ page }) => {
  78. await page.goto(`${BASE_URL}/#/content`);
  79. await page.waitForLoadState('networkidle');
  80. const checkbox = page.locator('.el-table__header .el-checkbox').first();
  81. if (await checkbox.isVisible()) {
  82. await checkbox.click();
  83. await page.waitForTimeout(300);
  84. }
  85. });
  86. test('CM-017: 文章分页切换', async ({ page }) => {
  87. await page.goto(`${BASE_URL}/#/content`);
  88. await page.waitForLoadState('networkidle');
  89. const nextButton = page.locator('.btn-next').first();
  90. if (await nextButton.isVisible()) {
  91. await nextButton.click();
  92. await page.waitForTimeout(1000);
  93. }
  94. });
  95. });