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
+9 -9
View File
@@ -20,7 +20,7 @@ test.describe('Task form', () => {
await loginAndGo(page, '/add-task');
await expect(page.locator('.el-form-item').filter({ hasText: '任务名称' }).locator('input')).toHaveValue('');
await expect(page.locator('.el-form-item').filter({ hasText: '任务描述' }).locator('textarea')).toHaveValue('');
await expect(page.locator('.action-row button').first()).toContainText('添加');
await expect(page.getByRole('button', { name: '添加', exact: true })).toBeVisible();
});
test('submitting add-task sends POST and navigates to /study', async ({ page }) => {
@@ -36,9 +36,9 @@ test.describe('Task form', () => {
});
await loginAndGo(page, '/add-task');
await page.locator('.el-form-item').filter({ hasText: '任务名称' }).locator('input').fill('新学习任务');
await page.locator('.el-form-item').filter({ hasText: '任务描述' }).locator('textarea').fill('这是一个测试任务');
await page.locator('.action-row button').first().click();
await page.getByPlaceholder('例如:Vue3 组件通信实践').fill('新学习任务');
await page.getByPlaceholder('请输入任务描述').fill('这是一个测试任务');
await page.getByRole('button', { name: '添加', exact: true }).click();
await expect(page).toHaveURL(/\/study/, { timeout: 10_000 });
});
@@ -75,18 +75,18 @@ test.describe('Task form', () => {
});
await loginAndGo(page, '/update-task/1');
await expect(page.locator('.el-form-item').filter({ hasText: '任务名称' }).locator('input')).toHaveValue('已有任务');
await expect(page.locator('.action-row button').first()).toContainText('更新');
await expect(page.getByPlaceholder('例如:Vue3 组件通信实践')).toHaveValue('已有任务');
await expect(page.getByRole('button', { name: '更新', exact: true })).toBeVisible();
await page.locator('.el-form-item').filter({ hasText: '任务名称' }).locator('input').fill('更新后的任务');
await page.locator('.action-row button').first().click();
await page.getByPlaceholder('例如:Vue3 组件通信实践').fill('更新后的任务');
await page.getByRole('button', { name: '添加', exact: true }).click();
await expect(page).toHaveURL(/\/study/, { timeout: 10_000 });
});
test('cancel navigates back to /study', async ({ page }) => {
await loginAndGo(page, '/add-task');
await page.locator('.action-row button').nth(1).click();
await page.getByRole('button', { name: '取消' }).click();
await expect(page).toHaveURL(/\/study/);
});
});