55 lines
1.7 KiB
TypeScript
55 lines
1.7 KiB
TypeScript
import { test, expect } from '@playwright/test';
|
|
|
|
test.describe('Headless模式测试', () => {
|
|
|
|
test('测试1: 使用headless=false访问前端', async ({ page }) => {
|
|
console.log('测试1: 使用headless=false访问前端');
|
|
|
|
try {
|
|
const response = await page.goto('http://localhost:3001/login', {
|
|
waitUntil: 'domcontentloaded',
|
|
timeout: 10000
|
|
});
|
|
console.log('响应状态:', response.status());
|
|
console.log('页面标题:', await page.title());
|
|
expect(response.status()).toBe(200);
|
|
} catch (error) {
|
|
console.error('访问失败:', error);
|
|
throw error;
|
|
}
|
|
});
|
|
|
|
test('测试2: 使用更长的超时时间', async ({ page }) => {
|
|
console.log('测试2: 使用更长的超时时间');
|
|
|
|
try {
|
|
const response = await page.goto('http://localhost:3001/login', {
|
|
waitUntil: 'networkidle',
|
|
timeout: 60000
|
|
});
|
|
console.log('响应状态:', response.status());
|
|
console.log('页面标题:', await page.title());
|
|
expect(response.status()).toBe(200);
|
|
} catch (error) {
|
|
console.error('访问失败:', error);
|
|
throw error;
|
|
}
|
|
});
|
|
|
|
test('测试3: 使用不同的waitUntil策略', async ({ page }) => {
|
|
console.log('测试3: 使用waitUntil=commit');
|
|
|
|
try {
|
|
const response = await page.goto('http://localhost:3001/login', {
|
|
waitUntil: 'commit',
|
|
timeout: 10000
|
|
});
|
|
console.log('响应状态:', response.status());
|
|
console.log('页面标题:', await page.title());
|
|
expect(response.status()).toBe(200);
|
|
} catch (error) {
|
|
console.error('访问失败:', error);
|
|
throw error;
|
|
}
|
|
});
|
|
}); |