增加生产环境配置文件。

This commit is contained in:
dengqichen 2025-03-25 17:13:39 +08:00
parent aa3f497434
commit e59c5c5c60
7 changed files with 55 additions and 48 deletions

View File

@ -7,7 +7,7 @@ IBP_PASSWORD=123456
# 测试配置 # 测试配置
TEST_DATA_DIR=test-data TEST_DATA_DIR=test-data
TEST_BATCH_SIZE=2 TEST_BATCH_SIZE=1
TEST_RETRY_COUNT=3 TEST_RETRY_COUNT=3
TEST_BATCH_INTERVAL=2000 TEST_BATCH_INTERVAL=2000
TEST_MAX_RETRY_DELAY=10000 TEST_MAX_RETRY_DELAY=10000
@ -31,3 +31,6 @@ TEST_PROGRESS_FILE_PATH=test-data/test-progress.json
PAGE_LOAD_MAX_RETRIES=5 PAGE_LOAD_MAX_RETRIES=5
PAGE_LOAD_RETRY_INTERVAL=3000 PAGE_LOAD_RETRY_INTERVAL=3000
PAGE_LOAD_STABILITY_DELAY=2000 PAGE_LOAD_STABILITY_DELAY=2000
# 邮件配置
EMAIL_RECIPIENTS=shengzeqiang@iscmtech.com, wanghaipeng@iscmtech.com

View File

@ -7,19 +7,19 @@ IBP_PASSWORD=Lianyu_123
# 测试配置 # 测试配置
TEST_DATA_DIR=test-data TEST_DATA_DIR=test-data
TEST_BATCH_SIZE=2 TEST_BATCH_SIZE=1
TEST_RETRY_COUNT=3 TEST_RETRY_COUNT=3
TEST_BATCH_INTERVAL=2000 TEST_BATCH_INTERVAL=2000
TEST_MAX_RETRY_DELAY=10000 TEST_MAX_RETRY_DELAY=10000
# 超时配置 # 超时配置
MENU_TIME_OUT=60000 MENU_TIME_OUT=60000
EXPECT_TIMEOUT=3600000 EXPECT_TIMEOUT=36000000
# 浏览器配置 # 浏览器配置
BROWSER_HEADLESS=false BROWSER_HEADLESS=false
BROWSER_SLOW_MO=100 BROWSER_SLOW_MO=100
BROWSER_TIMEOUT=120000 BROWSER_TIMEOUT=1200000
VIEWPORT_WIDTH=1920 VIEWPORT_WIDTH=1920
VIEWPORT_HEIGHT=1080 VIEWPORT_HEIGHT=1080
@ -31,3 +31,6 @@ TEST_PROGRESS_FILE_PATH=test-data/test-progress.json
PAGE_LOAD_MAX_RETRIES=5 PAGE_LOAD_MAX_RETRIES=5
PAGE_LOAD_RETRY_INTERVAL=3000 PAGE_LOAD_RETRY_INTERVAL=3000
PAGE_LOAD_STABILITY_DELAY=2000 PAGE_LOAD_STABILITY_DELAY=2000
# 邮件配置
EMAIL_RECIPIENTS=shengzeqiang@iscmtech.com, wanghaipeng@iscmtech.com

View File

