aaaaaaaaaa
This commit is contained in:
parent
d55befa222
commit
d12e39ff3a
@ -59,7 +59,7 @@ module.exports = {
|
||||
createReportDir(dirPath) {
|
||||
try {
|
||||
if (!fs.existsSync(dirPath)) {
|
||||
fs.mkdirSync(dirPath, { recursive: true });
|
||||
fs.mkdirSync(dirPath, {recursive: true});
|
||||
}
|
||||
return null;
|
||||
} catch (e) {
|
||||
@ -107,11 +107,11 @@ module.exports = {
|
||||
}
|
||||
},
|
||||
|
||||
saveReport({ data, filename }) {
|
||||
saveReport({data, filename}) {
|
||||
try {
|
||||
const reportsDir = path.join(__dirname, 'cypress', 'reports');
|
||||
if (!fs.existsSync(reportsDir)) {
|
||||
fs.mkdirSync(reportsDir, { recursive: true });
|
||||
fs.mkdirSync(reportsDir, {recursive: true});
|
||||
}
|
||||
fs.writeFileSync(
|
||||
path.join(reportsDir, filename),
|
||||
@ -122,9 +122,43 @@ module.exports = {
|
||||
console.error('Save report failed:', e);
|
||||
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;
|
||||
},
|
||||
},
|
||||
|
||||
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) => {
|
||||
cy.log(`📎 处理二级菜单: ${menuItem.text}`);
|
||||
// TODO: 添加二级菜单的具体处理逻辑
|
||||
// 1. 点击菜单
|
||||
// 2. 验证页面加载
|
||||
// 3. 检查页面内容
|
||||
|
||||
// 点击菜单项
|
||||
cy.get('.el-sub-menu__title, .el-menu-item').eq(menuItem.index).then($element => {
|
||||
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) => {
|
||||
cy.log(`📑 处理三级菜单: ${menuItem.text}`);
|
||||
|
||||
// 根据菜单索引找到对应的菜单元素
|
||||
cy.get('.el-sub-menu__title, .el-menu-item').eq(menuItem.index).then($element => {
|
||||
const processThirdMenuItems = ($thirdMenuItems, currentIndex = 0) => {
|
||||
if (currentIndex >= $thirdMenuItems.length) {
|
||||
cy.log(`✅ 完成所有三级菜单处理: ${menuItem.text}`);
|
||||
return;
|
||||
}
|
||||
// 获取二级菜单元素
|
||||
cy.get('.el-sub-menu__title, .el-menu-item').eq(menuItem.index).as('secondMenu');
|
||||
|
||||
// 确保二级菜单展开并等待三级菜单出现
|
||||
cy.wrap($element).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')
|
||||
// 定义获取三级菜单的命令
|
||||
Cypress.Commands.add('getThirdMenuItems', () => {
|
||||
return cy.get('@secondMenu').click()
|
||||
.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')
|
||||
.then($thirdMenuItems => {
|
||||
if ($thirdMenuItems.length > 0) {
|
||||
cy.log(`发现 ${$thirdMenuItems.length} 个三级菜单项`);
|
||||
processThirdMenuItems($thirdMenuItems);
|
||||
} else {
|
||||
cy.log('没有找到三级菜单项');
|
||||
}
|
||||
});
|
||||
.find('.menuTitle.canClick')
|
||||
.should('be.visible');
|
||||
});
|
||||
});
|
||||
|
||||
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 = () => {
|
||||
cy.log('等待页面数据加载...');
|
||||
@ -302,6 +350,36 @@ describe('隆基系统页面验证', () => {
|
||||
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('验证系统页面是否可用', () => {
|
||||
// 验证环境参数
|
||||
@ -317,32 +395,11 @@ describe('隆基系统页面验证', () => {
|
||||
|
||||
getLatestDataFileContent().then(result => {
|
||||
if (result && result.content && result.content.menuItems) {
|
||||
const totalMenus = result.content.menuItems.length;
|
||||
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);
|
||||
}
|
||||
|
||||
});
|
||||
processMenuTests(result);
|
||||
} else {
|
||||
cy.log('❌ 没有找到有效的菜单数据');
|
||||
}
|
||||
})
|
||||
});
|
||||
|
||||
cy.log('✅ 系统菜单加载成功');
|
||||
cy.log(`🏁 测试完成,环境: ${SELECT_ENV}`);
|
||||
|
||||
Loading…
Reference in New Issue
Block a user