refactor: 场景报告重构修改名称交互并增加跳转场景的功能,场景报告增加步骤统计

场景报告重构修改名称交互并增加跳转场景的功能,场景报告增加步骤统计
This commit is contained in:
song-tianyang 2021-06-15 19:56:32 +08:00 committed by 刘瑞斌
parent 16ac406fbd
commit b1f13fceba
6 changed files with 136 additions and 19 deletions

View File

@ -155,10 +155,9 @@ public class APIBackendListenerClient extends AbstractBackendListenerClient impl
public void teardownTest(BackendListenerContext context) throws Exception {
TestResult testResult = new TestResult();
testResult.setTestId(testId);
testResult.setTotal(queue.size());
testResult.setSetReportId(this.setReportId);
testResult.setConsole(getConsole());
testResult.setTotal(0);
// 一个脚本里可能包含多个场景(ThreadGroup)所以要区分开key: 场景Id
final Map<String, ScenarioResult> scenarios = new LinkedHashMap<>();
queue.forEach(result -> {
@ -198,11 +197,12 @@ public class APIBackendListenerClient extends AbstractBackendListenerClient impl
testResult.addPassAssertions(requestResult.getPassAssertions());
testResult.addTotalAssertions(requestResult.getTotalAssertions());
testResult.setTotal(testResult.getTotal()+1);
scenarioResult.addPassAssertions(requestResult.getPassAssertions());
scenarioResult.addTotalAssertions(requestResult.getTotalAssertions());
}
});
testResult.getScenarios().addAll(scenarios.values());
testResult.getScenarios().sort(Comparator.comparing(ScenarioResult::getId));
ApiTestReport report = null;

View File

@ -1,6 +1,7 @@
package io.metersphere.api.jmeter;
import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONArray;
import io.metersphere.commons.constants.DelimiterConstants;
import lombok.Data;
import org.apache.commons.collections.CollectionUtils;
@ -46,6 +47,11 @@ public class TestResult {
private Map<String, Boolean> margeScenariMap = new HashMap<>();
private Map<String, Boolean> scenarioStepMap = new HashMap<>();
private int scenarioStepSuccess = 0;
private int scenarioStepError = 0;
private int scenarioStepTotal = 0;
public void addError(int count) {
this.error += count;
}
@ -74,12 +80,33 @@ public class TestResult {
}
}
private void setStepStatus(String step_names, boolean status) {
if (!scenarioStepMap.containsKey(step_names) || status) {
scenarioStepMap.put(step_names, status);
}
}
public void addScenario(ScenarioResult result) {
if (result != null && CollectionUtils.isNotEmpty(result.getRequestResults())) {
result.getRequestResults().forEach(item -> {
String itemScenarioName = "";
if (StringUtils.isNotEmpty(item.getScenario())) {
List<String> id_names = JSON.parseObject(item.getScenario(), List.class);
this.setStatus(id_names, item.getError() > 0);
List<String> all_id_names = JSON.parseObject(item.getScenario(), List.class);
if(all_id_names.size()>1){
List<String> id_names = new ArrayList<>();
all_id_names.forEach(name -> {
if(!name.endsWith(result.getName())){
id_names.add(name);
}
});
this.setStatus(id_names, item.getError() > 0);
itemScenarioName = JSONArray.toJSONString(id_names);
}else{
this.setStatus(all_id_names, item.getError() > 0);
itemScenarioName = JSONArray.toJSONString(all_id_names);
}
}
if (StringUtils.isNotEmpty(item.getName()) && item.getName().indexOf(SEPARATOR) != -1) {
String array[] = item.getName().split(SEPARATOR);
@ -102,17 +129,38 @@ public class TestResult {
}
});
}
this.setStepStatus(item.getName()+itemScenarioName,item.getError()>0);
});
scenarios.add(result);
}
for (String key : margeScenariMap.keySet()) {
if (margeScenariMap.get(key)) {
this.scenarioError++;
/**
* 1.10.2 场景成功/失败统计不再按照请求为纬度按照场景为纬度
*/
for (String key : scenarioStepMap.keySet()) {
if (scenarioStepMap .get(key)) {
this.scenarioStepError++;
} else {
this.scenarioSuccess++;
this.scenarioStepSuccess++;
}
}
this.setScenarioTotal(this.margeScenariMap.size());
boolean hasError = false;
for (String key : margeScenariMap.keySet()) {
if (margeScenariMap.get(key)) {
hasError = true;
break;
}
}
if(!margeScenariMap.isEmpty()){
if(hasError){
this.scenarioError ++;
}else {
this.scenarioSuccess++;
}
this.scenarioTotal++;
}
this.setScenarioStepTotal(this.scenarioStepMap.size());
}
}

View File

@ -411,6 +411,9 @@ public class ApiScenarioReportService {
testResult.setScenarioSuccess(testResult.getScenarioSuccess() + scenarioResult.getScenarioSuccess());
testResult.setScenarioError(testResult.getScenarioError() + scenarioResult.getScenarioError());
testResult.setConsole(scenarioResult.getConsole());
testResult.setScenarioStepError(scenarioResult.getScenarioStepError()+testResult.getScenarioStepError());
testResult.setScenarioStepSuccess(scenarioResult.getScenarioStepSuccess()+testResult.getScenarioStepSuccess());
testResult.setScenarioStepTotal(scenarioResult.getScenarioStepTotal()+testResult.getScenarioStepTotal());
} catch (Exception e) {
LogUtil.error(e.getMessage());
}

