| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475 |
- import { test, expect } from '@playwright/test';
- test.describe('银行名称管理 - 状态切换验证', () => {
- test('验证状态切换功能', async ({ page }) => {
- test.setTimeout(90000);
- // 登录
- await page.goto('http://localhost:8080/admin/login');
- await page.locator('input[name="username"]').fill('admin');
- await page.locator('input[type="password"]').fill('admin123');
- await page.click('button:has-text("登录")');
- await page.waitForTimeout(2000);
- // 访问银行名称页面
- await page.goto('http://localhost:8080/admin/bank-names', { waitUntil: 'networkidle', timeout: 30000 });
- await page.waitForTimeout(2000);
- console.log('=== 开始验证银行名称状态切换 ===');
-
- // 获取初始状态
- const firstRow = page.locator('table tbody tr').first();
- const initialStatusText = await firstRow.locator('td').nth(3).textContent();
- console.log('初始状态:', initialStatusText?.trim());
- // 打开编辑对话框
- await firstRow.locator('button').first().click();
- await page.waitForTimeout(1000);
- // 查找并点击状态开关
- const statusSwitch = page.locator('button[role="switch"]').first();
- const beforeState = await statusSwitch.isChecked();
- console.log('开关状态(点击前):', beforeState ? '启用' : '禁用');
- await statusSwitch.click();
- await page.waitForTimeout(500);
- const afterState = await statusSwitch.isChecked();
- console.log('开关状态(点击后):', afterState ? '启用' : '禁用');
- expect(afterState).toBe(!beforeState);
- console.log('状态切换成功!');
- // 提交 - 使用更具体的选择器
- await page.locator('button:has-text("更新")').click();
- await page.waitForTimeout(2000);
- console.log('已提交更改');
- // 验证更新后的状态
- await page.goto('http://localhost:8080/admin/bank-names', { waitUntil: 'networkidle' });
- await page.waitForTimeout(1000);
- const updatedFirstRow = page.locator('table tbody tr').first();
- const finalStatusText = await updatedFirstRow.locator('td').nth(3).textContent();
- console.log('更新后状态:', finalStatusText?.trim());
- // 验证状态已更新
- const expectedStatus = !beforeState ? '启用' : '禁用';
- expect(finalStatusText?.trim()).toContain(expectedStatus);
- console.log('状态已成功更新为:', expectedStatus);
- // 恢复原状态
- await updatedFirstRow.locator('button').first().click();
- await page.waitForTimeout(1000);
- const statusSwitch2 = page.locator('button[role="switch"]').first();
- await statusSwitch2.click();
- await page.waitForTimeout(500);
- await page.locator('button:has-text("更新")').click();
- await page.waitForTimeout(2000);
- console.log('已恢复原状态');
- console.log('=== 验证完成 ===');
- });
- });
|