feat(接口自动化 ): 报告优化-增加场景步骤统计

This commit is contained in:
fit2-zhao 2021-05-06 17:35:38 +08:00 committed by fit2-zhao
parent 9dced1f356
commit 81bd6de3fd
21 changed files with 368 additions and 208 deletions

View File

@ -26,6 +26,7 @@ import io.metersphere.api.dto.scenario.KeyValue;
import io.metersphere.api.dto.scenario.environment.EnvironmentConfig;
import io.metersphere.api.service.ApiTestEnvironmentService;
import io.metersphere.base.domain.ApiTestEnvironmentWithBLOBs;
import io.metersphere.commons.constants.DelimiterConstants;
import io.metersphere.commons.constants.LoopConstants;
import io.metersphere.commons.constants.MsTestElementConstants;
import io.metersphere.commons.exception.MSException;
@ -206,7 +207,7 @@ public abstract class MsTestElement {
}
csvDataSet.setIgnoreFirstLine(false);
// csvDataSet.setProperty("quotedData",true);
csvDataSet.setProperty("shareMode","shareMode.group");
csvDataSet.setProperty("shareMode", "shareMode.group");
csvDataSet.setProperty("recycle", true);
csvDataSet.setProperty("delimiter", item.getDelimiter());
csvDataSet.setComment(StringUtils.isEmpty(item.getDescription()) ? "" : item.getDescription());
@ -259,12 +260,22 @@ public abstract class MsTestElement {
}
}
public void getFullPath(MsTestElement element, StringBuilder path) {
public String getFullPath(MsTestElement element, String path) {
if (element.getParent() == null) {
return path;
}
path = StringUtils.isEmpty(element.getName()) ? element.getType() : element.getName() + DelimiterConstants.STEP_DELIMITER.toString() + path;
return getFullPath(element.getParent(), path);
}
public void getScenarioSet(MsTestElement element, List<String> id_names) {
if (StringUtils.equals(element.getType(), "scenario")) {
id_names.add(element.getResourceId() + "_" + element.getName());
}
if (element.getParent() == null) {
return;
}
path.append(StringUtils.isEmpty(element.getName()) ? element.getType() : element.getName()).append("^@~@^");
getFullPath(element.getParent(), path);
getScenarioSet(element.getParent(), id_names);
}
protected String getParentName(MsTestElement parent) {
@ -282,9 +293,8 @@ public abstract class MsTestElement {
}
}
// 获取全路径以备后面使用
StringBuilder fullPath = new StringBuilder();
getFullPath(parent, fullPath);
return fullPath + "<->" + parent.getName();
String fullPath = getFullPath(parent, new String());
return fullPath + DelimiterConstants.SEPARATOR.toString() + parent.getName();
}
return "";
}

View File

@ -1,9 +1,11 @@
package io.metersphere.api.dto.definition.request.processors;
import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.annotation.JSONField;
import com.alibaba.fastjson.annotation.JSONType;
import io.metersphere.api.dto.definition.request.MsTestElement;
import io.metersphere.api.dto.definition.request.ParameterConfig;
import io.metersphere.commons.constants.DelimiterConstants;
import lombok.Data;
import lombok.EqualsAndHashCode;
import org.apache.commons.collections.CollectionUtils;
@ -13,6 +15,7 @@ import org.apache.jmeter.save.SaveService;
import org.apache.jmeter.testelement.TestElement;
import org.apache.jorphan.collections.HashTree;
import java.util.LinkedList;
import java.util.List;
@Data
@ -42,9 +45,12 @@ public class MsJSR223Processor extends MsTestElement {
}
String name = this.getParentName(this.getParent());
if (StringUtils.isNotEmpty(name) && !config.isOperating()) {
processor.setName(this.getName() + "<->" + name);
processor.setName(this.getName() + DelimiterConstants.SEPARATOR.toString() + name);
}
processor.setProperty("MS-ID", this.getId());
List<String> id_names = new LinkedList<>();
this.getScenarioSet(this, id_names);
processor.setProperty("MS-SCENARIO", JSON.toJSONString(id_names));
processor.setProperty(TestElement.TEST_CLASS, JSR223Sampler.class.getName());
processor.setProperty(TestElement.GUI_CLASS, SaveService.aliasToClass("TestBeanGUI"));

View File

