test: e2e 选择器迁移为角色定位

This commit is contained in:
2026-08-27 22:25:59 +08:00
parent 8c8924d652
commit 5569921df6
5 changed files with 30 additions and 30 deletions
+8 -8
View File
@@ -17,11 +17,11 @@ test.describe('Login page', () => {
// Element Plus inputs
const inputs = page.locator('.el-input');
await expect(inputs).toHaveCount(2);
await expect(page.locator('.submit-btn')).toBeVisible();
await expect(page.getByRole('button', { name: '进入系统' })).toBeVisible();
});
test('shows validation errors when fields are empty', async ({ page }) => {
await page.locator('.submit-btn').click();
await page.getByRole('button', { name: '进入系统' }).click();
// Element Plus validation shows error messages
await expect(page.locator('.el-form-item__error').first()).toBeVisible({ timeout: 5000 });
});
@@ -42,11 +42,11 @@ test.describe('Login page', () => {
);
// Fill in inputs using Element Plus el-input inner input
const usernameInput = page.locator('.el-form-item').filter({ hasText: '账号' }).locator('input');
const passwordInput = page.locator('.el-form-item').filter({ hasText: '密码' }).locator('input');
const usernameInput = page.getByPlaceholder('请输入账号');
const passwordInput = page.getByPlaceholder('请输入密码');
await usernameInput.fill('wronguser');
await passwordInput.fill('wrongpass');
await page.locator('.submit-btn').click();
await page.getByRole('button', { name: '进入系统' }).click();
// Element Plus error message appears in a popup
await expect(page.locator('.el-message--error')).toBeVisible({ timeout: 5000 });
@@ -67,11 +67,11 @@ test.describe('Login page', () => {
route.fulfill({ status: 200, contentType: 'application/json', body: JSON.stringify(mockFeed) }),
);
const usernameInput = page.locator('.el-form-item').filter({ hasText: '账号' }).locator('input');
const passwordInput = page.locator('.el-form-item').filter({ hasText: '密码' }).locator('input');
const usernameInput = page.getByPlaceholder('请输入账号');
const passwordInput = page.getByPlaceholder('请输入密码');
await usernameInput.fill('admin');
await passwordInput.fill('password123');
await page.locator('.submit-btn').click();
await page.getByRole('button', { name: '进入系统' }).click();
await expect(page).toHaveURL(/\/welcome/, { timeout: 10_000 });
const isLoggedIn = await page.evaluate(() => localStorage.getItem('isLoggedIn'));