aaaaaaaaaa
This commit is contained in:
parent
d55befa222
commit
d12e39ff3a
@ -59,7 +59,7 @@ module.exports = {
|
|||||||
createReportDir(dirPath) {
|
createReportDir(dirPath) {
|
||||||
try {
|
try {
|
||||||
if (!fs.existsSync(dirPath)) {
|
if (!fs.existsSync(dirPath)) {
|
||||||
fs.mkdirSync(dirPath, { recursive: true });
|
fs.mkdirSync(dirPath, {recursive: true});
|
||||||
}
|
}
|
||||||
return null;
|
return null;
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
@ -73,7 +73,7 @@ module.exports = {
|
|||||||
const reportsDir = path.join(__dirname, 'cypress', 'reports');
|
const reportsDir = path.join(__dirname, 'cypress', 'reports');
|
||||||
const reports = [];
|
const reports = [];
|
||||||
const files = fs.readdirSync(reportsDir);
|
const files = fs.readdirSync(reportsDir);
|
||||||
|
|
||||||
files.forEach(file => {
|
files.forEach(file => {
|
||||||
if (file.startsWith(`${environment}-menu-test-report-batch-`) && file.endsWith('.json')) {
|
if (file.startsWith(`${environment}-menu-test-report-batch-`) && file.endsWith('.json')) {
|
||||||
const filePath = path.join(reportsDir, file);
|
const filePath = path.join(reportsDir, file);
|
||||||
@ -81,7 +81,7 @@ module.exports = {
|
|||||||
reports.push(JSON.parse(content));
|
reports.push(JSON.parse(content));
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
return reports;
|
return reports;
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
console.error('Read reports failed:', e);
|
console.error('Read reports failed:', e);
|
||||||
@ -93,13 +93,13 @@ module.exports = {
|
|||||||
try {
|
try {
|
||||||
const reportsDir = path.join(__dirname, 'cypress', 'reports');
|
const reportsDir = path.join(__dirname, 'cypress', 'reports');
|
||||||
const files = fs.readdirSync(reportsDir);
|
const files = fs.readdirSync(reportsDir);
|
||||||
|
|
||||||
files.forEach(file => {
|
files.forEach(file => {
|
||||||
if (file.startsWith(`${environment}-menu-test-report-batch-`) && file.endsWith('.json')) {
|
if (file.startsWith(`${environment}-menu-test-report-batch-`) && file.endsWith('.json')) {
|
||||||
fs.unlinkSync(path.join(reportsDir, file));
|
fs.unlinkSync(path.join(reportsDir, file));
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
return null;
|
return null;
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
console.error('Cleanup reports failed:', e);
|
console.error('Cleanup reports failed:', e);
|
||||||
@ -107,11 +107,11 @@ module.exports = {
|
|||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
|
||||||
saveReport({ data, filename }) {
|
saveReport({data, filename}) {
|
||||||
try {
|
try {
|
||||||
const reportsDir = path.join(__dirname, 'cypress', 'reports');
|
const reportsDir = path.join(__dirname, 'cypress', 'reports');
|
||||||
if (!fs.existsSync(reportsDir)) {
|
if (!fs.existsSync(reportsDir)) {
|
||||||
fs.mkdirSync(reportsDir, { recursive: true });
|
fs.mkdirSync(reportsDir, {recursive: true});
|
||||||
}
|
}
|
||||||
fs.writeFileSync(
|
fs.writeFileSync(
|
||||||
path.join(reportsDir, filename),
|
path.join(reportsDir, filename),
|
||||||
@ -122,9 +122,43 @@ module.exports = {
|
|||||||
console.error('Save report failed:', e);
|
console.error('Save report failed:', e);
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
},
|
||||||
|
getLatestDataFile() {
|
||||||
|
const fixturesDir = path.join(__dirname, 'cypress/fixtures');
|
||||||
|
|
||||||
|
try {
|
||||||
|
// 读取fixtures目录
|
||||||
|
const files = fs.readdirSync(fixturesDir);
|
||||||
|
|
||||||
|
// 过滤出数据文件
|
||||||
|
const dataFiles = files.filter(file =>
|
||||||
|
file.includes('-data-') && file.endsWith('.json')
|
||||||
|
);
|
||||||
|
|
||||||
|
if (dataFiles.length === 0) {
|
||||||
|
return null; // 没有找到数据文件
|
||||||
|
}
|
||||||
|
|
||||||
|
// 按文件名倒序排序
|
||||||
|
dataFiles.sort().reverse();
|
||||||
|
|
||||||
|
const latestFile = dataFiles[0];
|
||||||
|
|
||||||
|
// 读取文件内容
|
||||||
|
const fileContent = JSON.parse(
|
||||||
|
fs.readFileSync(path.join(fixturesDir, latestFile), 'utf8')
|
||||||
|
);
|
||||||
|
|
||||||
|
return {
|
||||||
|
filename: latestFile,
|
||||||
|
content: fileContent
|
||||||
|
};
|
||||||
|
} catch (error) {
|
||||||
|
console.error('读取数据文件时出错:', error);
|
||||||
|
return null;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
return config;
|
return config;
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
|
|||||||
File diff suppressed because it is too large
Load Diff
@ -161,76 +161,124 @@ describe('隆基系统页面验证', () => {
|
|||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
// 处理二级菜单的方法
|
// 关闭活动的标签页
|
||||||
|
const closeActiveTab = (menuText) => {
|
||||||
|
cy.log(`尝试关闭标签页: ${menuText}`);
|
||||||
|
cy.get('.vab-tabs .el-tabs__item').each(($tab) => {
|
||||||
|
if ($tab.text().trim() === menuText) {
|
||||||
|
cy.wrap($tab).find('.el-icon-close').click();
|
||||||
|
cy.wait(500);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
};
|
||||||
|
|
||||||
|
// 处理二级菜单的方法
|
||||||
const handleSecondLevelMenu = (menuItem) => {
|
const handleSecondLevelMenu = (menuItem) => {
|
||||||
cy.log(`📎 处理二级菜单: ${menuItem.text}`);
|
cy.log(`📎 处理二级菜单: ${menuItem.text}`);
|
||||||
// TODO: 添加二级菜单的具体处理逻辑
|
|
||||||
// 1. 点击菜单
|
// 点击菜单项
|
||||||
// 2. 验证页面加载
|
cy.get('.el-sub-menu__title, .el-menu-item').eq(menuItem.index).then($element => {
|
||||||
// 3. 检查页面内容
|
cy.wrap($element).click();
|
||||||
|
cy.wait(1000);
|
||||||
|
|
||||||
|
// 等待页面加载
|
||||||
|
waitForPageLoad();
|
||||||
|
|
||||||
|
// 检查并处理标签页
|
||||||
|
cy.get('.vab-tabs .el-tabs__item').then($tabs => {
|
||||||
|
if ($tabs.length > 0) {
|
||||||
|
// 遍历所有标签页
|
||||||
|
cy.get('.vab-tabs .el-tabs__item').each(($tab) => {
|
||||||
|
const tabText = $tab.text().trim();
|
||||||
|
cy.log(`处理标签页: ${tabText}`);
|
||||||
|
|
||||||
|
// 点击标签页
|
||||||
|
cy.wrap($tab).click();
|
||||||
|
cy.wait(1000);
|
||||||
|
|
||||||
|
// 等待页面加载
|
||||||
|
waitForPageLoad();
|
||||||
|
});
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
// 关闭当前菜单的所有标签页
|
||||||
|
closeActiveTab(menuItem.text);
|
||||||
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
// 处理三级菜单的方法
|
// 处理三级菜单的方法
|
||||||
const handleThirdLevelMenu = (menuItem) => {
|
const handleThirdLevelMenu = (menuItem) => {
|
||||||
cy.log(`📑 处理三级菜单: ${menuItem.text}`);
|
cy.log(`📑 处理三级菜单: ${menuItem.text}`);
|
||||||
|
|
||||||
// 根据菜单索引找到对应的菜单元素
|
// 获取二级菜单元素
|
||||||
cy.get('.el-sub-menu__title, .el-menu-item').eq(menuItem.index).then($element => {
|
cy.get('.el-sub-menu__title, .el-menu-item').eq(menuItem.index).as('secondMenu');
|
||||||
const processThirdMenuItems = ($thirdMenuItems, currentIndex = 0) => {
|
|
||||||
if (currentIndex >= $thirdMenuItems.length) {
|
|
||||||
cy.log(`✅ 完成所有三级菜单处理: ${menuItem.text}`);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
// 确保二级菜单展开并等待三级菜单出现
|
// 定义获取三级菜单的命令
|
||||||
cy.wrap($element).click();
|
Cypress.Commands.add('getThirdMenuItems', () => {
|
||||||
|
return cy.get('@secondMenu').click()
|
||||||
// 等待三级菜单弹出框出现
|
|
||||||
cy.get('.el-popper.is-light.el-popover', {timeout: 5000})
|
|
||||||
.should('be.visible')
|
|
||||||
.then(() => {
|
|
||||||
// 重新获取三级菜单项
|
|
||||||
cy.get('.el-popper.is-light.el-popover .menuTitle.canClick')
|
|
||||||
.should('be.visible')
|
|
||||||
.then($updatedThirdMenus => {
|
|
||||||
const $currentThirdMenu = $updatedThirdMenus.eq(currentIndex);
|
|
||||||
const thirdMenuText = $currentThirdMenu.text().trim();
|
|
||||||
|
|
||||||
cy.log(`处理第 ${currentIndex + 1}/${$thirdMenuItems.length} 个三级菜单: ${thirdMenuText}`);
|
|
||||||
|
|
||||||
// 点击三级菜单项
|
|
||||||
cy.wrap($currentThirdMenu).click();
|
|
||||||
|
|
||||||
// 等待页面加载
|
|
||||||
waitForPageLoad();
|
|
||||||
|
|
||||||
// 处理下一个三级菜单项
|
|
||||||
cy.wait(1000).then(() => {
|
|
||||||
processThirdMenuItems($thirdMenuItems, currentIndex + 1);
|
|
||||||
});
|
|
||||||
});
|
|
||||||
});
|
|
||||||
};
|
|
||||||
|
|
||||||
// 开始处理三级菜单
|
|
||||||
cy.wrap($element).click();
|
|
||||||
|
|
||||||
// 等待三级菜单弹出框出现
|
|
||||||
cy.get('.el-popper.is-light.el-popover', {timeout: 5000})
|
|
||||||
.should('be.visible')
|
|
||||||
.then(() => {
|
.then(() => {
|
||||||
cy.get('.el-popper.is-light.el-popover .menuTitle.canClick')
|
return cy.get('.el-popper.is-light.el-popover', {timeout: 5000})
|
||||||
.should('be.visible')
|
.should('be.visible')
|
||||||
.then($thirdMenuItems => {
|
.find('.menuTitle.canClick')
|
||||||
if ($thirdMenuItems.length > 0) {
|
.should('be.visible');
|
||||||
cy.log(`发现 ${$thirdMenuItems.length} 个三级菜单项`);
|
|
||||||
processThirdMenuItems($thirdMenuItems);
|
|
||||||
} else {
|
|
||||||
cy.log('没有找到三级菜单项');
|
|
||||||
}
|
|
||||||
});
|
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
const processThirdMenuItems = ($thirdMenuItems, currentIndex = 0) => {
|
||||||
|
if (currentIndex >= $thirdMenuItems.length) {
|
||||||
|
cy.log(`✅ 完成所有三级菜单处理: ${menuItem.text}`);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
// 获取并处理当前三级菜单项
|
||||||
|
cy.getThirdMenuItems().then($updatedThirdMenus => {
|
||||||
|
const $currentThirdMenu = $updatedThirdMenus.eq(currentIndex);
|
||||||
|
const thirdMenuText = $currentThirdMenu.text().trim();
|
||||||
|
|
||||||
|
cy.log(`处理第 ${currentIndex + 1}/${$thirdMenuItems.length} 个三级菜单: ${thirdMenuText}`);
|
||||||
|
|
||||||
|
// 点击三级菜单项
|
||||||
|
cy.wrap($currentThirdMenu).click();
|
||||||
|
waitForPageLoad();
|
||||||
|
|
||||||
|
// 检查并处理标签页
|
||||||
|
cy.get('.vab-tabs .el-tabs__item').then($tabs => {
|
||||||
|
if ($tabs.length > 0) {
|
||||||
|
// 遍历所有标签页
|
||||||
|
cy.get('.vab-tabs .el-tabs__item').each(($tab) => {
|
||||||
|
const tabText = $tab.text().trim();
|
||||||
|
cy.log(`处理标签页: ${tabText}`);
|
||||||
|
|
||||||
|
// 点击标签页
|
||||||
|
cy.wrap($tab).click();
|
||||||
|
cy.wait(1000);
|
||||||
|
|
||||||
|
// 等待页面加载
|
||||||
|
waitForPageLoad();
|
||||||
|
});
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
// 关闭当前菜单的标签页
|
||||||
|
closeActiveTab(thirdMenuText);
|
||||||
|
|
||||||
|
// 处理下一个三级菜单项
|
||||||
|
cy.wait(1000).then(() => {
|
||||||
|
processThirdMenuItems($thirdMenuItems, currentIndex + 1);
|
||||||
|
});
|
||||||
|
});
|
||||||
|
};
|
||||||
|
|
||||||
|
// 开始处理三级菜单
|
||||||
|
cy.getThirdMenuItems().then($thirdMenuItems => {
|
||||||
|
if ($thirdMenuItems.length > 0) {
|
||||||
|
cy.log(`发现 ${$thirdMenuItems.length} 个三级菜单项`);
|
||||||
|
processThirdMenuItems($thirdMenuItems);
|
||||||
|
} else {
|
||||||
|
cy.log('没有找到三级菜单项');
|
||||||
|
}
|
||||||
|
});
|
||||||
};
|
};
|
||||||
const waitForPageLoad = () => {
|
const waitForPageLoad = () => {
|
||||||
cy.log('等待页面数据加载...');
|
cy.log('等待页面数据加载...');
|
||||||
@ -302,6 +350,36 @@ describe('隆基系统页面验证', () => {
|
|||||||
saveMenuItemsToFile();
|
saveMenuItemsToFile();
|
||||||
};
|
};
|
||||||
|
|
||||||
|
// 处理菜单测试的方法
|
||||||
|
const processMenuTests = (menuData) => {
|
||||||
|
const {menuItems} = menuData.content;
|
||||||
|
const totalMenus = menuItems.length;
|
||||||
|
const untestedMenus = menuItems.filter(item => !item.tested);
|
||||||
|
|
||||||
|
cy.log('📊 菜单测试统计');
|
||||||
|
cy.log(`总菜单数: ${totalMenus}`);
|
||||||
|
cy.log(`待测试数: ${untestedMenus.length}`);
|
||||||
|
cy.log(`已完成数: ${totalMenus - untestedMenus.length}`);
|
||||||
|
|
||||||
|
// 遍历每个菜单项
|
||||||
|
menuItems.forEach((menuItem, index) => {
|
||||||
|
// 跳过已测试的菜单项
|
||||||
|
if (menuItem.tested) {
|
||||||
|
cy.log(`⏭️ 跳过已测试的菜单项:${menuItem.text}`);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
cy.log(`🔄 正在处理第 ${index + 1}/${totalMenus} 个菜单项:${menuItem.text}`);
|
||||||
|
|
||||||
|
// 根据菜单类型调用对应的处理方法
|
||||||
|
if (menuItem.hasThirdMenu) {
|
||||||
|
handleThirdLevelMenu(menuItem);
|
||||||
|
} else {
|
||||||
|
handleSecondLevelMenu(menuItem);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
};
|
||||||
|
|
||||||
// 测试入口
|
// 测试入口
|
||||||
it('验证系统页面是否可用', () => {
|
it('验证系统页面是否可用', () => {
|
||||||
// 验证环境参数
|
// 验证环境参数
|
||||||
@ -317,32 +395,11 @@ describe('隆基系统页面验证', () => {
|
|||||||
|
|
||||||
getLatestDataFileContent().then(result => {
|
getLatestDataFileContent().then(result => {
|
||||||
if (result && result.content && result.content.menuItems) {
|
if (result && result.content && result.content.menuItems) {
|
||||||
const totalMenus = result.content.menuItems.length;
|
processMenuTests(result);
|
||||||
const untestedMenus = result.content.menuItems.filter(item => !item.tested);
|
|
||||||
|
|
||||||
cy.log(`菜单项统计:总数 ${totalMenus},待测试 ${untestedMenus.length},已完成 ${totalMenus - untestedMenus.length}`);
|
|
||||||
|
|
||||||
// 遍历每个菜单项
|
|
||||||
result.content.menuItems.forEach((menuItem, index) => {
|
|
||||||
// 如果菜单项已测试,则跳过
|
|
||||||
if (menuItem.tested) {
|
|
||||||
cy.log(`⏭️ 跳过已测试的菜单项:${menuItem.text}`);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
cy.log(`🔄 正在处理第 ${index + 1} 个菜单项:${menuItem.text}`);
|
|
||||||
// 根据菜单层级调用不同的处理方法
|
|
||||||
if (menuItem.hasThirdMenu) {
|
|
||||||
handleThirdLevelMenu(menuItem);
|
|
||||||
} else {
|
|
||||||
handleSecondLevelMenu(menuItem);
|
|
||||||
}
|
|
||||||
|
|
||||||
});
|
|
||||||
} else {
|
} else {
|
||||||
cy.log('❌ 没有找到有效的菜单数据');
|
cy.log('❌ 没有找到有效的菜单数据');
|
||||||
}
|
}
|
||||||
})
|
});
|
||||||
|
|
||||||
cy.log('✅ 系统菜单加载成功');
|
cy.log('✅ 系统菜单加载成功');
|
||||||
cy.log(`🏁 测试完成,环境: ${SELECT_ENV}`);
|
cy.log(`🏁 测试完成,环境: ${SELECT_ENV}`);
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user