ui自动化和压力测试bug修改

This commit is contained in:
2025-05-28 16:31:27 +08:00
parent 66498fd750
commit 080a80d53d
5 changed files with 147 additions and 89 deletions

View File

@@ -216,13 +216,16 @@ public class UiSceneStepsServiceImpl implements IUiSceneStepsService {
if (1 == uiReport.getStatus()){ if (1 == uiReport.getStatus()){
uiReport.setStatus(4); uiReport.setStatus(4);
} }
if (scenesErrorNumber > 0){
uiReport.setStatus(2);
}
uiReportService.updateUiReport(uiReport); uiReportService.updateUiReport(uiReport);
//修改ui_automation //修改ui_automation
UiAutomation uiAutomation1 = new UiAutomation(); UiAutomation uiAutomation1 = new UiAutomation();
uiAutomation1.setId(automationId); uiAutomation1.setId(automationId);
uiAutomation1.setExecutionResult("2"); uiAutomation1.setExecutionResult("2");
if (!uiAutomation.getExecutionResult().equals("2")) { if (scenesErrorNumber == 0) {
uiAutomation1.setExecutionResult("3"); uiAutomation1.setExecutionResult("3");
} }
uiAutomation1.setUpdateTime(DateUtils.getNowDate()); uiAutomation1.setUpdateTime(DateUtils.getNowDate());
@@ -470,11 +473,15 @@ public class UiSceneStepsServiceImpl implements IUiSceneStepsService {
Map<String, Object> stringObjectMap = filterByAssertionQOList(afterSettingList, seleniumUtils); Map<String, Object> stringObjectMap = filterByAssertionQOList(afterSettingList, seleniumUtils);
//断言失败是否终止 //断言失败是否终止
String continueExecution1 = (String) stringObjectMap.get("continueExecution"); String continueExecution1 = (String) stringObjectMap.get("continueExecution");
String isSuccess = (String) stringObjectMap.get("isSuccess");
if (continueExecution1.equals("1")) { if (continueExecution1.equals("1")) {
continueExecution = false; continueExecution = false;
report.setLogInfo(""); report.setLogInfo("");
report.setExecutionFlag("2"); report.setExecutionFlag("2");
} }
if("0".equals(isSuccess)){
report.setExecutionFlag("2");
}
List<AssertionReportVO> assertionReportVOS = (List<AssertionReportVO>) stringObjectMap.get("assertionReportVOS"); List<AssertionReportVO> assertionReportVOS = (List<AssertionReportVO>) stringObjectMap.get("assertionReportVOS");
Gson gson = new Gson(); Gson gson = new Gson();
report.setAssertionJson(assertionReportVOS.isEmpty() ? null : gson.toJson(assertionReportVOS)); report.setAssertionJson(assertionReportVOS.isEmpty() ? null : gson.toJson(assertionReportVOS));
@@ -514,9 +521,12 @@ public class UiSceneStepsServiceImpl implements IUiSceneStepsService {
Map<String, Object> result = new HashMap<>(); Map<String, Object> result = new HashMap<>();
String continueExecution = "2"; String continueExecution = "2";
List<AssertionReportVO> assertionReports = new ArrayList<>(); List<AssertionReportVO> assertionReports = new ArrayList<>();
String isSuccess = "1"; // 默认所有断言成功
result.put("continueExecution", continueExecution); result.put("continueExecution", continueExecution);
result.put("assertionReportVOS", assertionReports); result.put("assertionReportVOS", assertionReports);
result.put("isSuccess", isSuccess); // 添加整体成功标志
List<UiHighSettingVO> uiHighSettingVOS = settingList.stream() List<UiHighSettingVO> uiHighSettingVOS = settingList.stream()
.filter(setting -> setting.getOperateType().equals("2") && 1 == setting.getIsDisabled()) .filter(setting -> setting.getOperateType().equals("2") && 1 == setting.getIsDisabled())
.toList(); .toList();
@@ -561,15 +571,20 @@ public class UiSceneStepsServiceImpl implements IUiSceneStepsService {
errorDetail = "不支持的断言类型: " + assertionQO.getAssertionType(); errorDetail = "不支持的断言类型: " + assertionQO.getAssertionType();
report.setErrorInfo(errorDetail); report.setErrorInfo(errorDetail);
report.setIsSuccess("0"); report.setIsSuccess("0");
isSuccess = "0"; // 设置整体失败标志
} }
if (!assertionResult && "1".equals(assertionQO.getIsFailedAbort())) { if (!assertionResult) {
continueExecution = "1"; isSuccess = "0"; // 任何断言失败都设置整体失败标志
result.put("continueExecution", continueExecution); if ("1".equals(assertionQO.getIsFailedAbort())) {
continueExecution = "1";
result.put("continueExecution", continueExecution);
}
} }
} catch (Exception e) { } catch (Exception e) {
report.setErrorInfo("断言执行异常: " + e.getMessage()); report.setErrorInfo("断言执行异常: " + e.getMessage());
report.setIsSuccess("0"); report.setIsSuccess("0");
isSuccess = "0"; // 异常也设置整体失败标志
log.error("断言执行异常", e); log.error("断言执行异常", e);
} }
@@ -578,6 +593,7 @@ public class UiSceneStepsServiceImpl implements IUiSceneStepsService {
} }
} }
result.put("assertionReportVOS", assertionReports); result.put("assertionReportVOS", assertionReports);
result.put("isSuccess", isSuccess); // 更新最终的整体成功标志
return result; return result;
} }
@@ -925,7 +941,7 @@ public class UiSceneStepsServiceImpl implements IUiSceneStepsService {
*/ */
public Map<String, Object> filterBydataExtractionQOList(List<UiHighSettingVO> settingList, SeleniumUtils seleniumUtils) { public Map<String, Object> filterBydataExtractionQOList(List<UiHighSettingVO> settingList, SeleniumUtils seleniumUtils) {
List<UiHighSettingVO> uiHighSettingVOS = settingList.stream() List<UiHighSettingVO> uiHighSettingVOS = settingList.stream()
.filter(setting -> setting.getOperateType().equals("3") && setting.getIsDisabled() == 0) .filter(setting -> setting.getOperateType().equals("3") && setting.getIsDisabled() == 1)
.toList(); .toList();
Map<String, Object> variableStorage = new HashMap<>(); Map<String, Object> variableStorage = new HashMap<>();
if (CollectionUtils.isEmpty(uiHighSettingVOS)) { if (CollectionUtils.isEmpty(uiHighSettingVOS)) {

View File

@@ -14,10 +14,10 @@
<div class="date-top"> <div class="date-top">
<i class="el-icon-date"></i> <i class="el-icon-date"></i>
<span class="date-title">SCHEDULER</span> <span class="date-title">SCHEDULER</span>
<el-switch v-model="switchOpen" @change="switchChange"></el-switch> <el-switch v-model="addForm.crontabStatus" :active-value="1" :inactive-value="0" @change="handleSwitchChange"></el-switch>
</div> </div>
<div class="date-bottom"> <div class="date-bottom" v-if="addForm.crontabStatus === 1">
<span>下次执行时间</span> <span>下次执行时间{{ nextExecutionTime }}</span>
</div> </div>
</div> </div>
</div> </div>
@@ -124,8 +124,6 @@
<div class="crontab-wrap"> <div class="crontab-wrap">
<div class="title">Crontab表达式</div> <div class="title">Crontab表达式</div>
<el-input v-model="addForm.crontab" @input="updateExecutionTimes" placeholder="请输入crontab表达式" /> <el-input v-model="addForm.crontab" @input="updateExecutionTimes" placeholder="请输入crontab表达式" />
<div class="title" style="margin-left: 50px;">定时任务开关</div>
<el-switch v-model="addForm.crontabStatus" active-value="1" inactive-value="0"></el-switch>
</div> </div>
<div class="near-time"> <div class="near-time">
<div class="title">最近5次运行时间</div> <div class="title">最近5次运行时间</div>
@@ -135,8 +133,8 @@
</div> </div>
</el-tabs> </el-tabs>
<span slot="footer" class="dialog-footer"> <span slot="footer" class="dialog-footer">
<el-button @click="dialogVisibleTime = false, switchOpen = false"> </el-button> <el-button @click="dialogVisibleTime = false, addForm.crontabStatus = false"> </el-button>
<el-button type="primary" @click="dialogVisibleTime = false"> </el-button> <el-button type="primary" @click="handleDialogConfirm"> </el-button>
</span> </span>
</el-dialog> </el-dialog>
</div> </div>
@@ -144,6 +142,7 @@
<script> <script>
import { addTest, addAndExecuteTest, getTestCaseList } from '../../../api/performance'; import { addTest, addAndExecuteTest, getTestCaseList } from '../../../api/performance';
import parser from 'cron-parser'; // 添加 cron-parser 依赖
export default { export default {
name: "PerformanceAdd", name: "PerformanceAdd",
@@ -162,7 +161,7 @@ export default {
rpsStatus: '0', // rps状态0关闭1开启默认0 rpsStatus: '0', // rps状态0关闭1开启默认0
rpsLimit: '0', // 每分钟rps上限数默认0 rpsLimit: '0', // 每分钟rps上限数默认0
crontab: '', // crontab表达式 crontab: '', // crontab表达式
crontabStatus: '0', // 定时任务状态0关闭1开启默认0 crontabStatus: 0, // 定时任务状态0关闭1开启默认0
loopCount: '0', // 迭代次数默认0 loopCount: '0', // 迭代次数默认0
}, },
activeName: 'first', activeName: 'first',
@@ -177,26 +176,10 @@ export default {
searchScene: '', searchScene: '',
changeList: [], changeList: [],
multipleSelection: [], multipleSelection: [],
switchOpen: false,
dialogVisibleTime: false, dialogVisibleTime: false,
activeTime: 'first', activeTime: 'first',
executionTimeList: [ executionTimeList: [], // 修改为空数组
{ nextExecutionTime: '', // 添加下次执行时间
time: "2025-02-18 10:00:00",
},
{
time: "2025-02-19 10:00:00",
},
{
time: "2025-02-20 10:00:00",
},
{
time: "2025-02-21 10:00:00",
},
{
time: "2025-02-22 10:00:00",
},
],
validation: false, // 校验 validation: false, // 校验
} }
}, },
@@ -313,37 +296,70 @@ export default {
}) })
this.dialogVisible = false this.dialogVisible = false
}, },
switchChange(val) {
this.dialogVisibleTime = val
},
handleClose() { handleClose() {
this.dialogVisibleTime = false this.dialogVisibleTime = false
this.switchOpen = false this.addForm.crontabStatus = false
}, },
// 根据crontab表达式更新执行时间 // 更新执行时间列表
updateExecutionTimes() { updateExecutionTimes() {
const crontab = this.addForm.crontab.trim(); const crontab = this.addForm.crontab.trim();
if (!crontab) { if (!crontab) {
this.executionTimeList = []; this.executionTimeList = [];
this.nextExecutionTime = '';
return; return;
} }
try { try {
// 解析crontab表达式 // 解析crontab表达式
const interval = cronParser.parseExpression(crontab); const interval = parser.parseExpression(crontab);
const times = []; const times = [];
// 获取最近次执行时间 // 获取最近5次执行时间
for (let i = 0; i < 3; i++) { for (let i = 0; i < 5; i++) {
const nextTime = interval.next().toDate(); // 获取 Date 对象 const nextTime = interval.next().toDate();
const formattedTime = this.formatDate(nextTime); // 格式化时间 times.push({
times.push({ time: formattedTime }); time: this.formatDate(nextTime)
});
} }
this.executionTimeList = times; this.executionTimeList = times;
this.nextExecutionTime = times[0].time; // 设置下次执行时间
} catch (error) { } catch (error) {
console.error('无效的crontab表达式:', error); this.$message.error('无效的crontab表达式');
this.executionTimeList = [{ time: '无效的crontab表达式' }]; this.executionTimeList = [];
this.nextExecutionTime = '';
}
},
// 格式化日期
formatDate(date) {
const year = date.getFullYear();
const month = String(date.getMonth() + 1).padStart(2, '0');
const day = String(date.getDate()).padStart(2, '0');
const hour = String(date.getHours()).padStart(2, '0');
const minute = String(date.getMinutes()).padStart(2, '0');
const second = String(date.getSeconds()).padStart(2, '0');
return `${year}-${month}-${day} ${hour}:${minute}:${second}`;
},
// 修改确定按钮的处理函数
handleDialogConfirm() {
if (!this.addForm.crontab.trim()) {
this.$message.warning('请输入Crontab表达式');
return;
}
try {
parser.parseExpression(this.addForm.crontab.trim());
this.updateExecutionTimes();
this.dialogVisibleTime = false;
} catch (error) {
this.$message.error('无效的crontab表达式请修正后再确定');
return;
}
},
// 添加开关变化处理函数
handleSwitchChange(val) {
if (val === 1) {
this.dialogVisibleTime = true;
} }
}, },
} }