View File

@ -2,7 +2,20 @@
<header class="report-header">
<el-row>
<el-col>
<span v-if="!debug"><el-input size="mini" style="width: 200px" v-model="report.name"/> </span>
<span v-if="!debug">
<el-input v-if="nameIsEdit" size="mini" @blur="nameIsEdit = false" style="width: 200px" v-model="report.name"/>
<span v-else>
<!-- <el-link type="info" @click="redirectPage()" target="_blank" style="color: #000000">{{report.name}}-->
<!-- </el-link>-->
<router-link v-if="isSingleScenario" :to="{name: 'ApiAutomation', params: { dataSelectRange: 'edit:' + scenarioId }}">
{{ report.name }}
</router-link>
<span v-else>
{{ report.name }}
</span>
<i class="el-icon-edit" style="cursor:pointer" @click="nameIsEdit = true" @click.stop/>
</span>
</span>
<span class="time"> {{ report.createTime | timestampFormatDate }}</span>
<el-button v-if="!debug" v-permission="['PROJECT_API_REPORT:READ+EXPORT']" :disabled="isReadOnly" class="export-button" plain type="primary" size="mini" @click="handleExport(report.name)" style="margin-right: 10px">
@ -20,6 +33,8 @@
<script>
import {getUUID} from "@/common/js/utils";
export default {
name: "MsApiReportViewHeader",
props: {
@ -30,14 +45,28 @@
path() {
return "/api/test/edit?id=" + this.report.testId;
},
scenarioId(){
if(typeof this.report.scenarioId === 'string'){
return this.report.scenarioId;
}else {
return "";
}
},
isSingleScenario(){
try {
JSON.parse(this.report.scenarioId);
return false;
} catch(e){
return true;
}
}
},
data() {
return {
isReadOnly: false,
nameIsEdit:false,
}
},
created() {
},
methods: {
handleExport(name) {
@ -45,7 +74,14 @@
},
handleSave(name) {
this.$emit('reportSave', name);
}
},
// redirectPage(){
// if(typeof this.report.scenarioId === 'string'){
// let uuid = getUUID();
// let projectId = getCurrentProjectID();
// this.$router.push({name:'ApiAutomation',params:{redirectID:uuid,scenarioId:this.report.scenarioId}});
// }
// },
}
}
</script>
@ -55,5 +91,13 @@
.export-button {
float: right;
}
.scenario-name {
overflow: hidden;
text-overflow: ellipsis;
white-space: nowrap;
font-size: 13px;
width: 100%;
}
</style>

View File

@ -38,23 +38,44 @@
<div style="width: 50%">
<el-row type="flex" justify="center" align="middle">
<el-row type="flex" justify="center" align="middle">
<div class="metric-box" style="margin-right: 50px">
<div class="metric-box">
<div class="value">{{ content.scenarioTotal ? content.scenarioTotal : 0}}</div>
<div class="name">{{ $t('api_test.scenario.scenario') }}</div>
</div>
<i class="circle success"/>
<i class="circle success" style="margin-left: 20px;margin-right: 20px"/>
<div class="metric-box">
<div class="value">{{ content.scenarioSuccess ? content.scenarioSuccess: 0 }}</div>
<div class="name">{{ $t('api_report.success') }}</div>
</div>
<div style="width: 40px"></div>
<i class="circle fail"/>
<!-- <div style="width: 40px"></div>-->
<i class="circle fail" style="margin-left: 20px;margin-right: 20px"/>
<div class="metric-box">
<div class="value">{{ content.scenarioError ? content.scenarioError : 0 }}</div>
<div class="name">{{ $t('api_report.fail') }}</div>
</div>
</el-row>
</el-row>
<el-divider></el-divider>
<el-row type="flex" justify="center" align="middle">
<el-row type="flex" justify="center" align="middle">
<div class="metric-box">
<div class="value">{{ content.scenarioStepTotal ? content.scenarioStepTotal : 0}}</div>
<div class="name">{{ $t('test_track.plan_view.step') }}</div>
</div>
<i class="circle success" style="margin-left: 20px;margin-right: 20px"/>
<div class="metric-box">
<div class="value">{{ content.scenarioStepSuccess ? content.scenarioStepSuccess: 0 }}</div>
<div class="name">{{ $t('api_report.success') }}</div>
</div>
<!-- <div style="width: 40px"></div>-->
<i class="circle fail" style="margin-left: 20px;margin-right: 20px"/>
<div class="metric-box">
<div class="value">{{ content.scenarioStepError ? content.scenarioStepError : 0 }}</div>
<div class="name">{{ $t('api_report.fail') }}</div>
</div>
</el-row>
</el-row>
</div>
<div class="split"></div>

View File

@ -317,6 +317,7 @@ export default {
},
data() {
return {
showConfigButtonWithOutPermission:false,
onSampleError: false,
props: {
label: "label",