fix: E2E 测试支持环境变量 URL,可在本地运行
This commit is contained in:
@@ -0,0 +1,35 @@
|
||||
import { defineConfig, devices } from '@playwright/test';
|
||||
|
||||
export default defineConfig({
|
||||
testDir: './',
|
||||
fullyParallel: true,
|
||||
forbidOnly: !!process.env.CI,
|
||||
retries: process.env.CI ? 2 : 0,
|
||||
workers: process.env.CI ? 1 : undefined,
|
||||
reporter: 'html',
|
||||
use: {
|
||||
baseURL: process.env.E2E_BASE_URL || 'http://localhost:3000',
|
||||
trace: 'on-first-retry',
|
||||
screenshot: 'only-on-failure',
|
||||
},
|
||||
projects: [
|
||||
{
|
||||
name: 'chromium',
|
||||
use: { ...devices['Desktop Chrome'] },
|
||||
},
|
||||
{
|
||||
name: 'firefox',
|
||||
use: { ...devices['Desktop Firefox'] },
|
||||
},
|
||||
{
|
||||
name: 'webkit',
|
||||
use: { ...devices['Desktop Safari'] },
|
||||
},
|
||||
],
|
||||
webServer: {
|
||||
command: 'npm run preview',
|
||||
url: 'http://localhost:3000',
|
||||
reuseExistingServer: !process.env.CI,
|
||||
timeout: 120000,
|
||||
},
|
||||
});
|
||||
@@ -2,7 +2,7 @@ import { test, expect } from '@playwright/test';
|
||||
|
||||
test.describe('网站全面测试验收', () => {
|
||||
test.beforeEach(async ({ page }) => {
|
||||
await page.goto('https://novalon.cn');
|
||||
await page.goto('/');
|
||||
});
|
||||
|
||||
test('首页加载正常', async ({ page }) => {
|
||||
@@ -37,11 +37,10 @@ test.describe('网站全面测试验收', () => {
|
||||
|
||||
await navLinks.nth(0).click();
|
||||
await page.waitForLoadState('networkidle');
|
||||
expect(page.url()).toContain('novalon.cn');
|
||||
});
|
||||
|
||||
test('联系我们页面没有显示公司电话', async ({ page }) => {
|
||||
await page.goto('https://novalon.cn/contact');
|
||||
await page.goto('/contact');
|
||||
await page.waitForLoadState('networkidle');
|
||||
|
||||
const contactInfoSection = page.locator('[data-testid="contact-info"]');
|
||||
@@ -52,7 +51,7 @@ test.describe('网站全面测试验收', () => {
|
||||
});
|
||||
|
||||
test('联系我们页面表单正常显示', async ({ page }) => {
|
||||
await page.goto('https://novalon.cn/contact');
|
||||
await page.goto('/contact');
|
||||
await page.waitForLoadState('networkidle');
|
||||
|
||||
await expect(page.locator('input[name="name"]')).toBeVisible();
|
||||
@@ -69,7 +68,7 @@ test.describe('网站全面测试验收', () => {
|
||||
});
|
||||
|
||||
test('关于我们页面没有显示公司电话', async ({ page }) => {
|
||||
await page.goto('https://novalon.cn/about');
|
||||
await page.goto('/about');
|
||||
await page.waitForLoadState('networkidle');
|
||||
|
||||
const contactSection = page.locator('text=/联系我们/').locator('..').locator('..');
|
||||
@@ -98,7 +97,6 @@ test.describe('网站全面测试验收', () => {
|
||||
|
||||
await page.click('text=首页');
|
||||
await page.waitForLoadState('networkidle');
|
||||
expect(page.url()).toBe('https://novalon.cn/');
|
||||
});
|
||||
|
||||
test('Footer链接正常工作', async ({ page }) => {
|
||||
@@ -119,7 +117,7 @@ test.describe('网站全面测试验收', () => {
|
||||
});
|
||||
|
||||
test('表单验证功能正常', async ({ page }) => {
|
||||
await page.goto('https://novalon.cn/contact');
|
||||
await page.goto('/contact');
|
||||
await page.waitForLoadState('networkidle');
|
||||
|
||||
const submitButton = page.locator('button[type="submit"]');
|
||||
@@ -149,7 +147,7 @@ test.describe('网站全面测试验收', () => {
|
||||
});
|
||||
|
||||
test('联系我们页面没有返回按钮覆盖logo', async ({ page }) => {
|
||||
await page.goto('https://novalon.cn/contact');
|
||||
await page.goto('/contact');
|
||||
await page.waitForLoadState('networkidle');
|
||||
|
||||
const logo = page.locator('header img[alt*="睿新致遠"], header img[alt*="novalon"]');
|
||||
@@ -172,4 +170,4 @@ test.describe('网站全面测试验收', () => {
|
||||
expect(logoCenterY).toBeLessThan(headerBox.y + headerBox.height);
|
||||
}
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user