View File

@@ -15,10 +15,10 @@
<div class="date-top"> <div class="date-top">
<i class="el-icon-date"></i> <i class="el-icon-date"></i>
<span class="date-title">SCHEDULER</span> <span class="date-title">SCHEDULER</span>
<el-switch v-model="switchOpen" @change="switchChange"></el-switch> <el-switch v-model="addForm.crontabStatus" :active-value="1" :inactive-value="0" @change="handleSwitchChange"></el-switch>
</div> </div>
<div class="date-bottom"> <div class="date-bottom" v-if="addForm.crontabStatus === 1">
<span>下次执行时间</span> <span>下次执行时间{{ nextExecutionTime }}</span>
</div> </div>
</div> </div>
</div> </div>
@@ -125,8 +125,6 @@
<div class="crontab-wrap"> <div class="crontab-wrap">
<div class="title">Crontab表达式</div> <div class="title">Crontab表达式</div>
<el-input v-model="addForm.crontab" @input="updateExecutionTimes" placeholder="请输入crontab表达式" /> <el-input v-model="addForm.crontab" @input="updateExecutionTimes" placeholder="请输入crontab表达式" />
<div class="title" style="margin-left: 50px;">定时任务开关</div>
<el-switch v-model="addForm.crontabStatus" active-value="1" inactive-value="0"></el-switch>
</div> </div>
<div class="near-time"> <div class="near-time">
<div class="title">最近5次运行时间</div> <div class="title">最近5次运行时间</div>
@@ -136,8 +134,8 @@
</div> </div>
</el-tabs> </el-tabs>
<span slot="footer" class="dialog-footer"> <span slot="footer" class="dialog-footer">
<el-button @click="dialogVisibleTime = false, switchOpen = false"> </el-button> <el-button @click="dialogVisibleTime = false, addForm.crontabStatus = 0"> </el-button>
<el-button type="primary" @click="dialogVisibleTime = false"> </el-button> <el-button type="primary" @click="handleDialogConfirm"> </el-button>
</span> </span>
</el-dialog> </el-dialog>
</div> </div>
@@ -146,6 +144,7 @@
<script> <script>
import { editTest, editAndExecuteTest, getTestCaseList, getTestDetail, executeTest } from '../../../api/performance'; import { editTest, editAndExecuteTest, getTestCaseList, getTestDetail, executeTest } from '../../../api/performance';
import {runTestPlanCase} from "../../../api/test/planCase"; import {runTestPlanCase} from "../../../api/test/planCase";
import parser from 'cron-parser'; // 添加 cron-parser 依赖
export default { export default {
name: "PerformanceEdit", name: "PerformanceEdit",
@@ -164,7 +163,7 @@ export default {
rpsStatus: '0', // rps状态0关闭1开启默认0 rpsStatus: '0', // rps状态0关闭1开启默认0
rpsLimit: '0', // 每分钟rps上限数默认0 rpsLimit: '0', // 每分钟rps上限数默认0
crontab: '', // crontab表达式 crontab: '', // crontab表达式
crontabStatus: '0', // 定时任务状态0关闭1开启默认0 crontabStatus: 0, // 定时任务状态0关闭1开启默认0
loopCount: '0', // 迭代次数默认0 loopCount: '0', // 迭代次数默认0
}, },
loading: false, loading: false,
@@ -180,26 +179,10 @@ export default {
searchScene: '', searchScene: '',
changeList: [], changeList: [],
multipleSelection: [], multipleSelection: [],
switchOpen: false,
dialogVisibleTime: false, dialogVisibleTime: false,
activeTime: 'first', activeTime: 'first',
executionTimeList: [ executionTimeList: [], // 修改为空数组
{ nextExecutionTime: '', // 添加下次执行时间
time: "2025-02-18 10:00:00",
},
{
time: "2025-02-19 10:00:00",
},
{
time: "2025-02-20 10:00:00",
},
{
time: "2025-02-21 10:00:00",
},
{
time: "2025-02-22 10:00:00",
},
],
validation: false, // 校验 validation: false, // 校验
} }
}, },
@@ -323,6 +306,7 @@ export default {
getTestDetail(this.$route.query.id).then(res => { getTestDetail(this.$route.query.id).then(res => {
if (res.code === 200) { if (res.code === 200) {
this.addForm = res.data this.addForm = res.data
this.addForm.crontabStatus = parseInt(res.data.crontabStatus)
res.data.performanceTestCaseVOList.forEach(item => { res.data.performanceTestCaseVOList.forEach(item => {
item.status = String(item.status) item.status = String(item.status)
}) })
@@ -366,37 +350,70 @@ export default {
this.dialogVisible = false this.dialogVisible = false
}, },
switchChange(val) {
this.dialogVisibleTime = val
},
handleClose() { handleClose() {
this.dialogVisibleTime = false this.dialogVisibleTime = false
this.switchOpen = false this.addForm.crontabStatus = 0
}, },
// 根据crontab表达式更新执行时间 // 更新执行时间列表
updateExecutionTimes() { updateExecutionTimes() {
const crontab = this.form.crontab.trim(); const crontab = this.addForm.crontab.trim();
if (!crontab) { if (!crontab) {
this.executionTimeList = []; this.executionTimeList = [];
this.nextExecutionTime = '';
return; return;
} }
try { try {
// 解析crontab表达式 // 解析crontab表达式
const interval = cronParser.parseExpression(crontab); const interval = parser.parseExpression(crontab);
const times = []; const times = [];
// 获取最近次执行时间 // 获取最近5次执行时间
for (let i = 0; i < 3; i++) { for (let i = 0; i < 5; i++) {
const nextTime = interval.next().toDate(); // 获取 Date 对象 const nextTime = interval.next().toDate();
const formattedTime = this.formatDate(nextTime); // 格式化时间 times.push({
times.push({ time: formattedTime }); time: this.formatDate(nextTime)
});
} }
this.executionTimeList = times; this.executionTimeList = times;
this.nextExecutionTime = times[0].time; // 设置下次执行时间
} catch (error) { } catch (error) {
console.error('无效的crontab表达式:', error); this.$message.error('无效的crontab表达式');
this.executionTimeList = [{ time: '无效的crontab表达式' }]; this.executionTimeList = [];
this.nextExecutionTime = '';
}
},
// 格式化日期
formatDate(date) {
const year = date.getFullYear();
const month = String(date.getMonth() + 1).padStart(2, '0');
const day = String(date.getDate()).padStart(2, '0');
const hour = String(date.getHours()).padStart(2, '0');
const minute = String(date.getMinutes()).padStart(2, '0');
const second = String(date.getSeconds()).padStart(2, '0');
return `${year}-${month}-${day} ${hour}:${minute}:${second}`;
},
// 修改确定按钮的处理函数
handleDialogConfirm() {
if (!this.addForm.crontab.trim()) {
this.$message.warning('请输入Crontab表达式');
return;
}
try {
parser.parseExpression(this.addForm.crontab.trim());
this.updateExecutionTimes();
this.dialogVisibleTime = false;
} catch (error) {
this.$message.error('无效的crontab表达式请修正后再确定');
return;
}
},
// 添加开关变化处理函数
handleSwitchChange(val) {
if (val === 1) {
this.dialogVisibleTime = true;
} }
}, },
} }

View File

@@ -86,8 +86,14 @@ export default {
}) })
}, },
// 分页 // 分页
handleSizeChange() { }, handleSizeChange(val) {
handleCurrentChange() { }, this.serachForm.pageSize = val;
this.getReportListData();
},
handleCurrentChange(val) {
this.serachForm.pageNum = val;
this.getReportListData();
},
serachList() { serachList() {
this.getReportListData() this.getReportListData()
}, },