@ -1,6 +1,13 @@
// @ts-check // @ts-check
const {defineConfig, devices} = require('@playwright/test'); const {defineConfig, devices} = require('@playwright/test');
const testLifecycle = require('./src/hooks/testLifecycle'); const testLifecycle = require('./src/hooks/testLifecycle');
const dotenv = require('dotenv');
// 根据环境加载对应的.env文件
const env = process.env.NODE_ENV || 'dev';
const envPath = `.env.${env}`;
dotenv.config({ path: envPath });
console.log(`[Playwright Config] 已加载环境配置: ${envPath}`);
/** /**
* Read environment variables and process them * Read environment variables and process them

Binary file not shown.

View File

@ -1,34 +1,22 @@
server { @echo off
listen 80; echo Starting automated tests...
server_name devops.iscmtech.com; cd /d %~dp0
:: 设置控制台编码为UTF-8
chcp 65001 > nul
location ~ ^/(deploy/longi|notice/zentao/statistics) { :: 设置默认环境为dev
proxy_pass http://127.0.0.1:8080; if "%1"=="" (
proxy_set_header Host $host; set TEST_ENV=dev
proxy_set_header X-Real-IP $remote_addr; ) else (
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; set TEST_ENV=%1
proxy_set_header X-Forwarded-Proto $scheme; )
}
location /deploy-ease/ { echo [Batch] Preparing to run tests in %TEST_ENV% environment...
proxy_pass http://127.0.0.1:8081;
proxy_set_header Host $host; :: 运行测试并发送报告
proxy_set_header X-Real-IP $remote_addr; set NODE_ENV=%TEST_ENV%
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; node src/scripts/runTestsAndSendReport.js
proxy_set_header X-Forwarded-Proto $scheme;
} echo.
location /prod/longi/ { echo [Batch] Execution completed
proxy_pass http://127.0.0.1:8082;
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header X-Forwarded-Proto $scheme;
}
location /order/longi/ {
proxy_pass http://127.0.0.1:8084;
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header X-Forwarded-Proto $scheme;
}
}

View File

@ -22,7 +22,7 @@ class TestLifecycle {
await FileUtils.ensureDirectoryExists('./test-results'); await FileUtils.ensureDirectoryExists('./test-results');
// 清空之前的性能数据 // 清空之前的性能数据
await performanceService.clearPerformanceData(); await performanceService.clearPerformanceData();
console.log('✨ 测试环境初始化完成'); console.log('✨ 环境初始化完成');
} }
async afterAll() { async afterAll() {
@ -30,9 +30,11 @@ class TestLifecycle {
try { try {
const performanceData = performanceService.getPerformanceData(); const performanceData = performanceService.getPerformanceData();
console.log('获取到性能数据:', performanceData.length, '条记录'); console.log('获取到性能数据:', performanceData.length, '条记录');
const report = this.generateReport(performanceData); // 获取当前环境
const env = process.env.NODE_ENV || 'dev';
const report = this.generateReport(performanceData, env);
await this.saveReport(report); await this.saveReport(report);
console.log(`📊 测试报告已生成: ${this.reportPath}`); console.log(`📊 ${env} 测试报告已生成: ${this.reportPath}`);
} catch (error) { } catch (error) {
console.error('生成测试报告出错:', error); console.error('生成测试报告出错:', error);
throw error; throw error;
@ -42,9 +44,10 @@ class TestLifecycle {
/** /**
* 生成测试报告 * 生成测试报告
* @param {Object} data 性能数据对象 * @param {Object} data 性能数据对象
* @param {String} env 当前环境
* @returns {String} 测试报告字符串 * @returns {String} 测试报告字符串
*/ */
generateReport(performanceData) { generateReport(performanceData, env) {
// 统计数据 // 统计数据
const totalTests = performanceData.length; const totalTests = performanceData.length;
const successTests = performanceData.filter(record => record.success).length; const successTests = performanceData.filter(record => record.success).length;
@ -82,7 +85,7 @@ class TestLifecycle {
<html> <html>
<head> <head>
<meta charset="UTF-8"> <meta charset="UTF-8">
<title>测试执行报告</title> <title>测试执行报告 (${env})</title>
<style> <style>
body { font-family: Arial, sans-serif; margin: 0; padding: 20px; background: #f5f5f5; } body { font-family: Arial, sans-serif; margin: 0; padding: 20px; background: #f5f5f5; }
.container { max-width: 1200px; margin: 0 auto; background: white; padding: 20px; border-radius: 8px; box-shadow: 0 2px 4px rgba(0,0,0,0.1); } .container { max-width: 1200px; margin: 0 auto; background: white; padding: 20px; border-radius: 8px; box-shadow: 0 2px 4px rgba(0,0,0,0.1); }
@ -103,7 +106,7 @@ class TestLifecycle {
<body> <body>
<div class="container"> <div class="container">
<div class="header"> <div class="header">
<h1>测试执行报告</h1> <h1>测试执行报告 (${env})</h1>
<p>执行时间: ${new Date().toLocaleString()}</p> <p>执行时间: ${new Date().toLocaleString()}</p>
</div> </div>

View File

@ -53,9 +53,11 @@ async function runTestsAndSendReport() {
// 发送邮件 // 发送邮件
console.log('[Node] Sending test report email...'); console.log('[Node] Sending test report email...');
const emailRecipients = process.env.EMAIL_RECIPIENTS || 'wanghaipeng@iscmtech.com';
console.log(`[Node] Email recipients: ${emailRecipients}`);
const result = await emailService.sendMail({ const result = await emailService.sendMail({
to: 'dengqichen@iscmtech.com', to: emailRecipients,
subject: `[成功] Playwright自动化测试报告 (${env}) - ${startTime.toLocaleDateString()}`, subject: `隆基需求计划页面可用性-自动化测试报告 (${env}) - ${startTime.toLocaleDateString()}`,
html: performanceReport html: performanceReport
}); });
@ -73,9 +75,10 @@ async function runTestsAndSendReport() {
const reportPath = path.join(process.cwd(), 'test-results', 'performance-report.html'); const reportPath = path.join(process.cwd(), 'test-results', 'performance-report.html');
if (fs.existsSync(reportPath)) { if (fs.existsSync(reportPath)) {
const performanceReport = fs.readFileSync(reportPath, 'utf8'); const performanceReport = fs.readFileSync(reportPath, 'utf8');
const emailRecipients = process.env.EMAIL_RECIPIENTS || 'wanghaipeng@iscmtech.com';
const result = await emailService.sendMail({ const result = await emailService.sendMail({
to: 'wanghaipeng@iscmtech.com', to: emailRecipients,
subject: `[失败] Playwright自动化测试报告 (${env}) - ${startTime.toLocaleDateString()}`, subject: `隆基需求计划页面可用性-自动化测试报告 (${env}) - ${startTime.toLocaleDateString()}`,
html: performanceReport html: performanceReport
}); });