refactor(tests): 迁移 E2E 测试到独立的 e2e-tests 目录
This commit is contained in:
@@ -0,0 +1,87 @@
|
||||
import { test, expect } from '@playwright/test';
|
||||
|
||||
test.describe('调试创建角色功能', () => {
|
||||
test('调试创建角色流程', async ({ page }) => {
|
||||
const timestamp = Date.now();
|
||||
const roleName = `测试角色_${timestamp}`;
|
||||
const roleKey = `test_role_${timestamp}`;
|
||||
|
||||
await test.step('导航到角色管理', async () => {
|
||||
await page.goto('/dashboard');
|
||||
await page.waitForLoadState('networkidle');
|
||||
await page.locator('text=系统管理').click();
|
||||
await page.waitForTimeout(500);
|
||||
await page.locator('text=角色管理').click();
|
||||
await page.waitForLoadState('networkidle');
|
||||
await expect(page).toHaveURL(/.*roles/, { timeout: 10000 });
|
||||
});
|
||||
|
||||
await test.step('点击创建角色按钮', async () => {
|
||||
await page.locator('button:has-text("新增角色")').click();
|
||||
await page.waitForSelector('.el-dialog', { state: 'visible', timeout: 5000 });
|
||||
await page.screenshot({ path: 'test-results/debug-1-dialog-opened.png' });
|
||||
});
|
||||
|
||||
await test.step('填写角色信息', async () => {
|
||||
const dialog = page.locator('.el-dialog');
|
||||
|
||||
const roleNameInput = dialog.locator('input').first();
|
||||
await roleNameInput.fill(roleName);
|
||||
await roleNameInput.blur();
|
||||
await page.waitForTimeout(300);
|
||||
await page.screenshot({ path: 'test-results/debug-2-filled-roleName.png' });
|
||||
|
||||
const roleKeyInput = dialog.locator('input').nth(1);
|
||||
await roleKeyInput.fill(roleKey);
|
||||
await roleKeyInput.blur();
|
||||
await page.waitForTimeout(300);
|
||||
await page.screenshot({ path: 'test-results/debug-3-filled-roleKey.png' });
|
||||
|
||||
const roleSortInput = dialog.locator('.el-input-number .el-input__inner');
|
||||
await roleSortInput.fill('99');
|
||||
await roleSortInput.blur();
|
||||
await page.waitForTimeout(300);
|
||||
await page.screenshot({ path: 'test-results/debug-4-filled-roleSort.png' });
|
||||
|
||||
console.log('Filled form with:', { roleName, roleKey, roleSort: 99 });
|
||||
|
||||
const formItems = await dialog.locator('.el-form-item').all();
|
||||
console.log('Number of form items:', formItems.length);
|
||||
|
||||
for (let i = 0; i < formItems.length; i++) {
|
||||
const label = await formItems[i].locator('.el-form-item__label').textContent();
|
||||
const hasError = await formItems[i].locator('.el-form-item__error').isVisible().catch(() => false);
|
||||
if (hasError) {
|
||||
const errorText = await formItems[i].locator('.el-form-item__error').textContent();
|
||||
console.log(`Form item "${label}" has error: ${errorText}`);
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
await test.step('提交表单', async () => {
|
||||
await page.screenshot({ path: 'test-results/debug-5-before-submit.png' });
|
||||
|
||||
await page.locator('.el-dialog button:has-text("确定")').click();
|
||||
|
||||
await page.waitForTimeout(1000);
|
||||
await page.screenshot({ path: 'test-results/debug-6-after-submit-1s.png' });
|
||||
|
||||
await page.waitForTimeout(2000);
|
||||
await page.screenshot({ path: 'test-results/debug-7-after-submit-3s.png' });
|
||||
|
||||
const dialogVisible = await page.locator('.el-dialog').isVisible();
|
||||
console.log('Dialog visible after submit:', dialogVisible);
|
||||
|
||||
const successMessage = await page.locator('.el-message--success').isVisible().catch(() => false);
|
||||
console.log('Success message visible:', successMessage);
|
||||
|
||||
const errorMessage = await page.locator('.el-message--error').isVisible().catch(() => false);
|
||||
console.log('Error message visible:', errorMessage);
|
||||
|
||||
if (errorMessage) {
|
||||
const errorText = await page.locator('.el-message--error').textContent();
|
||||
console.log('Error message text:', errorText);
|
||||
}
|
||||
});
|
||||
});
|
||||
});
|
||||
@@ -0,0 +1,123 @@
|
||||
import { test, expect } from '@playwright/test';
|
||||
|
||||
test.describe('调试角色分配', () => {
|
||||
test('调试角色分配功能', async ({ page }) => {
|
||||
await test.step('导航到用户管理', async () => {
|
||||
await page.goto('/users');
|
||||
await page.waitForLoadState('networkidle');
|
||||
await expect(page.locator('.el-table')).toBeVisible({ timeout: 10000 });
|
||||
});
|
||||
|
||||
await test.step('查找测试用户', async () => {
|
||||
const searchInput = page.locator('input[placeholder*="用户名"]').first();
|
||||
await searchInput.fill('testuser_journey');
|
||||
await page.locator('button:has-text("搜索")').click();
|
||||
await page.waitForTimeout(1000);
|
||||
|
||||
const userRow = page.locator('.el-table__row').first();
|
||||
await expect(userRow).toBeVisible({ timeout: 5000 });
|
||||
await page.screenshot({ path: 'test-results/debug-role-1-user-found.png' });
|
||||
});
|
||||
|
||||
await test.step('打开分配角色对话框', async () => {
|
||||
const userRow = page.locator('.el-table__row').first();
|
||||
await userRow.locator('button:has-text("分配角色")').click();
|
||||
await page.waitForSelector('.el-dialog:has-text("分配角色")', { state: 'visible', timeout: 5000 });
|
||||
await page.screenshot({ path: 'test-results/debug-role-2-dialog-open.png' });
|
||||
});
|
||||
|
||||
await test.step('检查转移组件状态', async () => {
|
||||
const transfer = page.locator('.el-transfer');
|
||||
|
||||
const leftPanel = transfer.locator('.el-transfer-panel').first();
|
||||
const rightPanel = transfer.locator('.el-transfer-panel').last();
|
||||
|
||||
const leftItems = await leftPanel.locator('.el-checkbox').all();
|
||||
const rightItems = await rightPanel.locator('.el-checkbox').all();
|
||||
|
||||
console.log(`左侧面板有 ${leftItems.length} 个选项`);
|
||||
console.log(`右侧面板有 ${rightItems.length} 个选项`);
|
||||
|
||||
for (let i = 0; i < leftItems.length; i++) {
|
||||
const text = await leftItems[i].textContent();
|
||||
const isChecked = await leftItems[i].locator('input').isChecked();
|
||||
console.log(`左侧选项 ${i}: ${text}, 是否选中: ${isChecked}`);
|
||||
}
|
||||
|
||||
for (let i = 0; i < rightItems.length; i++) {
|
||||
const text = await rightItems[i].textContent();
|
||||
const isChecked = await rightItems[i].locator('input').isChecked();
|
||||
console.log(`右侧选项 ${i}: ${text}, 是否选中: ${isChecked}`);
|
||||
}
|
||||
|
||||
await page.screenshot({ path: 'test-results/debug-role-3-transfer-state.png' });
|
||||
});
|
||||
|
||||
await test.step('选择并转移角色', async () => {
|
||||
const transfer = page.locator('.el-transfer');
|
||||
|
||||
const superAdminCheckbox = transfer.locator('.el-checkbox:has-text("超级管理员")');
|
||||
const isChecked = await superAdminCheckbox.locator('input').isChecked();
|
||||
|
||||
console.log(`超级管理员复选框是否已选中: ${isChecked}`);
|
||||
|
||||
if (!isChecked) {
|
||||
await superAdminCheckbox.click();
|
||||
await page.waitForTimeout(500);
|
||||
console.log('点击了超级管理员复选框');
|
||||
}
|
||||
|
||||
await page.screenshot({ path: 'test-results/debug-role-4-checkbox-clicked.png' });
|
||||
|
||||
const moveToRightButton = transfer.locator('.el-transfer__buttons button').nth(1);
|
||||
const isEnabled = await moveToRightButton.isEnabled();
|
||||
console.log(`转移按钮是否可用: ${isEnabled}`);
|
||||
|
||||
if (isEnabled) {
|
||||
await moveToRightButton.click();
|
||||
await page.waitForTimeout(500);
|
||||
console.log('点击了转移按钮');
|
||||
}
|
||||
|
||||
await page.screenshot({ path: 'test-results/debug-role-5-role-transferred.png' });
|
||||
|
||||
const rightPanel = transfer.locator('.el-transfer-panel').last();
|
||||
const rightItems = await rightPanel.locator('.el-checkbox').all();
|
||||
console.log(`转移后右侧面板有 ${rightItems.length} 个选项`);
|
||||
});
|
||||
|
||||
await test.step('点击确定按钮', async () => {
|
||||
const confirmButton = page.locator('.el-dialog:has-text("分配角色") button:has-text("确定")');
|
||||
await confirmButton.click();
|
||||
console.log('点击了确定按钮');
|
||||
|
||||
await page.waitForTimeout(2000);
|
||||
await page.screenshot({ path: 'test-results/debug-role-6-after-confirm.png' });
|
||||
|
||||
const dialog = page.locator('.el-dialog:has-text("分配角色")');
|
||||
const isVisible = await dialog.isVisible();
|
||||
console.log(`对话框是否可见: ${isVisible}`);
|
||||
|
||||
if (isVisible) {
|
||||
const errorMessage = page.locator('.el-message--error');
|
||||
const hasError = await errorMessage.isVisible().catch(() => false);
|
||||
if (hasError) {
|
||||
const errorText = await errorMessage.textContent();
|
||||
console.log(`错误消息: ${errorText}`);
|
||||
}
|
||||
|
||||
const formItems = await dialog.locator('.el-form-item').all();
|
||||
console.log(`表单项数量: ${formItems.length}`);
|
||||
|
||||
for (let i = 0; i < formItems.length; i++) {
|
||||
const hasError = await formItems[i].locator('.el-form-item__error').isVisible().catch(() => false);
|
||||
if (hasError) {
|
||||
const label = await formItems[i].locator('.el-form-item__label').textContent();
|
||||
const errorText = await formItems[i].locator('.el-form-item__error').textContent();
|
||||
console.log(`表单项 "${label}" 有错误: ${errorText}`);
|
||||
}
|
||||
}
|
||||
}
|
||||
});
|
||||
});
|
||||
});
|
||||
Reference in New Issue
Block a user