内存优化1
This commit is contained in:
parent
a01ccded66
commit
22d2d993aa
@ -26,7 +26,7 @@ module.exports = {
|
|||||||
'--disable-backgrounding-occluded-windows',
|
'--disable-backgrounding-occluded-windows',
|
||||||
'--memory-pressure-off',
|
'--memory-pressure-off',
|
||||||
'--disable-site-isolation-trials',
|
'--disable-site-isolation-trials',
|
||||||
'--js-flags="--max-old-space-size=8192"',
|
'--js-flags="--max-old-space-size=4096"',
|
||||||
'--disable-gpu',
|
'--disable-gpu',
|
||||||
'--disable-notifications',
|
'--disable-notifications',
|
||||||
'--disable-extensions',
|
'--disable-extensions',
|
||||||
|
|||||||
@ -7,6 +7,11 @@ describe('隆基系统全部页面验证', () => {
|
|||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
// 每个测试用例结束后清理内存
|
||||||
|
afterEach(() => {
|
||||||
|
cleanupMemory();
|
||||||
|
});
|
||||||
|
|
||||||
// 格式化时间的辅助函数
|
// 格式化时间的辅助函数
|
||||||
const formatTime = (date) => {
|
const formatTime = (date) => {
|
||||||
return date.toLocaleString('zh-CN', {
|
return date.toLocaleString('zh-CN', {
|
||||||
@ -154,12 +159,6 @@ describe('隆基系统全部页面验证', () => {
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
// 每个测试用例前不再重新访问登录页
|
|
||||||
// beforeEach(() => {
|
|
||||||
// // 只设置异常处理
|
|
||||||
// Cypress.on('uncaught:exception', (err, runnable) => false);
|
|
||||||
// });
|
|
||||||
|
|
||||||
// 添加内存清理的公共方法
|
// 添加内存清理的公共方法
|
||||||
const cleanupMemory = () => {
|
const cleanupMemory = () => {
|
||||||
// 执行垃圾回收
|
// 执行垃圾回收
|
||||||
@ -167,20 +166,22 @@ describe('隆基系统全部页面验证', () => {
|
|||||||
|
|
||||||
// 清理DOM快照
|
// 清理DOM快照
|
||||||
cy.get('body').then(() => {
|
cy.get('body').then(() => {
|
||||||
Cypress.$(document).find('*').off();
|
try {
|
||||||
Cypress.$('.el-loading-mask').remove();
|
// 移除一些可能导致内存泄漏的元素
|
||||||
Cypress.$('.el-message').remove();
|
Cypress.$('.el-loading-mask').remove();
|
||||||
Cypress.$('.el-message-box').remove();
|
Cypress.$('.el-message').remove();
|
||||||
|
Cypress.$('.el-message-box').remove();
|
||||||
|
|
||||||
// 清理可能的内存泄漏
|
// 清理事件监听器 - 只清理特定元素的事件
|
||||||
Cypress.$('iframe').remove(); // 移除所有iframe
|
Cypress.$('.el-dialog__wrapper').off();
|
||||||
Cypress.$('img').remove(); // 移除所有图片
|
Cypress.$('.el-notification').off();
|
||||||
Cypress.$('video').remove(); // 移除所有视频
|
Cypress.$('.el-drawer__wrapper').off();
|
||||||
|
|
||||||
// 清理事件监听器
|
// 清理控制台
|
||||||
const win = Cypress.$(window);
|
console.clear();
|
||||||
win.off();
|
} catch (e) {
|
||||||
win.find('*').off();
|
console.error('清理DOM时出错:', e);
|
||||||
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
// 手动清理一些可能的引用
|
// 手动清理一些可能的引用
|
||||||
@ -213,20 +214,29 @@ describe('隆基系统全部页面验证', () => {
|
|||||||
|
|
||||||
// 添加报告写入方法
|
// 添加报告写入方法
|
||||||
const writeReportBatch = () => {
|
const writeReportBatch = () => {
|
||||||
const batchNumber = Math.floor(testReport.summary.totalPages / 20); // 每20个页面写入一次
|
if (testReport.currentBatch.pages.length === 0) {
|
||||||
const fileName = `cypress/reports/${selectedEnvironment}-menu-test-report-batch-${batchNumber}.json`;
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
const batchNumber = Math.floor(Math.random() * 10000);
|
||||||
|
|
||||||
cy.log(`📊 写入批次报告 ${batchNumber}:`);
|
cy.log(`📊 写入批次报告 ${batchNumber}:`);
|
||||||
cy.log(`当前批次页面数: ${testReport.currentBatch.pages.length}`);
|
cy.log(`当前批次页面数: ${testReport.currentBatch.pages.length}`);
|
||||||
cy.log(`当前批次失败页面数: ${testReport.currentBatch.failedPages.length}`);
|
cy.log(`当前批次失败页面数: ${testReport.currentBatch.failedPages.length}`);
|
||||||
|
|
||||||
cy.writeFile(fileName, testReport.currentBatch).then(() => {
|
cy.task('saveReport', {
|
||||||
cy.log(`✅ 批次报告已写入: ${fileName}`);
|
data: testReport.currentBatch,
|
||||||
// 清空当前批次数据,释放内存
|
filename: `${selectedEnvironment}-menu-test-report-batch-${batchNumber}.json`
|
||||||
|
}).then(() => {
|
||||||
|
cy.log(`✅ 批次报告已写入`);
|
||||||
|
|
||||||
|
// 清空当前批次
|
||||||
testReport.currentBatch = {
|
testReport.currentBatch = {
|
||||||
pages: [],
|
pages: [],
|
||||||
failedPages: []
|
failedPages: []
|
||||||
};
|
};
|
||||||
|
|
||||||
|
// 清理内存
|
||||||
cleanupMemory();
|
cleanupMemory();
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
@ -681,6 +691,7 @@ describe('隆基系统全部页面验证', () => {
|
|||||||
// 开始测试的函数
|
// 开始测试的函数
|
||||||
function startTesting(selectedMenus) {
|
function startTesting(selectedMenus) {
|
||||||
let processedCount = 0;
|
let processedCount = 0;
|
||||||
|
const batchSize = 10; // 每批处理10个菜单项
|
||||||
|
|
||||||
const processMenuItems = (index = 0) => {
|
const processMenuItems = (index = 0) => {
|
||||||
if (index >= selectedMenus.length) {
|
if (index >= selectedMenus.length) {
|
||||||
@ -700,12 +711,12 @@ describe('隆基系统全部页面验证', () => {
|
|||||||
}).replace(/[\/\s:]/g, '');
|
}).replace(/[\/\s:]/g, '');
|
||||||
|
|
||||||
// 创建以时间戳命名的报告目录
|
// 创建以时间戳命名的报告目录
|
||||||
const reportDir = `cypress/reports/report-${timestamp}`;
|
const reportDir = `cypress/reports/${selectedEnvironment}-report-${timestamp}`;
|
||||||
|
|
||||||
// 创建报告目录并生成最终报告
|
// 创建报告目录并生成最终报告
|
||||||
cy.task('createReportDir', reportDir).then(() => {
|
cy.task('createReportDir', reportDir).then(() => {
|
||||||
// 将摘要信息写入到时间戳目录中
|
// 将摘要信息写入到时间戳目录中
|
||||||
cy.writeFile(`${reportDir}/test-summary-${timestamp}.json`, testReport.summary).then(() => {
|
cy.writeFile(`${reportDir}/${selectedEnvironment}-test-summary-${timestamp}.json`, testReport.summary).then(() => {
|
||||||
generateFinalReport(reportDir, timestamp, selectedEnvironment);
|
generateFinalReport(reportDir, timestamp, selectedEnvironment);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
@ -716,6 +727,31 @@ describe('隆基系统全部页面验证', () => {
|
|||||||
writeReportBatch();
|
writeReportBatch();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// 每处理一定数量的菜单项,重新加载页面以释放内存
|
||||||
|
if (index > 0 && index % batchSize === 0) {
|
||||||
|
cy.log(`已处理 ${index} 个菜单项,重新加载页面以释放内存...`);
|
||||||
|
|
||||||
|
// 保存当前进度
|
||||||
|
writeReportBatch();
|
||||||
|
|
||||||
|
// 清理内存
|
||||||
|
cleanupMemory();
|
||||||
|
|
||||||
|
// 重新加载页面
|
||||||
|
cy.reload();
|
||||||
|
|
||||||
|
// 等待页面加载完成
|
||||||
|
cy.get('.ly-side-nav', { timeout: 30000 }).should('be.visible');
|
||||||
|
|
||||||
|
// 确保菜单展开
|
||||||
|
cy.get('.ly-side-nav').then($nav => {
|
||||||
|
if ($nav.css('left') !== '0px') {
|
||||||
|
cy.get('.vab-content .toggle-icon').click();
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
// 每处理3个菜单项清理一次内存
|
||||||
if (index > 0 && index % 3 === 0) {
|
if (index > 0 && index % 3 === 0) {
|
||||||
cleanupMemory();
|
cleanupMemory();
|
||||||
}
|
}
|
||||||
@ -756,11 +792,6 @@ describe('隆基系统全部页面验证', () => {
|
|||||||
checkTestStarted();
|
checkTestStarted();
|
||||||
});
|
});
|
||||||
|
|
||||||
// 在每个测试用例结束后清理内存
|
|
||||||
afterEach(() => {
|
|
||||||
cleanupMemory();
|
|
||||||
});
|
|
||||||
|
|
||||||
// 修改生成HTML报告的方法,接收环境参数
|
// 修改生成HTML报告的方法,接收环境参数
|
||||||
const generateFinalReport = (reportDir, timestamp, environment) => {
|
const generateFinalReport = (reportDir, timestamp, environment) => {
|
||||||
// 读取所有批次报告
|
// 读取所有批次报告
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user