View File

@@ -56,7 +56,7 @@
</div> </div>
<div class="scene-wrap"> <div class="scene-wrap">
<div class="scene-header"> <div class="scene-header">
<el-button size="mini" @click="handleClickSave">保存</el-button> <el-button size="mini" :loading="isSaving" @click="handleClickSave">保存</el-button>
</div> </div>
<SceneStep v-show="informationForm.uiSceneStepsVOList.length > 0" :detail="changeStep" /> <SceneStep v-show="informationForm.uiSceneStepsVOList.length > 0" :detail="changeStep" />
<AdvancedSetting v-show="informationForm.uiSceneStepsVOList.length > 0" :detail="changeStep" <AdvancedSetting v-show="informationForm.uiSceneStepsVOList.length > 0" :detail="changeStep"
@@ -90,6 +90,7 @@ export default {
data() { data() {
return { return {
activeName: 'first', activeName: 'first',
isSaving: false, // 保存按钮loading状态
groupList: [], // 分组 groupList: [], // 分组
informationForm: { informationForm: {
automationId: null, // 场景id automationId: null, // 场景id
@@ -208,14 +209,16 @@ export default {
this.$modal.msgWarning("请输入责任人"); this.$modal.msgWarning("请输入责任人");
return return
} }
this.isSaving = true;
updateAutomation(this.informationForm).then(res => { updateAutomation(this.informationForm).then(res => {
if (res.code === 200) { if (res.code === 200) {
this.$modal.msgSuccess("编辑成功") this.$modal.msgSuccess("编辑成功")
this.$tab.closeOpenPage({ path: "/ui-test/automation-test" });
} else { } else {
this.$modal.msgError("编辑失败") this.$modal.msgError("编辑失败")
} }
}).finally(() => {
this.isSaving = false;
}) })
}, },
} }