lss.spec.ts 6.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181
  1. import { test, expect, type Page } from '@playwright/test'
  2. // 测试账号配置
  3. const TEST_USERNAME = process.env.TEST_USERNAME || 'admin'
  4. const TEST_PASSWORD = process.env.TEST_PASSWORD || '123456'
  5. // 日本相关测试数据
  6. const TEST_DATA = {
  7. name: '東京テスト環境',
  8. address: '東京都渋谷区神宮前1-2-3',
  9. // 用于恢复的原始数据
  10. originalName: '初台測試環境',
  11. originalAddress: ''
  12. }
  13. test.describe('LSS管理 CRUD 测试', () => {
  14. // 登录辅助函数
  15. async function login(page: Page) {
  16. await page.goto('/login')
  17. await page.evaluate(() => {
  18. localStorage.clear()
  19. document.cookie.split(';').forEach((c) => {
  20. document.cookie = c.replace(/^ +/, '').replace(/=.*/, '=;expires=' + new Date().toUTCString() + ';path=/')
  21. })
  22. })
  23. await page.reload()
  24. await page.getByPlaceholder('用户名').fill(TEST_USERNAME)
  25. await page.getByPlaceholder('密码').fill(TEST_PASSWORD)
  26. await page.getByRole('button', { name: '登录' }).click()
  27. await expect(page).not.toHaveURL(/\/login/, { timeout: 15000 })
  28. }
  29. test('LSS管理页面正确显示', async ({ page }) => {
  30. await login(page)
  31. await page.goto('/lss')
  32. // 验证页面标题
  33. await expect(page.locator('text=LSS 管理')).toBeVisible()
  34. // 验证搜索表单元素
  35. await expect(page.getByPlaceholder('LSS ID')).toBeVisible()
  36. await expect(page.getByPlaceholder('名称')).toBeVisible()
  37. await expect(page.getByRole('button', { name: 'Search' })).toBeVisible()
  38. await expect(page.getByRole('button', { name: 'Reset' })).toBeVisible()
  39. // 验证表头
  40. await expect(page.locator('th:has-text("LSS ID")')).toBeVisible()
  41. await expect(page.locator('th:has-text("Name")')).toBeVisible()
  42. await expect(page.locator('th:has-text("Address")')).toBeVisible()
  43. await expect(page.locator('th:has-text("IP")')).toBeVisible()
  44. await expect(page.locator('th:has-text("Actions")')).toBeVisible()
  45. })
  46. test('编辑LSS节点 - 修改Name和Address', async ({ page }) => {
  47. await login(page)
  48. await page.goto('/lss')
  49. // 等待表格加载
  50. await page.waitForTimeout(1000)
  51. // 找到数据行中的编辑按钮(Actions列第一个按钮)
  52. const editButton = page.locator('tbody tr').first().locator('button').nth(1)
  53. await expect(editButton).toBeVisible({ timeout: 10000 })
  54. await editButton.click()
  55. // 验证编辑对话框打开
  56. const dialog = page.locator('.el-drawer, .el-dialog').filter({ hasText: 'LSS详情' })
  57. await expect(dialog).toBeVisible({ timeout: 5000 })
  58. // 修改 Name 字段
  59. const nameInput = dialog
  60. .locator('input')
  61. .filter({ hasText: /名称|Name/ })
  62. .or(dialog.locator('label:has-text("Name")').locator('..').locator('input'))
  63. .first()
  64. // 使用更通用的方式定位 Name 输入框
  65. const nameField = dialog.getByPlaceholder('请输入名称')
  66. await nameField.clear()
  67. await nameField.fill(TEST_DATA.name)
  68. // 修改 Address 字段
  69. const addressField = dialog.getByPlaceholder('请输入地址')
  70. await addressField.clear()
  71. await addressField.fill(TEST_DATA.address)
  72. // 点击 Update 按钮保存
  73. await dialog.getByRole('button', { name: 'Update' }).click()
  74. // 等待对话框关闭
  75. await expect(dialog).not.toBeVisible({ timeout: 10000 })
  76. // 验证列表中数据已更新
  77. await page.waitForTimeout(500)
  78. const firstRow = page.locator('tbody tr').first()
  79. await expect(firstRow).toContainText(TEST_DATA.name)
  80. await expect(firstRow).toContainText(TEST_DATA.address)
  81. })
  82. test('查询LSS节点', async ({ page }) => {
  83. await login(page)
  84. await page.goto('/lss')
  85. // 等待表格加载
  86. await page.waitForTimeout(1000)
  87. // 在名称搜索框输入关键词
  88. await page.getByPlaceholder('名称').fill('東京')
  89. // 点击搜索
  90. await page.getByRole('button', { name: 'Search' }).click()
  91. await page.waitForTimeout(500)
  92. // 验证搜索结果
  93. const tableRows = page.locator('tbody tr')
  94. const rowCount = await tableRows.count()
  95. if (rowCount > 0) {
  96. // 验证每行都包含搜索关键词
  97. for (let i = 0; i < rowCount; i++) {
  98. const row = tableRows.nth(i)
  99. const rowText = await row.textContent()
  100. expect(rowText).toContain('東京')
  101. }
  102. }
  103. })
  104. test('重置搜索条件', async ({ page }) => {
  105. await login(page)
  106. await page.goto('/lss')
  107. // 填入搜索条件
  108. await page.getByPlaceholder('LSS ID').fill('test-id')
  109. await page.getByPlaceholder('名称').fill('test-name')
  110. // 点击重置
  111. await page.getByRole('button', { name: 'Reset' }).click()
  112. await page.waitForTimeout(300)
  113. // 验证搜索条件已清空
  114. await expect(page.getByPlaceholder('LSS ID')).toHaveValue('')
  115. await expect(page.getByPlaceholder('名称')).toHaveValue('')
  116. })
  117. test('查看LSS节点设备列表', async ({ page }) => {
  118. await login(page)
  119. await page.goto('/lss')
  120. // 等待表格加载
  121. await page.waitForTimeout(1000)
  122. // 点击 Device List 列的按钮
  123. const deviceListButton = page.locator('tbody tr').first().locator('button').first()
  124. await expect(deviceListButton).toBeVisible({ timeout: 10000 })
  125. await deviceListButton.click()
  126. // 验证设备列表面板打开
  127. const devicePanel = page.locator('.el-drawer, .el-dialog').filter({ hasText: '设备列表' })
  128. await expect(devicePanel).toBeVisible({ timeout: 5000 })
  129. // 验证设备列表表头
  130. await expect(devicePanel.locator('th:has-text("设备ID")')).toBeVisible()
  131. await expect(devicePanel.locator('th:has-text("名称")')).toBeVisible()
  132. // 关闭面板
  133. await devicePanel.locator('button[aria-label*="Close"], .el-drawer__close-btn, .el-dialog__close').first().click()
  134. await expect(devicePanel).not.toBeVisible({ timeout: 5000 })
  135. })
  136. test('从侧边栏导航到LSS管理', async ({ page }) => {
  137. await login(page)
  138. // 点击侧边栏 LSS 管理菜单项
  139. await page.getByText('LSS 管理').first().click()
  140. // 验证跳转到 LSS 管理页面
  141. await expect(page).toHaveURL(/\/lss/)
  142. await expect(page.locator('text=LSS 管理')).toBeVisible()
  143. })
  144. })