refactor: 场景报告重构修改名称交互并增加跳转场景的功能,场景报告增加步骤统计
场景报告重构修改名称交互并增加跳转场景的功能,场景报告增加步骤统计
This commit is contained in:
parent
16ac406fbd
commit
b1f13fceba
|
@ -155,10 +155,9 @@ public class APIBackendListenerClient extends AbstractBackendListenerClient impl
|
||||||
public void teardownTest(BackendListenerContext context) throws Exception {
|
public void teardownTest(BackendListenerContext context) throws Exception {
|
||||||
TestResult testResult = new TestResult();
|
TestResult testResult = new TestResult();
|
||||||
testResult.setTestId(testId);
|
testResult.setTestId(testId);
|
||||||
testResult.setTotal(queue.size());
|
|
||||||
testResult.setSetReportId(this.setReportId);
|
testResult.setSetReportId(this.setReportId);
|
||||||
testResult.setConsole(getConsole());
|
testResult.setConsole(getConsole());
|
||||||
|
testResult.setTotal(0);
|
||||||
// 一个脚本里可能包含多个场景(ThreadGroup),所以要区分开,key: 场景Id
|
// 一个脚本里可能包含多个场景(ThreadGroup),所以要区分开,key: 场景Id
|
||||||
final Map<String, ScenarioResult> scenarios = new LinkedHashMap<>();
|
final Map<String, ScenarioResult> scenarios = new LinkedHashMap<>();
|
||||||
queue.forEach(result -> {
|
queue.forEach(result -> {
|
||||||
|
@ -198,11 +197,12 @@ public class APIBackendListenerClient extends AbstractBackendListenerClient impl
|
||||||
|
|
||||||
testResult.addPassAssertions(requestResult.getPassAssertions());
|
testResult.addPassAssertions(requestResult.getPassAssertions());
|
||||||
testResult.addTotalAssertions(requestResult.getTotalAssertions());
|
testResult.addTotalAssertions(requestResult.getTotalAssertions());
|
||||||
|
testResult.setTotal(testResult.getTotal()+1);
|
||||||
scenarioResult.addPassAssertions(requestResult.getPassAssertions());
|
scenarioResult.addPassAssertions(requestResult.getPassAssertions());
|
||||||
scenarioResult.addTotalAssertions(requestResult.getTotalAssertions());
|
scenarioResult.addTotalAssertions(requestResult.getTotalAssertions());
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
testResult.getScenarios().addAll(scenarios.values());
|
testResult.getScenarios().addAll(scenarios.values());
|
||||||
testResult.getScenarios().sort(Comparator.comparing(ScenarioResult::getId));
|
testResult.getScenarios().sort(Comparator.comparing(ScenarioResult::getId));
|
||||||
ApiTestReport report = null;
|
ApiTestReport report = null;
|
||||||
|
|
|
@ -1,6 +1,7 @@
|
||||||
package io.metersphere.api.jmeter;
|
package io.metersphere.api.jmeter;
|
||||||
|
|
||||||
import com.alibaba.fastjson.JSON;
|
import com.alibaba.fastjson.JSON;
|
||||||
|
import com.alibaba.fastjson.JSONArray;
|
||||||
import io.metersphere.commons.constants.DelimiterConstants;
|
import io.metersphere.commons.constants.DelimiterConstants;
|
||||||
import lombok.Data;
|
import lombok.Data;
|
||||||
import org.apache.commons.collections.CollectionUtils;
|
import org.apache.commons.collections.CollectionUtils;
|
||||||
|
@ -46,6 +47,11 @@ public class TestResult {
|
||||||
|
|
||||||
private Map<String, Boolean> margeScenariMap = new HashMap<>();
|
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) {
|
public void addError(int count) {
|
||||||
this.error += 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) {
|
public void addScenario(ScenarioResult result) {
|
||||||
if (result != null && CollectionUtils.isNotEmpty(result.getRequestResults())) {
|
if (result != null && CollectionUtils.isNotEmpty(result.getRequestResults())) {
|
||||||
result.getRequestResults().forEach(item -> {
|
result.getRequestResults().forEach(item -> {
|
||||||
|
String itemScenarioName = "";
|
||||||
if (StringUtils.isNotEmpty(item.getScenario())) {
|
if (StringUtils.isNotEmpty(item.getScenario())) {
|
||||||
List<String> id_names = JSON.parseObject(item.getScenario(), List.class);
|
List<String> all_id_names = JSON.parseObject(item.getScenario(), List.class);
|
||||||
this.setStatus(id_names, item.getError() > 0);
|
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) {
|
if (StringUtils.isNotEmpty(item.getName()) && item.getName().indexOf(SEPARATOR) != -1) {
|
||||||
String array[] = item.getName().split(SEPARATOR);
|
String array[] = item.getName().split(SEPARATOR);
|
||||||
|
@ -102,17 +129,38 @@ public class TestResult {
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
this.setStepStatus(item.getName()+itemScenarioName,item.getError()>0);
|
||||||
});
|
});
|
||||||
scenarios.add(result);
|
scenarios.add(result);
|
||||||
}
|
}
|
||||||
for (String key : margeScenariMap.keySet()) {
|
/**
|
||||||
if (margeScenariMap.get(key)) {
|
* 1.10.2 场景成功/失败统计,不再按照请求为纬度,按照场景为纬度,
|
||||||
this.scenarioError++;
|
*/
|
||||||
|
for (String key : scenarioStepMap.keySet()) {
|
||||||
|
if (scenarioStepMap .get(key)) {
|
||||||
|
this.scenarioStepError++;
|
||||||
} else {
|
} 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());
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -411,6 +411,9 @@ public class ApiScenarioReportService {
|
||||||
testResult.setScenarioSuccess(testResult.getScenarioSuccess() + scenarioResult.getScenarioSuccess());
|
testResult.setScenarioSuccess(testResult.getScenarioSuccess() + scenarioResult.getScenarioSuccess());
|
||||||
testResult.setScenarioError(testResult.getScenarioError() + scenarioResult.getScenarioError());
|
testResult.setScenarioError(testResult.getScenarioError() + scenarioResult.getScenarioError());
|
||||||
testResult.setConsole(scenarioResult.getConsole());
|
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) {
|
} catch (Exception e) {
|
||||||
LogUtil.error(e.getMessage());
|
LogUtil.error(e.getMessage());
|
||||||
}
|
}
|
||||||
|
|
|
@ -2,7 +2,20 @@
|
||||||
<header class="report-header">
|
<header class="report-header">
|
||||||
<el-row>
|
<el-row>
|
||||||
<el-col>
|
<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>
|
<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">
|
<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>
|
<script>
|
||||||
|
|
||||||
|
import {getUUID} from "@/common/js/utils";
|
||||||
|
|
||||||
export default {
|
export default {
|
||||||
name: "MsApiReportViewHeader",
|
name: "MsApiReportViewHeader",
|
||||||
props: {
|
props: {
|
||||||
|
@ -30,14 +45,28 @@
|
||||||
path() {
|
path() {
|
||||||
return "/api/test/edit?id=" + this.report.testId;
|
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() {
|
data() {
|
||||||
return {
|
return {
|
||||||
isReadOnly: false,
|
isReadOnly: false,
|
||||||
|
nameIsEdit:false,
|
||||||
}
|
}
|
||||||
},
|
|
||||||
created() {
|
|
||||||
|
|
||||||
},
|
},
|
||||||
methods: {
|
methods: {
|
||||||
handleExport(name) {
|
handleExport(name) {
|
||||||
|
@ -45,7 +74,14 @@
|
||||||
},
|
},
|
||||||
handleSave(name) {
|
handleSave(name) {
|
||||||
this.$emit('reportSave', 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>
|
</script>
|
||||||
|
@ -55,5 +91,13 @@
|
||||||
.export-button {
|
.export-button {
|
||||||
float: right;
|
float: right;
|
||||||
}
|
}
|
||||||
|
.scenario-name {
|
||||||
|
overflow: hidden;
|
||||||
|
text-overflow: ellipsis;
|
||||||
|
white-space: nowrap;
|
||||||
|
font-size: 13px;
|
||||||
|
width: 100%;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
</style>
|
</style>
|
||||||
|
|
|
@ -38,23 +38,44 @@
|
||||||
<div style="width: 50%">
|
<div style="width: 50%">
|
||||||
<el-row type="flex" justify="center" align="middle">
|
<el-row type="flex" justify="center" align="middle">
|
||||||
<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="value">{{ content.scenarioTotal ? content.scenarioTotal : 0}}</div>
|
||||||
<div class="name">{{ $t('api_test.scenario.scenario') }}</div>
|
<div class="name">{{ $t('api_test.scenario.scenario') }}</div>
|
||||||
</div>
|
</div>
|
||||||
<i class="circle success"/>
|
<i class="circle success" style="margin-left: 20px;margin-right: 20px"/>
|
||||||
<div class="metric-box">
|
<div class="metric-box">
|
||||||
<div class="value">{{ content.scenarioSuccess ? content.scenarioSuccess: 0 }}</div>
|
<div class="value">{{ content.scenarioSuccess ? content.scenarioSuccess: 0 }}</div>
|
||||||
<div class="name">{{ $t('api_report.success') }}</div>
|
<div class="name">{{ $t('api_report.success') }}</div>
|
||||||
</div>
|
</div>
|
||||||
<div style="width: 40px"></div>
|
<!-- <div style="width: 40px"></div>-->
|
||||||
<i class="circle fail"/>
|
<i class="circle fail" style="margin-left: 20px;margin-right: 20px"/>
|
||||||
<div class="metric-box">
|
<div class="metric-box">
|
||||||
<div class="value">{{ content.scenarioError ? content.scenarioError : 0 }}</div>
|
<div class="value">{{ content.scenarioError ? content.scenarioError : 0 }}</div>
|
||||||
<div class="name">{{ $t('api_report.fail') }}</div>
|
<div class="name">{{ $t('api_report.fail') }}</div>
|
||||||
</div>
|
</div>
|
||||||
</el-row>
|
</el-row>
|
||||||
</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>
|
||||||
<div class="split"></div>
|
<div class="split"></div>
|
||||||
|
|
||||||
|
|
|
@ -317,6 +317,7 @@ export default {
|
||||||
},
|
},
|
||||||
data() {
|
data() {
|
||||||
return {
|
return {
|
||||||
|
showConfigButtonWithOutPermission:false,
|
||||||
onSampleError: false,
|
onSampleError: false,
|
||||||
props: {
|
props: {
|
||||||
label: "label",
|
label: "label",
|
||||||
|
|
Loading…
Reference in New Issue