user-management.spec.js 8.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229
  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('1.1 用户列表', () => {
  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('UM-001: 查看用户列表 - 显示完整列', async ({ page }) => {
  14. await page.goto(`${BASE_URL}/#/user/app`);
  15. await page.waitForLoadState('networkidle');
  16. await page.waitForTimeout(1000);
  17. const headers = await page.locator('.el-table__header th').allTextContents();
  18. expect(headers.some(h => h.includes('手机号') || h.includes('昵称'))).toBe(true);
  19. });
  20. test('UM-002: 按姓名模糊搜索', async ({ page }) => {
  21. await page.goto(`${BASE_URL}/#/user/app`);
  22. await page.waitForLoadState('networkidle');
  23. await page.getByPlaceholder('请输入手机号').fill('139');
  24. await page.getByRole('button', { name: '查询' }).click();
  25. await page.waitForTimeout(1000);
  26. });
  27. test('UM-003: 按手机号搜索', async ({ page }) => {
  28. await page.goto(`${BASE_URL}/#/user/app`);
  29. await page.waitForLoadState('networkidle');
  30. await page.getByPlaceholder('请输入手机号').fill('138');
  31. await page.getByRole('button', { name: '查询' }).click();
  32. await page.waitForTimeout(1000);
  33. });
  34. test('UM-004: 按设备编号搜索', async ({ page }) => {
  35. await page.goto(`${BASE_URL}/#/user/app`);
  36. await page.waitForLoadState('networkidle');
  37. const deviceInput = page.getByPlaceholder('请输入设备编号');
  38. if (await deviceInput.isVisible()) {
  39. await deviceInput.fill('AJY');
  40. await page.getByRole('button', { name: '查询' }).click();
  41. await page.waitForTimeout(1000);
  42. }
  43. });
  44. });
  45. test.describe('1.2 新增用户', () => {
  46. test.beforeEach(async ({ page }) => {
  47. await page.goto(BASE_URL);
  48. await page.waitForLoadState('networkidle');
  49. await page.getByPlaceholder('请输入用户名').fill(TEST_ADMIN.username);
  50. await page.getByPlaceholder('请输入密码').fill(TEST_ADMIN.password);
  51. await page.getByRole('button', { name: '登 录' }).click();
  52. await page.waitForURL(`${BASE_URL}/#/user/app`, { timeout: 10000 });
  53. });
  54. test('UM-010: 成功新增用户-打开弹窗', async ({ page }) => {
  55. await page.goto(`${BASE_URL}/#/user/app`);
  56. await page.waitForLoadState('networkidle');
  57. const addBtn = page.getByRole('button', { name: '新增' });
  58. if (await addBtn.isVisible()) {
  59. await addBtn.click();
  60. await page.waitForTimeout(500);
  61. }
  62. });
  63. test('UM-014: 手机号必填验证', async ({ page }) => {
  64. await page.goto(`${BASE_URL}/#/user/app`);
  65. await page.waitForLoadState('networkidle');
  66. const addBtn = page.getByRole('button', { name: '新增' });
  67. if (await addBtn.isVisible()) {
  68. await addBtn.click();
  69. await page.waitForTimeout(500);
  70. await page.getByRole('button', { name: '确定' }).click();
  71. await page.waitForTimeout(500);
  72. }
  73. });
  74. });
  75. test.describe('1.3 编辑用户', () => {
  76. test.beforeEach(async ({ page }) => {
  77. await page.goto(BASE_URL);
  78. await page.waitForLoadState('networkidle');
  79. await page.getByPlaceholder('请输入用户名').fill(TEST_ADMIN.username);
  80. await page.getByPlaceholder('请输入密码').fill(TEST_ADMIN.password);
  81. await page.getByRole('button', { name: '登 录' }).click();
  82. await page.waitForURL(`${BASE_URL}/#/user/app`, { timeout: 10000 });
  83. });
  84. test('UM-030: 编辑用户信息', async ({ page }) => {
  85. await page.goto(`${BASE_URL}/#/user/app`);
  86. await page.waitForLoadState('networkidle');
  87. const editBtn = page.locator('button:has-text("编辑")').first();
  88. if (await editBtn.isVisible()) {
  89. await editBtn.click();
  90. await page.waitForTimeout(500);
  91. }
  92. });
  93. test('UM-031: 编辑后重新生成坐标', async ({ page }) => {
  94. await page.goto(`${BASE_URL}/#/user/app`);
  95. await page.waitForLoadState('networkidle');
  96. const editBtn = page.locator('button:has-text("编辑")').first();
  97. if (await editBtn.isVisible()) {
  98. await editBtn.click();
  99. await page.waitForTimeout(500);
  100. }
  101. });
  102. test('UM-032: 查看用户详情', async ({ page }) => {
  103. await page.goto(`${BASE_URL}/#/user/app`);
  104. await page.waitForLoadState('networkidle');
  105. const viewBtn = page.locator('button:has-text("查看")').first();
  106. if (await viewBtn.isVisible()) {
  107. await viewBtn.click();
  108. await page.waitForTimeout(500);
  109. }
  110. });
  111. });
  112. test.describe('1.4 删除用户', () => {
  113. test.beforeEach(async ({ page }) => {
  114. await page.goto(BASE_URL);
  115. await page.waitForLoadState('networkidle');
  116. await page.getByPlaceholder('请输入用户名').fill(TEST_ADMIN.username);
  117. await page.getByPlaceholder('请输入密码').fill(TEST_ADMIN.password);
  118. await page.getByRole('button', { name: '登 录' }).click();
  119. await page.waitForURL(`${BASE_URL}/#/user/app`, { timeout: 10000 });
  120. });
  121. test('UM-040: 删除单个用户', async ({ page }) => {
  122. await page.goto(`${BASE_URL}/#/user/app`);
  123. await page.waitForLoadState('networkidle');
  124. const deleteBtn = page.locator('button:has-text("删除")').first();
  125. if (await deleteBtn.isVisible({ timeout: 2000 })) {
  126. await deleteBtn.click();
  127. await page.waitForTimeout(500);
  128. }
  129. });
  130. test('UM-041: 批量删除用户', async ({ page }) => {
  131. await page.goto(`${BASE_URL}/#/user/app`);
  132. await page.waitForLoadState('networkidle');
  133. });
  134. test('UM-042: 删除取消', async ({ page }) => {
  135. await page.goto(`${BASE_URL}/#/user/app`);
  136. await page.waitForLoadState('networkidle');
  137. const deleteBtn = page.locator('button:has-text("删除")').first();
  138. if (await deleteBtn.isVisible({ timeout: 2000 })) {
  139. await deleteBtn.click();
  140. await page.waitForTimeout(500);
  141. await page.getByRole('button', { name: '取消' }).click();
  142. await page.waitForTimeout(500);
  143. }
  144. });
  145. });
  146. test.describe('1.5 用户设备管理', () => {
  147. test.beforeEach(async ({ page }) => {
  148. await page.goto(BASE_URL);
  149. await page.waitForLoadState('networkidle');
  150. await page.getByPlaceholder('请输入用户名').fill(TEST_ADMIN.username);
  151. await page.getByPlaceholder('请输入密码').fill(TEST_ADMIN.password);
  152. await page.getByRole('button', { name: '登 录' }).click();
  153. await page.waitForURL(`${BASE_URL}/#/user/app`, { timeout: 10000 });
  154. });
  155. test('UM-050: 查看用户绑定设备', async ({ page }) => {
  156. await page.goto(`${BASE_URL}/#/user/app`);
  157. await page.waitForLoadState('networkidle');
  158. const deviceBtn = page.locator('button:has-text("设备管理")').first();
  159. if (await deviceBtn.isVisible()) {
  160. await deviceBtn.click();
  161. await page.waitForTimeout(500);
  162. }
  163. });
  164. test('UM-051: 添加设备到用户', async ({ page }) => {
  165. await page.goto(`${BASE_URL}/#/user/app`);
  166. await page.waitForLoadState('networkidle');
  167. });
  168. test('UM-052: 设置主设备', async ({ page }) => {
  169. await page.goto(`${BASE_URL}/#/user/app`);
  170. await page.waitForLoadState('networkidle');
  171. });
  172. test('UM-053: 解绑设备', async ({ page }) => {
  173. await page.goto(`${BASE_URL}/#/user/app`);
  174. await page.waitForLoadState('networkidle');
  175. });
  176. });
  177. test.describe('1.6 导入导出', () => {
  178. test.beforeEach(async ({ page }) => {
  179. await page.goto(BASE_URL);
  180. await page.waitForLoadState('networkidle');
  181. await page.getByPlaceholder('请输入用户名').fill(TEST_ADMIN.username);
  182. await page.getByPlaceholder('请输入密码').fill(TEST_ADMIN.password);
  183. await page.getByRole('button', { name: '登 录' }).click();
  184. await page.waitForURL(`${BASE_URL}/#/user/app`, { timeout: 10000 });
  185. });
  186. test('UM-060: 导出用户数据', async ({ page }) => {
  187. await page.goto(`${BASE_URL}/#/user/app`);
  188. await page.waitForLoadState('networkidle');
  189. const exportBtn = page.getByRole('button', { name: '导出' });
  190. if (await exportBtn.isVisible()) {
  191. await exportBtn.click();
  192. await page.waitForTimeout(1000);
  193. }
  194. });
  195. test('UM-061: 导入用户数据', async ({ page }) => {
  196. await page.goto(`${BASE_URL}/#/user/app`);
  197. await page.waitForLoadState('networkidle');
  198. });
  199. test('UM-062: 导入格式错误', async ({ page }) => {
  200. await page.goto(`${BASE_URL}/#/user/app`);
  201. await page.waitForLoadState('networkidle');
  202. });
  203. });