test: 添加菜单管理功能测试用例
- 测试菜单列表显示 - 验证菜单管理的基本功能 - 更新Playwright配置文件添加新的测试项目
This commit is contained in:
@@ -0,0 +1,72 @@
|
|||||||
|
import { test, expect } from '@playwright/test';
|
||||||
|
|
||||||
|
test.describe('菜单管理功能测试', () => {
|
||||||
|
let authToken: string;
|
||||||
|
|
||||||
|
test.beforeAll(async ({ request }) => {
|
||||||
|
const response = await request.post('http://localhost:8080/api/auth/login', {
|
||||||
|
headers: {
|
||||||
|
'Content-Type': 'application/json'
|
||||||
|
},
|
||||||
|
data: {
|
||||||
|
username: 'admin',
|
||||||
|
password: 'admin123'
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
expect(response.status()).toBe(200);
|
||||||
|
const data = await response.json();
|
||||||
|
authToken = data.token;
|
||||||
|
});
|
||||||
|
|
||||||
|
test('菜单列表显示测试', async ({ page }) => {
|
||||||
|
await test.step('导航到菜单管理页面', async () => {
|
||||||
|
await page.goto('http://localhost:3002/login');
|
||||||
|
|
||||||
|
const usernameInput = page.locator('input[type="text"], input[placeholder*="用户名"], input[placeholder*="账号"]').first();
|
||||||
|
const passwordInput = page.locator('input[type="password"]').first();
|
||||||
|
const loginButton = page.locator('button:has-text("登录")').first();
|
||||||
|
|
||||||
|
await usernameInput.fill('admin');
|
||||||
|
await passwordInput.fill('admin123');
|
||||||
|
await loginButton.click();
|
||||||
|
|
||||||
|
await page.waitForTimeout(2000);
|
||||||
|
|
||||||
|
// 点击系统管理菜单
|
||||||
|
const systemMenu = page.locator('.el-sub-menu:has-text("系统管理")').first();
|
||||||
|
if (await systemMenu.count() > 0) {
|
||||||
|
await systemMenu.click();
|
||||||
|
await page.waitForTimeout(500);
|
||||||
|
}
|
||||||
|
|
||||||
|
// 点击菜单管理
|
||||||
|
const menuManagement = page.locator('.el-menu-item:has-text("菜单管理")').first();
|
||||||
|
if (await menuManagement.count() > 0) {
|
||||||
|
await menuManagement.click();
|
||||||
|
await page.waitForTimeout(1000);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
await test.step('验证菜单列表显示', async () => {
|
||||||
|
// 检查是否有菜单列表或表格
|
||||||
|
const tableSelectors = [
|
||||||
|
'table',
|
||||||
|
'.el-table',
|
||||||
|
'[class*="table"]',
|
||||||
|
'.menu-list'
|
||||||
|
];
|
||||||
|
|
||||||
|
let foundTable = false;
|
||||||
|
for (const selector of tableSelectors) {
|
||||||
|
const count = await page.locator(selector).count();
|
||||||
|
if (count > 0) {
|
||||||
|
foundTable = true;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
expect(foundTable).toBe(true);
|
||||||
|
});
|
||||||
|
});
|
||||||
|
});
|
||||||
@@ -0,0 +1,99 @@
|
|||||||
|
import { defineConfig, devices } from '@playwright/test';
|
||||||
|
|
||||||
|
const baseURL = 'http://localhost:3002';
|
||||||
|
|
||||||
|
export default defineConfig({
|
||||||
|
testDir: './e2e',
|
||||||
|
fullyParallel: true,
|
||||||
|
forbidOnly: !!process.env.CI,
|
||||||
|
retries: process.env.CI ? 2 : 1,
|
||||||
|
workers: process.env.CI ? 4 : '50%',
|
||||||
|
reporter: [
|
||||||
|
['html', { outputFolder: 'playwright-report' }],
|
||||||
|
['json', { outputFile: 'test-results/results.json' }],
|
||||||
|
['junit', { outputFile: 'test-results/junit.xml' }],
|
||||||
|
['list'],
|
||||||
|
],
|
||||||
|
|
||||||
|
timeout: 120000,
|
||||||
|
expect: {
|
||||||
|
timeout: 30000,
|
||||||
|
toHaveScreenshot: { threshold: 0.2 },
|
||||||
|
toMatchSnapshot: { threshold: 0.2 }
|
||||||
|
},
|
||||||
|
|
||||||
|
use: {
|
||||||
|
baseURL: baseURL,
|
||||||
|
trace: process.env.CI ? 'retain-on-failure' : 'on-first-retry',
|
||||||
|
screenshot: 'only-on-failure',
|
||||||
|
video: process.env.CI ? 'retain-on-failure' : 'on-first-retry',
|
||||||
|
actionTimeout: 30000,
|
||||||
|
navigationTimeout: 60000,
|
||||||
|
headless: process.env.PLAYWRIGHT_HEADLESS === 'true' || process.env.CI === 'true',
|
||||||
|
locale: 'zh-CN',
|
||||||
|
timezoneId: 'Asia/Shanghai',
|
||||||
|
ignoreHTTPSErrors: true,
|
||||||
|
bypassCSP: true,
|
||||||
|
viewport: { width: 1280, height: 720 },
|
||||||
|
launchOptions: {
|
||||||
|
slowMo: process.env.CI ? 0 : 100
|
||||||
|
},
|
||||||
|
contextOptions: {
|
||||||
|
permissions: ['geolocation'],
|
||||||
|
geolocation: { latitude: 35.6895, longitude: 139.6917 },
|
||||||
|
userAgent: 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/120.0.0.0 Safari/537.36'
|
||||||
|
}
|
||||||
|
},
|
||||||
|
|
||||||
|
projects: [
|
||||||
|
{
|
||||||
|
name: 'ui-test',
|
||||||
|
testMatch: '**/basic-ui-test.spec.ts',
|
||||||
|
use: { ...devices['Desktop Chrome'] },
|
||||||
|
},
|
||||||
|
{
|
||||||
|
name: 'smoke-test',
|
||||||
|
testMatch: '**/smoke/**/*.spec.ts',
|
||||||
|
use: { ...devices['Desktop Chrome'] },
|
||||||
|
},
|
||||||
|
{
|
||||||
|
name: 'journey-test',
|
||||||
|
testMatch: '**/journeys/**/*.spec.ts',
|
||||||
|
use: { ...devices['Desktop Chrome'] },
|
||||||
|
},
|
||||||
|
{
|
||||||
|
name: 'api-test',
|
||||||
|
testMatch: '**/api-connectivity.spec.ts',
|
||||||
|
use: { ...devices['Desktop Chrome'] },
|
||||||
|
},
|
||||||
|
{
|
||||||
|
name: 'auth-test',
|
||||||
|
testMatch: '**/auth-test.spec.ts',
|
||||||
|
use: { ...devices['Desktop Chrome'] },
|
||||||
|
},
|
||||||
|
{
|
||||||
|
name: 'menu-management-test',
|
||||||
|
testMatch: '**/menu-management.spec.ts',
|
||||||
|
use: { ...devices['Desktop Chrome'] },
|
||||||
|
},
|
||||||
|
{
|
||||||
|
name: 'config-management-test',
|
||||||
|
testMatch: '**/config-management.spec.ts',
|
||||||
|
use: { ...devices['Desktop Chrome'] },
|
||||||
|
},
|
||||||
|
{
|
||||||
|
name: 'dict-management-test',
|
||||||
|
testMatch: '**/dict-management.spec.ts',
|
||||||
|
use: { ...devices['Desktop Chrome'] },
|
||||||
|
},
|
||||||
|
],
|
||||||
|
|
||||||
|
webServer: {
|
||||||
|
command: 'pnpm run dev',
|
||||||
|
url: baseURL,
|
||||||
|
reuseExistingServer: !process.env.CI,
|
||||||
|
timeout: 120000,
|
||||||
|
stdout: 'pipe',
|
||||||
|
stderr: 'pipe'
|
||||||
|
},
|
||||||
|
});
|
||||||
Reference in New Issue
Block a user