@ -1,5 +1,6 @@
package io.metersphere.api.dto.definition.request.sampler;
import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.annotation.JSONField;
import com.alibaba.fastjson.annotation.JSONType;
import com.fasterxml.jackson.annotation.JsonProperty;
@ -19,6 +20,7 @@ import io.metersphere.api.service.ApiDefinitionService;
import io.metersphere.api.service.ApiTestCaseService;
import io.metersphere.base.domain.ApiDefinitionWithBLOBs;
import io.metersphere.base.domain.ApiTestCaseWithBLOBs;
import io.metersphere.commons.constants.DelimiterConstants;
import io.metersphere.commons.constants.MsTestElementConstants;
import io.metersphere.commons.utils.CommonBeanFactory;
import io.metersphere.commons.utils.LogUtil;
@ -31,6 +33,7 @@ import org.apache.jmeter.save.SaveService;
import org.apache.jmeter.testelement.TestElement;
import org.apache.jorphan.collections.HashTree;
import java.util.LinkedList;
import java.util.List;
import java.util.stream.Collectors;
@ -133,11 +136,14 @@ public class MsDubboSampler extends MsTestElement {
sampler.setName(this.getName());
String name = this.getParentName(this.getParent());
if (StringUtils.isNotEmpty(name) && !config.isOperating()) {
sampler.setName(this.getName() + "<->" + name);
sampler.setName(this.getName() + DelimiterConstants.SEPARATOR.toString() + name);
}
sampler.setProperty(TestElement.TEST_CLASS, DubboSample.class.getName());
sampler.setProperty(TestElement.GUI_CLASS, SaveService.aliasToClass("DubboSampleGui"));
sampler.setProperty("MS-ID", this.getId());
List<String> id_names = new LinkedList<>();
this.getScenarioSet(this, id_names);
sampler.setProperty("MS-SCENARIO", JSON.toJSONString(id_names));
sampler.addTestElement(configCenter(this.getConfigCenter()));
sampler.addTestElement(registryCenter(this.getRegistryCenter()));

View File

@ -1,5 +1,6 @@
package io.metersphere.api.dto.definition.request.sampler;
import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.annotation.JSONField;
import com.alibaba.fastjson.annotation.JSONType;
import com.fasterxml.jackson.core.type.TypeReference;
@ -20,6 +21,7 @@ import io.metersphere.base.domain.ApiDefinitionWithBLOBs;
import io.metersphere.base.domain.ApiTestCaseWithBLOBs;
import io.metersphere.base.domain.TestPlanApiCase;
import io.metersphere.commons.constants.ConditionType;
import io.metersphere.commons.constants.DelimiterConstants;
import io.metersphere.commons.constants.MsTestElementConstants;
import io.metersphere.commons.exception.MSException;
import io.metersphere.commons.utils.CommonBeanFactory;
@ -42,10 +44,7 @@ import org.apache.jorphan.collections.HashTree;
import java.net.URL;
import java.net.URLDecoder;
import java.util.HashMap;
import java.util.Iterator;
import java.util.List;
import java.util.Map;
import java.util.*;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
@ -163,11 +162,15 @@ public class MsHTTPSamplerProxy extends MsTestElement {
}
String name = this.getParentName(this.getParent());
if (StringUtils.isNotEmpty(name) && !config.isOperating()) {
sampler.setName(this.getName() + "<->" + name);
sampler.setName(this.getName() + DelimiterConstants.SEPARATOR.toString() + name);
}
sampler.setProperty(TestElement.TEST_CLASS, HTTPSamplerProxy.class.getName());
sampler.setProperty(TestElement.GUI_CLASS, SaveService.aliasToClass("HttpTestSampleGui"));
sampler.setProperty("MS-ID", this.getId());
List<String> id_names = new LinkedList<>();
this.getScenarioSet(this, id_names);
sampler.setProperty("MS-SCENARIO", JSON.toJSONString(id_names));
sampler.setMethod(this.getMethod());
sampler.setContentEncoding("UTF-8");
sampler.setConnectTimeout(this.getConnectTimeout() == null ? "6000" : this.getConnectTimeout());

View File

@ -1,5 +1,6 @@
package io.metersphere.api.dto.definition.request.sampler;
import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;
import com.alibaba.fastjson.annotation.JSONField;
import com.alibaba.fastjson.annotation.JSONType;
@ -17,6 +18,7 @@ import io.metersphere.api.service.ApiTestEnvironmentService;
import io.metersphere.base.domain.ApiDefinitionWithBLOBs;
import io.metersphere.base.domain.ApiTestCaseWithBLOBs;
import io.metersphere.base.domain.ApiTestEnvironmentWithBLOBs;
import io.metersphere.commons.constants.DelimiterConstants;
import io.metersphere.commons.constants.MsTestElementConstants;
import io.metersphere.commons.exception.MSException;
import io.metersphere.commons.utils.CommonBeanFactory;
@ -33,6 +35,7 @@ import org.apache.jmeter.testelement.TestElement;
import org.apache.jorphan.collections.HashTree;
import java.util.Iterator;
import java.util.LinkedList;
import java.util.List;
import java.util.stream.Collectors;
@ -231,11 +234,14 @@ public class MsJDBCSampler extends MsTestElement {
sampler.setName(this.getName());
String name = this.getParentName(this.getParent());
if (StringUtils.isNotEmpty(name) && !config.isOperating()) {
sampler.setName(this.getName() + "<->" + name);
sampler.setName(this.getName() + DelimiterConstants.SEPARATOR.toString() + name);
}
sampler.setProperty(TestElement.TEST_CLASS, JDBCSampler.class.getName());
sampler.setProperty(TestElement.GUI_CLASS, SaveService.aliasToClass("TestBeanGUI"));
sampler.setProperty("MS-ID", this.getId());
List<String> id_names = new LinkedList<>();
this.getScenarioSet(this, id_names);
sampler.setProperty("MS-SCENARIO", JSON.toJSONString(id_names));
// request.getDataSource() 是ID需要转换为Name
sampler.setProperty("dataSource", this.dataSource.getName());

View File

@ -1,5 +1,6 @@
package io.metersphere.api.dto.definition.request.sampler;
import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.annotation.JSONField;
import com.alibaba.fastjson.annotation.JSONType;
import com.fasterxml.jackson.core.type.TypeReference;
@ -15,6 +16,7 @@ import io.metersphere.api.service.ApiDefinitionService;
import io.metersphere.api.service.ApiTestCaseService;
import io.metersphere.base.domain.ApiDefinitionWithBLOBs;
import io.metersphere.base.domain.ApiTestCaseWithBLOBs;
import io.metersphere.commons.constants.DelimiterConstants;
import io.metersphere.commons.constants.MsTestElementConstants;
import io.metersphere.commons.utils.CommonBeanFactory;
import io.metersphere.commons.utils.LogUtil;
@ -34,6 +36,7 @@ import org.apache.jorphan.collections.HashTree;
import org.apache.jorphan.collections.ListedHashTree;
import java.util.ArrayList;
import java.util.LinkedList;
import java.util.List;
import java.util.Random;
@ -174,9 +177,12 @@ public class MsTCPSampler extends MsTestElement {
tcpSampler.setName(this.getName());
String name = this.getParentName(this.getParent());
if (StringUtils.isNotEmpty(name) && !config.isOperating()) {
tcpSampler.setName(this.getName() + "<->" + name);
tcpSampler.setName(this.getName() + DelimiterConstants.SEPARATOR.toString() + name);
}
tcpSampler.setProperty("MS-ID", this.getId());
List<String> id_names = new LinkedList<>();
this.getScenarioSet(this, id_names);
tcpSampler.setProperty("MS-SCENARIO", JSON.toJSONString(id_names));
tcpSampler.setProperty(TestElement.TEST_CLASS, TCPSampler.class.getName());
tcpSampler.setProperty(TestElement.GUI_CLASS, SaveService.aliasToClass("TCPSamplerGui"));

View File

@ -420,6 +420,7 @@ public class APIBackendListenerClient extends AbstractBackendListenerClient impl
requestResult.setTotalAssertions(result.getAssertionResults().length);
requestResult.setSuccess(result.isSuccessful());
requestResult.setError(result.getErrorCount());
requestResult.setScenario(result.getScenario());
if (result instanceof HTTPSampleResult) {
HTTPSampleResult res = (HTTPSampleResult) result;
requestResult.setCookies(res.getCookies());

View File

@ -8,6 +8,7 @@ import io.metersphere.api.dto.scenario.request.BodyFile;
import io.metersphere.base.domain.JarConfig;
import io.metersphere.base.domain.TestResource;
import io.metersphere.commons.constants.ApiRunMode;
import io.metersphere.commons.constants.RunModeConstants;
import io.metersphere.commons.exception.MSException;
import io.metersphere.commons.utils.*;
import io.metersphere.config.JmeterProperties;
@ -122,7 +123,7 @@ public class JMeterService {
BackendListener backendListener = new BackendListener();
backendListener.setName(testId);
Arguments arguments = new Arguments();
if (config != null && config.getMode().equals("serial") && config.getReportType().equals("setReport")) {
if (config != null && config.getMode().equals(RunModeConstants.SERIAL.toString()) && config.getReportType().equals(RunModeConstants.SET_REPORT.toString())) {
arguments.addArgument(APIBackendListenerClient.TEST_REPORT_ID, config.getReportId());
}

View File

@ -16,6 +16,8 @@ public class RequestResult {
private String method;
private String scenario;
private long requestSize;
private long startTime;

View File

@ -1,11 +1,15 @@
package io.metersphere.api.jmeter;
import com.alibaba.fastjson.JSON;
import io.metersphere.commons.constants.DelimiterConstants;
import lombok.Data;
import org.apache.commons.collections.CollectionUtils;
import org.apache.commons.lang3.StringUtils;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
@Data
public class TestResult {
@ -14,6 +18,12 @@ public class TestResult {
private String setReportId;
private int scenarioTotal;
private int scenarioSuccess;
private int scenarioError;
private String userId;
private boolean isDebug;
@ -32,6 +42,8 @@ public class TestResult {
private List<ScenarioResult> scenarios = new ArrayList<>();
private Map<String, Boolean> margeScenariMap = new HashMap<>();
public void addError(int count) {
this.error += count;
}
@ -48,11 +60,25 @@ public class TestResult {
this.passAssertions += count;
}
private static final String SEPARATOR = "<->";
private static final String SEPARATOR = DelimiterConstants.SEPARATOR.toString();
private void setStatus(List<String> id_names, boolean status) {
if (CollectionUtils.isNotEmpty(id_names)) {
id_names.forEach(item -> {
if (!margeScenariMap.containsKey(item) || status) {
margeScenariMap.put(item, status);
}
});
}
}
public void addScenario(ScenarioResult result) {
if (result != null && CollectionUtils.isNotEmpty(result.getRequestResults())) {
result.getRequestResults().forEach(item -> {
if (StringUtils.isNotEmpty(item.getScenario())) {
List<String> id_names = JSON.parseObject(item.getScenario(), List.class);
this.setStatus(id_names, item.getError() > 0);
}
if (StringUtils.isNotEmpty(item.getName()) && item.getName().indexOf(SEPARATOR) != -1) {
String array[] = item.getName().split(SEPARATOR);
item.setName(array[1] + array[0]);
@ -63,5 +89,13 @@ public class TestResult {
});
scenarios.add(result);
}
for (String key : margeScenariMap.keySet()) {
if (margeScenariMap.get(key)) {
this.scenarioError++;
} else {
this.scenarioSuccess++;
}
}
this.setScenarioTotal(this.margeScenariMap.size());
}
}

View File

@ -597,7 +597,7 @@ public class ApiAutomationService {
}
report.setUpdateTime(System.currentTimeMillis());
report.setCreateTime(System.currentTimeMillis());
if (config != null && config.getMode().equals("serial")) {
if (config != null && config.getMode().equals(RunModeConstants.SERIAL.toString())) {
report.setCreateTime(System.currentTimeMillis() + 2000);
report.setUpdateTime(System.currentTimeMillis() + 2000);
}
@ -751,8 +751,8 @@ public class ApiAutomationService {
// 环境检查
this.checkEnv(request, apiScenarios);
if (request.getConfig() != null && request.getConfig().getMode().equals("serial")) {
if (StringUtils.isNotEmpty(request.getConfig().getReportName())) {
if (request.getConfig() != null && request.getConfig().getMode().equals(RunModeConstants.SERIAL.toString())) {
if (StringUtils.equals(request.getConfig().getReportType(), RunModeConstants.SET_REPORT.toString()) && StringUtils.isNotEmpty(request.getConfig().getReportName())) {
request.setExecuteType(ExecuteType.Completed.name());
}
}
@ -806,7 +806,7 @@ public class ApiAutomationService {
// 生成集成报告
String serialReportId = null;
if (request.getConfig() != null && request.getConfig().getMode().equals("serial") && StringUtils.equals(request.getConfig().getReportType(), "setReport") && StringUtils.isNotEmpty(request.getConfig().getReportName())) {
if (request.getConfig() != null && request.getConfig().getMode().equals(RunModeConstants.SERIAL.toString()) && StringUtils.equals(request.getConfig().getReportType(), RunModeConstants.SET_REPORT.toString()) && StringUtils.isNotEmpty(request.getConfig().getReportName())) {
request.getConfig().setReportId(UUID.randomUUID().toString());
APIScenarioReportResult report = createScenarioReport(request.getConfig().getReportId(), JSON.toJSONString(scenarioIds), scenarioNames.deleteCharAt(scenarioNames.toString().length() - 1).toString(), ReportTriggerMode.MANUAL.name(),
ExecuteType.Saved.name(), request.getProjectId(), request.getReportUserID(), request.getConfig());
@ -823,7 +823,7 @@ public class ApiAutomationService {
private void run(Map<APIScenarioReportResult, HashTree> map, RunScenarioRequest request, String serialReportId) {
// 开始选择执行模式
ExecutorService executorService = Executors.newFixedThreadPool(map.size());
if (request.getConfig() != null && request.getConfig().getMode().equals("serial")) {
if (request.getConfig() != null && request.getConfig().getMode().equals(RunModeConstants.SERIAL.toString())) {
// 开始串行执行
Thread thread = new Thread(new Runnable() {
@Override
@ -1057,7 +1057,7 @@ public class ApiAutomationService {
public String run(RunScenarioRequest request) {
if (request.getConfig() != null) {
if (request.getConfig().getMode().equals("parallel")) {
if (request.getConfig().getMode().equals(RunModeConstants.PARALLEL.toString())) {
// 校验并发数量
int count = 50;
BaseSystemConfigDTO dto = systemParameterService.getBaseInfo();

View File

@ -3,11 +3,15 @@ package io.metersphere.api.service;
import com.alibaba.fastjson.JSON;
import io.metersphere.api.dto.datacount.ExecutedCaseInfoResult;
import io.metersphere.api.jmeter.TestResult;
import io.metersphere.base.domain.*;
import io.metersphere.base.domain.ApiDefinitionExecResult;
import io.metersphere.base.domain.ApiDefinitionExecResultExample;
import io.metersphere.base.domain.ApiTestCaseWithBLOBs;
import io.metersphere.base.domain.TestPlanApiCase;
import io.metersphere.base.mapper.ApiDefinitionExecResultMapper;
import io.metersphere.base.mapper.ApiTestCaseMapper;
import io.metersphere.base.mapper.ext.ExtApiDefinitionExecResultMapper;
import io.metersphere.commons.constants.ApiRunMode;
import io.metersphere.commons.constants.DelimiterConstants;
import io.metersphere.commons.utils.DateUtils;
import io.metersphere.commons.utils.SessionUtils;
import io.metersphere.track.dto.TestPlanDTO;
@ -61,8 +65,8 @@ public class ApiDefinitionExecResultService {
saveResult.setCreateTime(item.getStartTime());
saveResult.setUserId(result.getUserId());
saveResult.setName(item.getName());
if (item.getName().indexOf("<->") != -1) {
saveResult.setName(item.getName().substring(0, item.getName().indexOf("<->")));
if (item.getName().indexOf(DelimiterConstants.SEPARATOR.toString()) != -1) {
saveResult.setName(item.getName().substring(0, item.getName().indexOf(DelimiterConstants.SEPARATOR.toString())));
}
saveResult.setResourceId(item.getName());
saveResult.setContent(JSON.toJSONString(item));

View File

@ -583,8 +583,8 @@ public class ApiDefinitionService {
public void addResult(TestResult res) {
if (res != null && CollectionUtils.isNotEmpty(res.getScenarios()) && res.getScenarios().get(0) != null && CollectionUtils.isNotEmpty(res.getScenarios().get(0).getRequestResults())) {
RequestResult result = res.getScenarios().get(0).getRequestResults().get(0);
if (result.getName().indexOf("<->") != -1) {
result.setName(result.getName().substring(0, result.getName().indexOf("<->")));
if (result.getName().indexOf(DelimiterConstants.SEPARATOR.toString()) != -1) {
result.setName(result.getName().substring(0, result.getName().indexOf(DelimiterConstants.SEPARATOR.toString())));
}
cache.put(res.getTestId(), result);
} else {

View File

@ -396,6 +396,9 @@ public class ApiScenarioReportService {
testResult.setPassAssertions(testResult.getPassAssertions() + scenarioResult.getPassAssertions());
testResult.setSuccess(testResult.getSuccess() + scenarioResult.getSuccess());
testResult.setTotalAssertions(scenarioResult.getTotalAssertions() + testResult.getTotalAssertions());
testResult.setScenarioTotal(testResult.getScenarioTotal() + scenarioResult.getScenarioTotal());
testResult.setScenarioSuccess(testResult.getScenarioSuccess() + scenarioResult.getScenarioSuccess());
testResult.setScenarioError(testResult.getScenarioError() + scenarioResult.getScenarioError());
} catch (Exception e) {
LogUtil.error(e.getMessage());
}

View File

@ -45,6 +45,11 @@ public class SerialScenarioExecTask<T> implements Callable<T> {
break;
}
}
// 执行失败了恢复报告状态
if (index == 200 && report != null && report.getStatus().equals(APITestStatus.Running.name())) {
report.setStatus(APITestStatus.Error.name());
apiScenarioReportMapper.updateByPrimaryKey(report);
}
return (T) report;
} catch (Exception ex) {
LogUtil.error(ex.getMessage());

View File

@ -0,0 +1,15 @@
package io.metersphere.commons.constants;
public enum DelimiterConstants {
STEP_DELIMITER("^@~@^"), SEPARATOR("<->");
private String value;
DelimiterConstants(String value) {
this.value = value;
}
@Override
public String toString() {
return this.value;
}
}

View File

@ -0,0 +1,17 @@
package io.metersphere.commons.constants;
public enum RunModeConstants {
SERIAL("serial"), SET_REPORT("setReport"), PARALLEL("parallel");
private String value;
RunModeConstants(String value) {
this.value = value;
}
@Override
public String toString() {
return this.value;
}
}

View File

@ -6,6 +6,7 @@ import io.metersphere.base.mapper.LoadTestReportMapper;
import io.metersphere.base.mapper.TestPlanLoadCaseMapper;
import io.metersphere.base.mapper.TestPlanMapper;
import io.metersphere.base.mapper.ext.ExtTestPlanLoadCaseMapper;
import io.metersphere.commons.constants.RunModeConstants;
import io.metersphere.commons.constants.TestPlanStatus;
import io.metersphere.commons.exception.MSException;
import io.metersphere.controller.request.OrderRequest;
@ -129,7 +130,7 @@ public class TestPlanLoadCaseService {
}
public void runBatch(RunBatchTestPlanRequest request) {
if (request.getConfig() != null && request.getConfig().getMode().equals("serial")) {
if (request.getConfig() != null && request.getConfig().getMode().equals(RunModeConstants.SERIAL.toString())) {
try {
serialRun(request);
} catch (Exception e) {

View File

@ -23,7 +23,6 @@ import org.apache.jmeter.gui.Searchable;
import org.apache.jmeter.testelement.TestPlan;
import org.apache.jmeter.threads.JMeterContext.TestLogicalAction;
import org.apache.jmeter.threads.JMeterContextService;
import org.apache.jmeter.threads.JMeterVariables;
import org.apache.jmeter.util.JMeterUtils;
import org.apache.jorphan.util.JOrphanUtils;
import org.slf4j.Logger;
@ -164,12 +163,25 @@ public class SampleResult implements Serializable, Cloneable, Searchable {
}
}
/**
* 定制自定义添加 =================
*/
private String samplerId;
public String getSamplerId() {
return this.samplerId;
}
// 数据格式 List<id_name> 多层父级按照同级统计
private String scenario;
public String getScenario() {
return this.scenario;
}
/**
* 定制自定义添加 =================
*/
private SampleSaveConfiguration saveConfig;
private SampleResult parent;
@ -336,6 +348,7 @@ public class SampleResult implements Serializable, Cloneable, Searchable {
Sampler sampler = JMeterContextService.getContext().getCurrentSampler();
if (sampler != null) {
this.samplerId = sampler.getPropertyAsString("MS-ID");
this.scenario = sampler.getPropertyAsString("MS-SCENARIO");
}
}

View File

@ -26,6 +26,30 @@
</el-row>
</div>
<div class="split"></div>
<!-- 场景统计 -->
<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="value">{{ content.scenarioTotal ? content.scenarioTotal : 0}}</div>
<div class="name">{{ $t('api_test.scenario.scenario') }}</div>
</div>
<i class="circle success"/>
<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 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>
</div>
<div class="split"></div>
<div style="width: 50%">
<el-row type="flex" justify="space-around" align="middle">
<div class="metric-icon-box">
@ -50,206 +74,209 @@
</template>
<script>
import MsChart from "@/business/components/common/chart/MsChart";
import MsChart from "@/business/components/common/chart/MsChart";
export default {
name: "MsMetricChart",
components: {MsChart},
props: {
content: Object,
totalTime: Number
},
data() {
return {
hour: 0,
minutes: 0,
seconds: 0,
time: 0,
}
},
created() {
this.initTime()
},
methods: {
initTime() {
this.time = this.totalTime
this.seconds = Math.floor(this.time / 1000)
if (this.seconds >= 1) {
if (this.seconds > 60) {
this.minutes = Math.round(this.time / 60)
this.seconds = Math.round(this.time % 60)
this.time = this.minutes + "min" + this.seconds + "s"
}
if (this.seconds > 60) {
this.minutes = Math.round(this.time / 60)
this.seconds = Math.round(this.time % 60)
this.time = this.minutes + "min" + this.seconds + "s"
}
if (this.minutes > 60) {
this.hour = Math.round(this.minutes / 60)
this.minutes = Math.round(this.minutes % 60)
this.time = this.hour + "hour" + this.minutes + "min" + this.seconds + "s"
}
this.time = (this.seconds) + "s"
} else {
this.time = this.totalTime + "ms"
export default {
name: "MsMetricChart",
components: {MsChart},
props: {
content: Object,
totalTime: Number
},
data() {
return {
hour: 0,
minutes: 0,
seconds: 0,
time: 0,
scenarioTotal: 0,
scenarioSuccess: 0,
scenarioError: 0,
}
},
},
computed: {
options() {
return {
color: ['#67C23A', '#F56C6C'],
tooltip: {
trigger: 'item',
formatter: '{b}: {c} ({d}%)'
},
title: [{
text: this.content.total,
subtext: this.$t('api_report.request'),
top: 'center',
left: 'center',
textStyle: {
rich: {
align: 'center',
value: {
fontSize: 32,
fontWeight: 'bold',
padding: [10, 0]
},
name: {
fontSize: 14,
fontWeight: 'normal',
color: '#7F7F7F',
created() {
this.initTime()
},
methods: {
initTime() {
this.time = this.totalTime
this.seconds = Math.floor(this.time / 1000)
if (this.seconds >= 1) {
if (this.seconds > 60) {
this.minutes = Math.round(this.time / 60)
this.seconds = Math.round(this.time % 60)
this.time = this.minutes + "min" + this.seconds + "s"
}
if (this.seconds > 60) {
this.minutes = Math.round(this.time / 60)
this.seconds = Math.round(this.time % 60)
this.time = this.minutes + "min" + this.seconds + "s"
}
if (this.minutes > 60) {
this.hour = Math.round(this.minutes / 60)
this.minutes = Math.round(this.minutes % 60)
this.time = this.hour + "hour" + this.minutes + "min" + this.seconds + "s"
}
this.time = (this.seconds) + "s"
} else {
this.time = this.totalTime + "ms"
}
},
},
computed: {
options() {
return {
color: ['#67C23A', '#F56C6C'],
tooltip: {
trigger: 'item',
formatter: '{b}: {c} ({d}%)'
},
title: [{
text: this.content.total,
subtext: this.$t('api_report.request'),
top: 'center',
left: 'center',
textStyle: {
rich: {
align: 'center',
value: {
fontSize: 32,
fontWeight: 'bold',
padding: [10, 0]
},
name: {
fontSize: 14,
fontWeight: 'normal',
color: '#7F7F7F',
}
}
}
}
}],
series: [
{
type: 'pie',
radius: ['80%', '90%'],
avoidLabelOverlap: false,
hoverAnimation: false,
itemStyle: {
normal: {
borderColor: "#FFF",
shadowColor: '#E1E1E1',
shadowBlur: 10
}
},
labelLine: {
show: false
},
data: [
{value: this.content.success},
{value: this.content.error},
]
}
]
};
},
}],
series: [
{
type: 'pie',
radius: ['80%', '90%'],
avoidLabelOverlap: false,
hoverAnimation: false,
itemStyle: {
normal: {
borderColor: "#FFF",
shadowColor: '#E1E1E1',
shadowBlur: 10
}
},
labelLine: {
show: false
},
data: [
{value: this.content.success},
{value: this.content.error},
]
}
]
};
},
fail() {
return (this.content.error / this.content.total * 100).toFixed(0) + "%";
fail() {
return (this.content.error / this.content.total * 100).toFixed(0) + "%";
},
assertions() {
return this.content.passAssertions + " / " + this.content.totalAssertions;
}
},
assertions() {
return this.content.passAssertions + " / " + this.content.totalAssertions;
}
},
}
}
</script>
<style scoped>
.metric-container {
padding: 20px;
}
.metric-container {
padding: 20px;
}
.metric-container #chart {
width: 140px;
height: 140px;
margin-right: 40px;
}
.metric-container #chart {
width: 140px;
height: 140px;
margin-right: 40px;
}
.metric-container .split {
margin: 20px;
height: 100px;
border-left: 1px solid #D8DBE1;
}
.metric-container .split {
margin: 20px;
height: 100px;
border-left: 1px solid #D8DBE1;
}
.metric-container .circle {
width: 12px;
height: 12px;
border-radius: 50%;
box-shadow: 0 0 20px 1px rgba(200, 216, 226, .42);
display: inline-block;
margin-right: 10px;
vertical-align: middle;
}
.metric-container .circle {
width: 12px;
height: 12px;
border-radius: 50%;
box-shadow: 0 0 20px 1px rgba(200, 216, 226, .42);
display: inline-block;
margin-right: 10px;
vertical-align: middle;
}
.metric-container .circle.success {
background-color: #67C23A;
}
.metric-container .circle.success {
background-color: #67C23A;
}
.metric-container .circle.fail {
background-color: #F56C6C;
}
.metric-container .circle.fail {
background-color: #F56C6C;
}
.metric-box {
display: inline-block;
text-align: center;
}
.metric-box {
display: inline-block;
text-align: center;
}
.metric-box .value {
font-size: 32px;
font-weight: 600;
letter-spacing: -.5px;
}
.metric-box .value {
font-size: 32px;
font-weight: 600;
letter-spacing: -.5px;
}
.metric-time .value {
font-size: 25px;
font-weight: 400;
letter-spacing: -.5px;
}
.metric-time .value {
font-size: 25px;
font-weight: 400;
letter-spacing: -.5px;
}
.metric-box .name {
font-size: 16px;
letter-spacing: -.2px;
color: #404040;
}
.metric-box .name {
font-size: 16px;
letter-spacing: -.2px;
color: #404040;
}
.metric-icon-box {
text-align: center;
margin: 0 10px;
}
.metric-icon-box {
text-align: center;
margin: 0 10px;
}
.metric-icon-box .value {
font-size: 20px;
font-weight: 600;
letter-spacing: -.4px;
line-height: 28px;
vertical-align: middle;
}
.metric-icon-box .value {
font-size: 20px;
font-weight: 600;
letter-spacing: -.4px;
line-height: 28px;
vertical-align: middle;
}
.metric-icon-box .name {
font-size: 13px;
letter-spacing: 1px;
color: #BFBFBF;
line-height: 18px;
}
.metric-icon-box .name {
font-size: 13px;
letter-spacing: 1px;
color: #BFBFBF;
line-height: 18px;
}
.metric-icon-box .fail {
color: #F56C6C;
font-size: 40px;
}
.metric-icon-box .fail {
color: #F56C6C;
font-size: 40px;
}
.metric-icon-box .assertions {
font-size: 40px;
}
.metric-icon-box .assertions {
font-size: 40px;
}
.metric-icon-box .total {
font-size: 40px;
}
.metric-icon-box .total {
font-size: 40px;
}
</style>

View File

@ -994,7 +994,7 @@
},
getApiScenario() {
this.loading = true;
if (this.currentScenario.tags != undefined && !(this.currentScenario.tags instanceof Array)) {
if (this.currentScenario.tags != undefined && this.currentScenario.tags && !(this.currentScenario.tags instanceof Array)) {
this.currentScenario.tags = JSON.parse(this.currentScenario.tags);
}
if (!this.currentScenario.variables) {