app.spec.js 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296
  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('TC-001: 正常登录', 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('TC-002: 用户名为空验证', async ({ page }) => {
  14. await page.goto(BASE_URL);
  15. await page.getByPlaceholder('请输入密码').fill(TEST_ADMIN.password);
  16. await page.getByRole('button', { name: '登 录' }).click();
  17. await expect(page.getByText('请输入用户名')).toBeVisible();
  18. });
  19. test('TC-003: 密码为空验证', async ({ page }) => {
  20. await page.goto(BASE_URL);
  21. await page.getByPlaceholder('请输入用户名').fill(TEST_ADMIN.username);
  22. await page.getByRole('button', { name: '登 录' }).click();
  23. await expect(page.getByText('请输入密码')).toBeVisible();
  24. });
  25. test('TC-004: 错误账号登录', async ({ page }) => {
  26. await page.goto(BASE_URL);
  27. await page.getByPlaceholder('请输入用户名').fill('wronguser');
  28. await page.getByPlaceholder('请输入密码').fill('wrongpass');
  29. await page.getByRole('button', { name: '登 录' }).click();
  30. await page.waitForTimeout(2000);
  31. await expect(page.getByRole('button', { name: '登 录' })).toBeVisible();
  32. });
  33. });
  34. test.describe('账号管理模块', () => {
  35. test.beforeEach(async ({ page }) => {
  36. await page.goto(BASE_URL);
  37. await page.waitForLoadState('networkidle');
  38. await page.getByPlaceholder('请输入用户名').fill(TEST_ADMIN.username);
  39. await page.getByPlaceholder('请输入密码').fill(TEST_ADMIN.password);
  40. await page.getByRole('button', { name: '登 录' }).click();
  41. await page.waitForURL(`${BASE_URL}/#/user/app`, { timeout: 10000 });
  42. });
  43. test('TC-010: 查看账号管理页面', async ({ page }) => {
  44. await expect(page.locator('.el-table__body')).toBeVisible();
  45. });
  46. test('TC-011: 账号列表搜索-手机号', async ({ page }) => {
  47. await page.getByPlaceholder('请输入手机号').fill('138');
  48. await page.getByRole('button', { name: '搜索' }).click();
  49. await page.waitForTimeout(1000);
  50. });
  51. test('TC-012: 账号列表搜索-昵称', async ({ page }) => {
  52. await page.getByPlaceholder('请输入昵称').fill('管理员');
  53. await page.getByRole('button', { name: '搜索' }).click();
  54. await page.waitForTimeout(1000);
  55. });
  56. test('TC-013: 新增用户按钮存在', async ({ page }) => {
  57. await expect(page.getByRole('button', { name: '新增用户' })).toBeVisible();
  58. });
  59. test('TC-014: 编辑功能', async ({ page }) => {
  60. const editBtn = page.locator('button:has-text("编辑")').first();
  61. if (await editBtn.isVisible()) {
  62. await editBtn.click();
  63. await page.waitForTimeout(500);
  64. }
  65. });
  66. test('TC-015: 禁用功能', async ({ page }) => {
  67. const disableBtn = page.locator('button:has-text("禁用")').first();
  68. if (await disableBtn.isVisible()) {
  69. await disableBtn.click();
  70. await page.waitForTimeout(500);
  71. }
  72. });
  73. test('TC-017: 取消删除', async ({ page }) => {
  74. const deleteBtn = page.locator('button:has-text("删除")').first();
  75. if (await deleteBtn.isVisible()) {
  76. await deleteBtn.click();
  77. await page.waitForTimeout(500);
  78. const cancelBtn = page.getByRole('button', { name: '取消' });
  79. if (await cancelBtn.isVisible()) {
  80. await cancelBtn.click();
  81. }
  82. }
  83. });
  84. test('TC-017: 重置搜索条件', async ({ page }) => {
  85. await page.getByPlaceholder('请输入手机号').fill('测试');
  86. await page.getByRole('button', { name: '重置' }).click();
  87. await page.waitForTimeout(500);
  88. });
  89. });
  90. test.describe('穴位管理模块', () => {
  91. test.beforeEach(async ({ page }) => {
  92. await page.goto(BASE_URL);
  93. await page.waitForLoadState('networkidle');
  94. await page.getByPlaceholder('请输入用户名').fill(TEST_ADMIN.username);
  95. await page.getByPlaceholder('请输入密码').fill(TEST_ADMIN.password);
  96. await page.getByRole('button', { name: '登 录' }).click();
  97. await page.waitForURL(`${BASE_URL}/#/user/app`, { timeout: 10000 });
  98. });
  99. test('TC-040: 查看穴位列表', async ({ page }) => {
  100. await expect(page.locator('.el-table__body')).toBeVisible();
  101. });
  102. test('TC-041: 穴位列表搜索-穴位名称', async ({ page }) => {
  103. await page.goto(`${BASE_URL}/#/acupoint`);
  104. await page.waitForLoadState('networkidle');
  105. await page.getByPlaceholder('请输入穴位名称').first().fill('大椎');
  106. await page.getByRole('button', { name: '查询' }).click();
  107. await page.waitForTimeout(1000);
  108. });
  109. test('TC-042: 新增按钮存在', async ({ page }) => {
  110. await page.getByRole('button', { name: '新增' }).click();
  111. await page.waitForTimeout(500);
  112. });
  113. test('TC-043: 查看穴位详情', async ({ page }) => {
  114. const viewBtn = page.locator('button:has-text("查看")').first();
  115. if (await viewBtn.isVisible()) {
  116. await viewBtn.click();
  117. await page.waitForTimeout(500);
  118. }
  119. });
  120. test('TC-044: 编辑穴位', async ({ page }) => {
  121. const editBtn = page.locator('button:has-text("编辑")').first();
  122. if (await editBtn.isVisible()) {
  123. await editBtn.click();
  124. await page.waitForTimeout(500);
  125. }
  126. });
  127. test('TC-045: 删除穴位', async ({ page }) => {
  128. const deleteBtn = page.locator('button:has-text("删除")').first();
  129. if (await deleteBtn.isVisible()) {
  130. await deleteBtn.click();
  131. await page.waitForTimeout(500);
  132. }
  133. });
  134. test('TC-046: 分页功能', async ({ page }) => {
  135. const nextBtn = page.getByRole('button', { name: '下一页' });
  136. if (await nextBtn.isEnabled()) {
  137. await nextBtn.click();
  138. await page.waitForTimeout(500);
  139. }
  140. });
  141. });
  142. test.describe('方案管理模块', () => {
  143. test.beforeEach(async ({ page }) => {
  144. await page.goto(BASE_URL);
  145. await page.waitForLoadState('networkidle');
  146. await page.getByPlaceholder('请输入用户名').fill(TEST_ADMIN.username);
  147. await page.getByPlaceholder('请输入密码').fill(TEST_ADMIN.password);
  148. await page.getByRole('button', { name: '登 录' }).click();
  149. await page.waitForURL(`${BASE_URL}/#/user/app`, { timeout: 10000 });
  150. });
  151. test('TC-060: 查看方案列表', async ({ page }) => {
  152. await page.goto(`${BASE_URL}/#/plan`);
  153. await page.waitForLoadState('networkidle');
  154. await expect(page.locator('.el-table__body')).toBeVisible();
  155. });
  156. test('TC-061: 方案列表搜索-方案名称', async ({ page }) => {
  157. await page.goto(`${BASE_URL}/#/plan`);
  158. await page.waitForLoadState('networkidle');
  159. await page.getByPlaceholder('请输入方案名称').first().fill('艾灸');
  160. await page.getByRole('button', { name: '查询' }).click();
  161. await page.waitForTimeout(1000);
  162. });
  163. test('TC-062: 新增按钮存在', async ({ page }) => {
  164. await page.getByRole('button', { name: '新增' }).click();
  165. await page.waitForTimeout(500);
  166. });
  167. test('TC-063: 查看方案详情', async ({ page }) => {
  168. const viewBtn = page.locator('button:has-text("查看")').first();
  169. if (await viewBtn.isVisible()) {
  170. await viewBtn.click();
  171. await page.waitForTimeout(500);
  172. }
  173. });
  174. test('TC-064: 编辑方案', async ({ page }) => {
  175. const editBtn = page.locator('button:has-text("编辑")').first();
  176. if (await editBtn.isVisible()) {
  177. await editBtn.click();
  178. await page.waitForTimeout(500);
  179. }
  180. });
  181. test('TC-065: 下架功能', async ({ page }) => {
  182. const downBtn = page.locator('button:has-text("下架")').first();
  183. if (await downBtn.isVisible()) {
  184. await downBtn.click();
  185. await page.waitForTimeout(500);
  186. }
  187. });
  188. test('TC-066: 分页功能', async ({ page }) => {
  189. const nextBtn = page.getByRole('button', { name: '下一页' });
  190. if (await nextBtn.isEnabled()) {
  191. await nextBtn.click();
  192. await page.waitForTimeout(500);
  193. }
  194. });
  195. });
  196. test.describe('设备管理模块', () => {
  197. test.beforeEach(async ({ page }) => {
  198. await page.goto(BASE_URL);
  199. await page.waitForLoadState('networkidle');
  200. await page.getByPlaceholder('请输入用户名').fill(TEST_ADMIN.username);
  201. await page.getByPlaceholder('请输入密码').fill(TEST_ADMIN.password);
  202. await page.getByRole('button', { name: '登 录' }).click();
  203. await page.waitForURL(`${BASE_URL}/#/user/app`, { timeout: 10000 });
  204. });
  205. test('TC-080: 查看设备列表', async ({ page }) => {
  206. await page.goto(`${BASE_URL}/#/device`);
  207. await page.waitForLoadState('networkidle');
  208. await page.waitForTimeout(1000);
  209. });
  210. test('TC-081: 新增设备', async ({ page }) => {
  211. await page.goto(`${BASE_URL}/#/device`);
  212. await page.waitForLoadState('networkidle');
  213. const addBtn = page.getByRole('button', { name: '新增' });
  214. if (await addBtn.isVisible({ timeout: 5000 })) {
  215. await addBtn.click();
  216. await page.waitForTimeout(500);
  217. }
  218. });
  219. });
  220. test.describe('系统管理模块', () => {
  221. test.beforeEach(async ({ page }) => {
  222. await page.goto(`${BASE_URL}/#/system`);
  223. await page.waitForLoadState('networkidle');
  224. await page.waitForTimeout(1000);
  225. });
  226. test('TC-090: 查看系统管理页面', async ({ page }) => {
  227. await page.waitForTimeout(500);
  228. });
  229. test('TC-091: 新增管理员', async ({ page }) => {
  230. const addBtn = page.getByRole('button', { name: '新增管理员' });
  231. if (await addBtn.isVisible()) {
  232. await addBtn.click();
  233. await page.waitForTimeout(500);
  234. }
  235. });
  236. });
  237. test.describe('艾灸手法管理模块', () => {
  238. test.beforeEach(async ({ page }) => {
  239. await page.goto(`${BASE_URL}/#/technique`);
  240. await page.waitForLoadState('networkidle');
  241. await page.waitForTimeout(1000);
  242. });
  243. test('TC-100: 查看艾灸手法管理页面', async ({ page }) => {
  244. await page.waitForTimeout(500);
  245. });
  246. });
  247. test.describe('方案模拟测试模块', () => {
  248. test.beforeEach(async ({ page }) => {
  249. await page.goto(`${BASE_URL}/#/simulation`);
  250. await page.waitForLoadState('networkidle');
  251. await page.waitForTimeout(1000);
  252. });
  253. test('TC-110: 查看方案模拟测试页面', async ({ page }) => {
  254. await page.waitForTimeout(500);
  255. });
  256. });