operation-log.spec.js 5.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143
  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('OL-001: 查看操作日志列表', async ({ page }) => {
  14. await page.goto(`${BASE_URL}/#/system/log`);
  15. await page.waitForLoadState('networkidle');
  16. await page.waitForTimeout(1000);
  17. });
  18. test('OL-002: 按操作人筛选', async ({ page }) => {
  19. await page.goto(`${BASE_URL}/#/system/log`);
  20. await page.waitForLoadState('networkidle');
  21. const operatorInput = page.getByPlaceholder('请输入操作人');
  22. if (await operatorInput.isVisible()) {
  23. await operatorInput.fill('admin');
  24. await page.getByRole('button', { name: '查询' }).click();
  25. await page.waitForTimeout(1000);
  26. }
  27. });
  28. test('OL-003: 按操作类型筛选', async ({ page }) => {
  29. await page.goto(`${BASE_URL}/#/system/log`);
  30. await page.waitForLoadState('networkidle');
  31. const typeSelect = page.locator('.el-select').first();
  32. if (await typeSelect.isVisible()) {
  33. await typeSelect.click();
  34. await page.waitForTimeout(300);
  35. }
  36. });
  37. test('OL-004: 按时间范围筛选', async ({ page }) => {
  38. await page.goto(`${BASE_URL}/#/system/log`);
  39. await page.waitForLoadState('networkidle');
  40. });
  41. test('OL-005: 按模块筛选', async ({ page }) => {
  42. await page.goto(`${BASE_URL}/#/system/log`);
  43. await page.waitForLoadState('networkidle');
  44. });
  45. test('OL-006: 日志分页-每页20条', async ({ page }) => {
  46. await page.goto(`${BASE_URL}/#/system/log`);
  47. await page.waitForLoadState('networkidle');
  48. const pageSizeSelect = page.locator('.el-select').last();
  49. if (await pageSizeSelect.isVisible()) {
  50. await pageSizeSelect.click();
  51. await page.waitForTimeout(300);
  52. await page.getByRole('option', { name: '20 条/页' }).click();
  53. await page.waitForTimeout(1000);
  54. }
  55. });
  56. test('OL-007: 日志分页-每页50条', async ({ page }) => {
  57. await page.goto(`${BASE_URL}/#/system/log`);
  58. await page.waitForLoadState('networkidle');
  59. });
  60. test('OL-008: 导出日志Excel', async ({ page }) => {
  61. await page.goto(`${BASE_URL}/#/system/log`);
  62. await page.waitForLoadState('networkidle');
  63. await page.waitForTimeout(1000);
  64. });
  65. test('OL-009: 重置查询条件', async ({ page }) => {
  66. await page.goto(`${BASE_URL}/#/system/log`);
  67. await page.waitForLoadState('networkidle');
  68. const operatorInput = page.getByPlaceholder('请输入操作人');
  69. if (await operatorInput.isVisible()) {
  70. await operatorInput.fill('test');
  71. await page.getByRole('button', { name: '重置' }).click();
  72. await page.waitForTimeout(500);
  73. await expect(operatorInput).toHaveValue('');
  74. }
  75. });
  76. test('OL-010: 日志详情查看', async ({ page }) => {
  77. await page.goto(`${BASE_URL}/#/system/log`);
  78. await page.waitForLoadState('networkidle');
  79. const detailBtn = page.getByRole('button', { name: '详情' }).first();
  80. if (await detailBtn.isVisible()) {
  81. await detailBtn.click();
  82. await page.waitForTimeout(500);
  83. }
  84. });
  85. });
  86. test.describe('管理员管理测试', () => {
  87. test.beforeEach(async ({ page }) => {
  88. await page.goto(BASE_URL);
  89. await page.waitForLoadState('networkidle');
  90. await page.getByPlaceholder('请输入用户名').fill(TEST_ADMIN.username);
  91. await page.getByPlaceholder('请输入密码').fill(TEST_ADMIN.password);
  92. await page.getByRole('button', { name: '登 录' }).click();
  93. await page.waitForURL(`${BASE_URL}/#/user/app`, { timeout: 10000 });
  94. });
  95. test('OL-020: 新增管理员-用户名重复验证', async ({ page }) => {
  96. await page.goto(`${BASE_URL}/#/system`);
  97. await page.waitForLoadState('networkidle');
  98. const addBtn = page.getByRole('button', { name: '新增管理员' });
  99. if (await addBtn.isVisible()) {
  100. await addBtn.click();
  101. await page.waitForTimeout(500);
  102. await page.getByRole('button', { name: '保存' }).click();
  103. await page.waitForTimeout(500);
  104. }
  105. });
  106. test('OL-021: 禁用管理员', async ({ page }) => {
  107. await page.goto(`${BASE_URL}/#/system`);
  108. await page.waitForLoadState('networkidle');
  109. });
  110. test('OL-022: 启用管理员', async ({ page }) => {
  111. await page.goto(`${BASE_URL}/#/system`);
  112. await page.waitForLoadState('networkidle');
  113. });
  114. test('OL-023: 管理员密码格式验证', async ({ page }) => {
  115. await page.goto(`${BASE_URL}/#/system`);
  116. await page.waitForLoadState('networkidle');
  117. const addBtn = page.getByRole('button', { name: '新增管理员' });
  118. if (await addBtn.isVisible()) {
  119. await addBtn.click();
  120. await page.waitForTimeout(500);
  121. await page.getByPlaceholder('请输入密码').fill('123');
  122. await page.getByRole('button', { name: '保存' }).click();
  123. await page.waitForTimeout(500);
  124. }
  125. });
  126. });