| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132 |
- import { test, expect } from '@playwright/test'
- // 测试账号配置
- const TEST_USERNAME = process.env.TEST_USERNAME || 'admin'
- const TEST_PASSWORD = process.env.TEST_PASSWORD || '123456'
- test.describe('仪表盘测试', () => {
- test.beforeEach(async ({ page }) => {
- // 先登录
- await page.goto('/login')
- await page.getByPlaceholder('用户名').fill(TEST_USERNAME)
- await page.getByPlaceholder('密码').fill(TEST_PASSWORD)
- await page.getByRole('button', { name: '登录' }).click()
- // 等待登录成功并跳转
- await page.waitForURL(/^(?!.*\/login).*$/, { timeout: 15000 })
- // 进入仪表盘页面
- await page.goto('/dashboard')
- await page.waitForLoadState('networkidle')
- })
- test('仪表盘页面正确显示', async ({ page }) => {
- // 验证页面标题
- await expect(page.locator('.dashboard__title')).toBeVisible()
- await expect(page.locator('.dashboard__title')).toContainText('仪表盘')
- })
- test('显示统计卡片', async ({ page }) => {
- // 验证统计卡片存在
- await expect(page.locator('.dashboard__stats')).toBeVisible()
- // 验证有多个统计卡片
- const cards = page.locator('.dashboard__card')
- await expect(cards).toHaveCount(4)
- })
- test('显示机器总数', async ({ page }) => {
- // 等待数据加载
- await page.waitForTimeout(1000)
- // 验证机器总数卡片
- await expect(page.getByText('机器总数')).toBeVisible()
- })
- test('显示摄像头总数', async ({ page }) => {
- // 验证摄像头总数卡片
- await expect(page.getByText('摄像头总数')).toBeVisible()
- })
- test('显示通道总数', async ({ page }) => {
- // 验证通道总数卡片
- await expect(page.getByText('通道总数')).toBeVisible()
- })
- test('显示摄像头在线率', async ({ page }) => {
- // 验证在线率卡片
- await expect(page.getByText('摄像头在线率')).toBeVisible()
- })
- test('快捷操作区域存在', async ({ page }) => {
- // 验证快捷操作区域
- await expect(page.getByText('快捷操作')).toBeVisible()
- await expect(page.locator('.dashboard__actions')).toBeVisible()
- })
- test('刷新数据按钮可用', async ({ page }) => {
- // 验证刷新按钮存在
- const refreshBtn = page.locator('.dashboard__refresh')
- await expect(refreshBtn).toBeVisible()
- // 点击刷新
- await refreshBtn.click()
- await page.waitForTimeout(1000)
- // 验证页面仍然正常
- await expect(page.locator('.dashboard__stats')).toBeVisible()
- })
- test('点击摄像头管理跳转正确', async ({ page }) => {
- // 点击摄像头管理
- const action = page.locator('.dashboard__action').filter({ hasText: '摄像头管理' })
- await action.click()
- // 验证跳转
- await expect(page).toHaveURL(/\/camera/)
- })
- test('点击机器管理跳转正确', async ({ page }) => {
- // 点击机器管理
- const action = page.locator('.dashboard__action').filter({ hasText: '机器管理' })
- await action.click()
- // 验证跳转
- await expect(page).toHaveURL(/\/machine/)
- })
- test('点击观看统计跳转正确', async ({ page }) => {
- // 点击观看统计
- const action = page.locator('.dashboard__action').filter({ hasText: '观看统计' })
- await action.click()
- // 验证跳转
- await expect(page).toHaveURL(/\/stats/)
- })
- test('系统信息区域存在', async ({ page }) => {
- // 验证系统信息区域
- await expect(page.getByText('系统信息')).toBeVisible()
- await expect(page.locator('.dashboard__info')).toBeVisible()
- })
- test('显示系统状态正常', async ({ page }) => {
- // 验证系统状态显示
- await expect(page.getByText('系统状态')).toBeVisible()
- await expect(page.getByText('正常')).toBeVisible()
- })
- test('显示版本号', async ({ page }) => {
- // 验证版本号显示
- await expect(page.getByText('版本')).toBeVisible()
- await expect(page.getByText(/v\d+\.\d+\.\d+/)).toBeVisible()
- })
- test('显示数据更新时间', async ({ page }) => {
- // 等待数据加载
- await page.waitForTimeout(1000)
- // 验证更新时间显示
- await expect(page.getByText('数据更新时间')).toBeVisible()
- })
- })
|