feat(接口自动化 ): 报告优化-增加场景步骤统计
This commit is contained in:
parent
184fc9bb96
commit
51a331c757
|
@ -26,6 +26,7 @@ import io.metersphere.api.dto.scenario.KeyValue;
|
||||||
import io.metersphere.api.dto.scenario.environment.EnvironmentConfig;
|
import io.metersphere.api.dto.scenario.environment.EnvironmentConfig;
|
||||||
import io.metersphere.api.service.ApiTestEnvironmentService;
|
import io.metersphere.api.service.ApiTestEnvironmentService;
|
||||||
import io.metersphere.base.domain.ApiTestEnvironmentWithBLOBs;
|
import io.metersphere.base.domain.ApiTestEnvironmentWithBLOBs;
|
||||||
|
import io.metersphere.commons.constants.DelimiterConstants;
|
||||||
import io.metersphere.commons.constants.LoopConstants;
|
import io.metersphere.commons.constants.LoopConstants;
|
||||||
import io.metersphere.commons.constants.MsTestElementConstants;
|
import io.metersphere.commons.constants.MsTestElementConstants;
|
||||||
import io.metersphere.commons.exception.MSException;
|
import io.metersphere.commons.exception.MSException;
|
||||||
|
@ -206,7 +207,7 @@ public abstract class MsTestElement {
|
||||||
}
|
}
|
||||||
csvDataSet.setIgnoreFirstLine(false);
|
csvDataSet.setIgnoreFirstLine(false);
|
||||||
// csvDataSet.setProperty("quotedData",true);
|
// csvDataSet.setProperty("quotedData",true);
|
||||||
csvDataSet.setProperty("shareMode","shareMode.group");
|
csvDataSet.setProperty("shareMode", "shareMode.group");
|
||||||
csvDataSet.setProperty("recycle", true);
|
csvDataSet.setProperty("recycle", true);
|
||||||
csvDataSet.setProperty("delimiter", item.getDelimiter());
|
csvDataSet.setProperty("delimiter", item.getDelimiter());
|
||||||
csvDataSet.setComment(StringUtils.isEmpty(item.getDescription()) ? "" : item.getDescription());
|
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) {
|
if (element.getParent() == null) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
path.append(StringUtils.isEmpty(element.getName()) ? element.getType() : element.getName()).append("^@~@^");
|
getScenarioSet(element.getParent(), id_names);
|
||||||
getFullPath(element.getParent(), path);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
protected String getParentName(MsTestElement parent) {
|
protected String getParentName(MsTestElement parent) {
|
||||||
|
@ -282,9 +293,8 @@ public abstract class MsTestElement {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
// 获取全路径以备后面使用
|
// 获取全路径以备后面使用
|
||||||
StringBuilder fullPath = new StringBuilder();
|
String fullPath = getFullPath(parent, new String());
|
||||||
getFullPath(parent, fullPath);
|
return fullPath + DelimiterConstants.SEPARATOR.toString() + parent.getName();
|
||||||
return fullPath + "<->" + parent.getName();
|
|
||||||
}
|
}
|
||||||
return "";
|
return "";
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,9 +1,11 @@
|
||||||
package io.metersphere.api.dto.definition.request.processors;
|
package io.metersphere.api.dto.definition.request.processors;
|
||||||
|
|
||||||
|
import com.alibaba.fastjson.JSON;
|
||||||
import com.alibaba.fastjson.annotation.JSONField;
|
import com.alibaba.fastjson.annotation.JSONField;
|
||||||
import com.alibaba.fastjson.annotation.JSONType;
|
import com.alibaba.fastjson.annotation.JSONType;
|
||||||
import io.metersphere.api.dto.definition.request.MsTestElement;
|
import io.metersphere.api.dto.definition.request.MsTestElement;
|
||||||
import io.metersphere.api.dto.definition.request.ParameterConfig;
|
import io.metersphere.api.dto.definition.request.ParameterConfig;
|
||||||
|
import io.metersphere.commons.constants.DelimiterConstants;
|
||||||
import lombok.Data;
|
import lombok.Data;
|
||||||
import lombok.EqualsAndHashCode;
|
import lombok.EqualsAndHashCode;
|
||||||
import org.apache.commons.collections.CollectionUtils;
|
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.jmeter.testelement.TestElement;
|
||||||
import org.apache.jorphan.collections.HashTree;
|
import org.apache.jorphan.collections.HashTree;
|
||||||
|
|
||||||
|
import java.util.LinkedList;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
@Data
|
@Data
|
||||||
|
@ -42,9 +45,12 @@ public class MsJSR223Processor extends MsTestElement {
|
||||||
}
|
}
|
||||||
String name = this.getParentName(this.getParent());
|
String name = this.getParentName(this.getParent());
|
||||||
if (StringUtils.isNotEmpty(name) && !config.isOperating()) {
|
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());
|
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.TEST_CLASS, JSR223Sampler.class.getName());
|
||||||
processor.setProperty(TestElement.GUI_CLASS, SaveService.aliasToClass("TestBeanGUI"));
|
processor.setProperty(TestElement.GUI_CLASS, SaveService.aliasToClass("TestBeanGUI"));
|
||||||
|
|
|
@ -1,5 +1,6 @@
|
||||||
package io.metersphere.api.dto.definition.request.sampler;
|
package io.metersphere.api.dto.definition.request.sampler;
|
||||||
|
|
||||||
|
import com.alibaba.fastjson.JSON;
|
||||||
import com.alibaba.fastjson.annotation.JSONField;
|
import com.alibaba.fastjson.annotation.JSONField;
|
||||||
import com.alibaba.fastjson.annotation.JSONType;
|
import com.alibaba.fastjson.annotation.JSONType;
|
||||||
import com.fasterxml.jackson.annotation.JsonProperty;
|
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.api.service.ApiTestCaseService;
|
||||||
import io.metersphere.base.domain.ApiDefinitionWithBLOBs;
|
import io.metersphere.base.domain.ApiDefinitionWithBLOBs;
|
||||||
import io.metersphere.base.domain.ApiTestCaseWithBLOBs;
|
import io.metersphere.base.domain.ApiTestCaseWithBLOBs;
|
||||||
|
import io.metersphere.commons.constants.DelimiterConstants;
|
||||||
import io.metersphere.commons.constants.MsTestElementConstants;
|
import io.metersphere.commons.constants.MsTestElementConstants;
|
||||||
import io.metersphere.commons.utils.CommonBeanFactory;
|
import io.metersphere.commons.utils.CommonBeanFactory;
|
||||||
import io.metersphere.commons.utils.LogUtil;
|
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.jmeter.testelement.TestElement;
|
||||||
import org.apache.jorphan.collections.HashTree;
|
import org.apache.jorphan.collections.HashTree;
|
||||||
|
|
||||||
|
import java.util.LinkedList;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.stream.Collectors;
|
import java.util.stream.Collectors;
|
||||||
|
|
||||||
|
@ -133,11 +136,14 @@ public class MsDubboSampler extends MsTestElement {
|
||||||
sampler.setName(this.getName());
|
sampler.setName(this.getName());
|
||||||
String name = this.getParentName(this.getParent());
|
String name = this.getParentName(this.getParent());
|
||||||
if (StringUtils.isNotEmpty(name) && !config.isOperating()) {
|
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.TEST_CLASS, DubboSample.class.getName());
|
||||||
sampler.setProperty(TestElement.GUI_CLASS, SaveService.aliasToClass("DubboSampleGui"));
|
sampler.setProperty(TestElement.GUI_CLASS, SaveService.aliasToClass("DubboSampleGui"));
|
||||||
sampler.setProperty("MS-ID", this.getId());
|
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(configCenter(this.getConfigCenter()));
|
||||||
sampler.addTestElement(registryCenter(this.getRegistryCenter()));
|
sampler.addTestElement(registryCenter(this.getRegistryCenter()));
|
||||||
|
|
|
@ -1,5 +1,6 @@
|
||||||
package io.metersphere.api.dto.definition.request.sampler;
|
package io.metersphere.api.dto.definition.request.sampler;
|
||||||
|
|
||||||
|
import com.alibaba.fastjson.JSON;
|
||||||
import com.alibaba.fastjson.annotation.JSONField;
|
import com.alibaba.fastjson.annotation.JSONField;
|
||||||
import com.alibaba.fastjson.annotation.JSONType;
|
import com.alibaba.fastjson.annotation.JSONType;
|
||||||
import com.fasterxml.jackson.core.type.TypeReference;
|
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.ApiTestCaseWithBLOBs;
|
||||||
import io.metersphere.base.domain.TestPlanApiCase;
|
import io.metersphere.base.domain.TestPlanApiCase;
|
||||||
import io.metersphere.commons.constants.ConditionType;
|
import io.metersphere.commons.constants.ConditionType;
|
||||||
|
import io.metersphere.commons.constants.DelimiterConstants;
|
||||||
import io.metersphere.commons.constants.MsTestElementConstants;
|
import io.metersphere.commons.constants.MsTestElementConstants;
|
||||||
import io.metersphere.commons.exception.MSException;
|
import io.metersphere.commons.exception.MSException;
|
||||||
import io.metersphere.commons.utils.CommonBeanFactory;
|
import io.metersphere.commons.utils.CommonBeanFactory;
|
||||||
|
@ -42,10 +44,7 @@ import org.apache.jorphan.collections.HashTree;
|
||||||
|
|
||||||
import java.net.URL;
|
import java.net.URL;
|
||||||
import java.net.URLDecoder;
|
import java.net.URLDecoder;
|
||||||
import java.util.HashMap;
|
import java.util.*;
|
||||||
import java.util.Iterator;
|
|
||||||
import java.util.List;
|
|
||||||
import java.util.Map;
|
|
||||||
import java.util.regex.Matcher;
|
import java.util.regex.Matcher;
|
||||||
import java.util.regex.Pattern;
|
import java.util.regex.Pattern;
|
||||||
|
|
||||||
|
@ -163,11 +162,15 @@ public class MsHTTPSamplerProxy extends MsTestElement {
|
||||||
}
|
}
|
||||||
String name = this.getParentName(this.getParent());
|
String name = this.getParentName(this.getParent());
|
||||||
if (StringUtils.isNotEmpty(name) && !config.isOperating()) {
|
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.TEST_CLASS, HTTPSamplerProxy.class.getName());
|
||||||
sampler.setProperty(TestElement.GUI_CLASS, SaveService.aliasToClass("HttpTestSampleGui"));
|
sampler.setProperty(TestElement.GUI_CLASS, SaveService.aliasToClass("HttpTestSampleGui"));
|
||||||
sampler.setProperty("MS-ID", this.getId());
|
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.setMethod(this.getMethod());
|
||||||
sampler.setContentEncoding("UTF-8");
|
sampler.setContentEncoding("UTF-8");
|
||||||
sampler.setConnectTimeout(this.getConnectTimeout() == null ? "6000" : this.getConnectTimeout());
|
sampler.setConnectTimeout(this.getConnectTimeout() == null ? "6000" : this.getConnectTimeout());
|
||||||
|
|
|
@ -1,5 +1,6 @@
|
||||||
package io.metersphere.api.dto.definition.request.sampler;
|
package io.metersphere.api.dto.definition.request.sampler;
|
||||||
|
|
||||||
|
import com.alibaba.fastjson.JSON;
|
||||||
import com.alibaba.fastjson.JSONObject;
|
import com.alibaba.fastjson.JSONObject;
|
||||||
import com.alibaba.fastjson.annotation.JSONField;
|
import com.alibaba.fastjson.annotation.JSONField;
|
||||||
import com.alibaba.fastjson.annotation.JSONType;
|
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.ApiDefinitionWithBLOBs;
|
||||||
import io.metersphere.base.domain.ApiTestCaseWithBLOBs;
|
import io.metersphere.base.domain.ApiTestCaseWithBLOBs;
|
||||||
import io.metersphere.base.domain.ApiTestEnvironmentWithBLOBs;
|
import io.metersphere.base.domain.ApiTestEnvironmentWithBLOBs;
|
||||||
|
import io.metersphere.commons.constants.DelimiterConstants;
|
||||||
import io.metersphere.commons.constants.MsTestElementConstants;
|
import io.metersphere.commons.constants.MsTestElementConstants;
|
||||||
import io.metersphere.commons.exception.MSException;
|
import io.metersphere.commons.exception.MSException;
|
||||||
import io.metersphere.commons.utils.CommonBeanFactory;
|
import io.metersphere.commons.utils.CommonBeanFactory;
|
||||||
|
@ -33,6 +35,7 @@ import org.apache.jmeter.testelement.TestElement;
|
||||||
import org.apache.jorphan.collections.HashTree;
|
import org.apache.jorphan.collections.HashTree;
|
||||||
|
|
||||||
import java.util.Iterator;
|
import java.util.Iterator;
|
||||||
|
import java.util.LinkedList;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.stream.Collectors;
|
import java.util.stream.Collectors;
|
||||||
|
|
||||||
|
@ -231,11 +234,14 @@ public class MsJDBCSampler extends MsTestElement {
|
||||||
sampler.setName(this.getName());
|
sampler.setName(this.getName());
|
||||||
String name = this.getParentName(this.getParent());
|
String name = this.getParentName(this.getParent());
|
||||||
if (StringUtils.isNotEmpty(name) && !config.isOperating()) {
|
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.TEST_CLASS, JDBCSampler.class.getName());
|
||||||
sampler.setProperty(TestElement.GUI_CLASS, SaveService.aliasToClass("TestBeanGUI"));
|
sampler.setProperty(TestElement.GUI_CLASS, SaveService.aliasToClass("TestBeanGUI"));
|
||||||
sampler.setProperty("MS-ID", this.getId());
|
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
|
// request.getDataSource() 是ID,需要转换为Name
|
||||||
sampler.setProperty("dataSource", this.dataSource.getName());
|
sampler.setProperty("dataSource", this.dataSource.getName());
|
||||||
|
|
|
@ -1,5 +1,6 @@
|
||||||
package io.metersphere.api.dto.definition.request.sampler;
|
package io.metersphere.api.dto.definition.request.sampler;
|
||||||
|
|
||||||
|
import com.alibaba.fastjson.JSON;
|
||||||
import com.alibaba.fastjson.annotation.JSONField;
|
import com.alibaba.fastjson.annotation.JSONField;
|
||||||
import com.alibaba.fastjson.annotation.JSONType;
|
import com.alibaba.fastjson.annotation.JSONType;
|
||||||
import com.fasterxml.jackson.core.type.TypeReference;
|
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.api.service.ApiTestCaseService;
|
||||||
import io.metersphere.base.domain.ApiDefinitionWithBLOBs;
|
import io.metersphere.base.domain.ApiDefinitionWithBLOBs;
|
||||||
import io.metersphere.base.domain.ApiTestCaseWithBLOBs;
|
import io.metersphere.base.domain.ApiTestCaseWithBLOBs;
|
||||||
|
import io.metersphere.commons.constants.DelimiterConstants;
|
||||||
import io.metersphere.commons.constants.MsTestElementConstants;
|
import io.metersphere.commons.constants.MsTestElementConstants;
|
||||||
import io.metersphere.commons.utils.CommonBeanFactory;
|
import io.metersphere.commons.utils.CommonBeanFactory;
|
||||||
import io.metersphere.commons.utils.LogUtil;
|
import io.metersphere.commons.utils.LogUtil;
|
||||||
|
@ -34,6 +36,7 @@ import org.apache.jorphan.collections.HashTree;
|
||||||
import org.apache.jorphan.collections.ListedHashTree;
|
import org.apache.jorphan.collections.ListedHashTree;
|
||||||
|
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
|
import java.util.LinkedList;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Random;
|
import java.util.Random;
|
||||||
|
|
||||||
|
@ -174,9 +177,12 @@ public class MsTCPSampler extends MsTestElement {
|
||||||
tcpSampler.setName(this.getName());
|
tcpSampler.setName(this.getName());
|
||||||
String name = this.getParentName(this.getParent());
|
String name = this.getParentName(this.getParent());
|
||||||
if (StringUtils.isNotEmpty(name) && !config.isOperating()) {
|
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());
|
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.TEST_CLASS, TCPSampler.class.getName());
|
||||||
tcpSampler.setProperty(TestElement.GUI_CLASS, SaveService.aliasToClass("TCPSamplerGui"));
|
tcpSampler.setProperty(TestElement.GUI_CLASS, SaveService.aliasToClass("TCPSamplerGui"));
|
||||||
|
|
|
@ -420,6 +420,7 @@ public class APIBackendListenerClient extends AbstractBackendListenerClient impl
|
||||||
requestResult.setTotalAssertions(result.getAssertionResults().length);
|
requestResult.setTotalAssertions(result.getAssertionResults().length);
|
||||||
requestResult.setSuccess(result.isSuccessful());
|
requestResult.setSuccess(result.isSuccessful());
|
||||||
requestResult.setError(result.getErrorCount());
|
requestResult.setError(result.getErrorCount());
|
||||||
|
requestResult.setScenario(result.getScenario());
|
||||||
if (result instanceof HTTPSampleResult) {
|
if (result instanceof HTTPSampleResult) {
|
||||||
HTTPSampleResult res = (HTTPSampleResult) result;
|
HTTPSampleResult res = (HTTPSampleResult) result;
|
||||||
requestResult.setCookies(res.getCookies());
|
requestResult.setCookies(res.getCookies());
|
||||||
|
|
|
@ -8,6 +8,7 @@ import io.metersphere.api.dto.scenario.request.BodyFile;
|
||||||
import io.metersphere.base.domain.JarConfig;
|
import io.metersphere.base.domain.JarConfig;
|
||||||
import io.metersphere.base.domain.TestResource;
|
import io.metersphere.base.domain.TestResource;
|
||||||
import io.metersphere.commons.constants.ApiRunMode;
|
import io.metersphere.commons.constants.ApiRunMode;
|
||||||
|
import io.metersphere.commons.constants.RunModeConstants;
|
||||||
import io.metersphere.commons.exception.MSException;
|
import io.metersphere.commons.exception.MSException;
|
||||||
import io.metersphere.commons.utils.*;
|
import io.metersphere.commons.utils.*;
|
||||||
import io.metersphere.config.JmeterProperties;
|
import io.metersphere.config.JmeterProperties;
|
||||||
|
@ -122,7 +123,7 @@ public class JMeterService {
|
||||||
BackendListener backendListener = new BackendListener();
|
BackendListener backendListener = new BackendListener();
|
||||||
backendListener.setName(testId);
|
backendListener.setName(testId);
|
||||||
Arguments arguments = new Arguments();
|
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());
|
arguments.addArgument(APIBackendListenerClient.TEST_REPORT_ID, config.getReportId());
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -16,6 +16,8 @@ public class RequestResult {
|
||||||
|
|
||||||
private String method;
|
private String method;
|
||||||
|
|
||||||
|
private String scenario;
|
||||||
|
|
||||||
private long requestSize;
|
private long requestSize;
|
||||||
|
|
||||||
private long startTime;
|
private long startTime;
|
||||||
|
|
|
@ -1,11 +1,15 @@
|
||||||
package io.metersphere.api.jmeter;
|
package io.metersphere.api.jmeter;
|
||||||
|
|
||||||
|
import com.alibaba.fastjson.JSON;
|
||||||
|
import io.metersphere.commons.constants.DelimiterConstants;
|
||||||
import lombok.Data;
|
import lombok.Data;
|
||||||
import org.apache.commons.collections.CollectionUtils;
|
import org.apache.commons.collections.CollectionUtils;
|
||||||
import org.apache.commons.lang3.StringUtils;
|
import org.apache.commons.lang3.StringUtils;
|
||||||
|
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
|
import java.util.HashMap;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
import java.util.Map;
|
||||||
|
|
||||||
@Data
|
@Data
|
||||||
public class TestResult {
|
public class TestResult {
|
||||||
|
@ -14,6 +18,12 @@ public class TestResult {
|
||||||
|
|
||||||
private String setReportId;
|
private String setReportId;
|
||||||
|
|
||||||
|
private int scenarioTotal;
|
||||||
|
|
||||||
|
private int scenarioSuccess;
|
||||||
|
|
||||||
|
private int scenarioError;
|
||||||
|
|
||||||
private String userId;
|
private String userId;
|
||||||
|
|
||||||
private boolean isDebug;
|
private boolean isDebug;
|
||||||
|
@ -32,6 +42,8 @@ public class TestResult {
|
||||||
|
|
||||||
private List<ScenarioResult> scenarios = new ArrayList<>();
|
private List<ScenarioResult> scenarios = new ArrayList<>();
|
||||||
|
|
||||||
|
private Map<String, Boolean> margeScenariMap = new HashMap<>();
|
||||||
|
|
||||||
public void addError(int count) {
|
public void addError(int count) {
|
||||||
this.error += count;
|
this.error += count;
|
||||||
}
|
}
|
||||||
|
@ -48,11 +60,25 @@ public class TestResult {
|
||||||
this.passAssertions += count;
|
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) {
|
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 -> {
|
||||||
|
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) {
|
if (StringUtils.isNotEmpty(item.getName()) && item.getName().indexOf(SEPARATOR) != -1) {
|
||||||
String array[] = item.getName().split(SEPARATOR);
|
String array[] = item.getName().split(SEPARATOR);
|
||||||
item.setName(array[1] + array[0]);
|
item.setName(array[1] + array[0]);
|
||||||
|
@ -63,5 +89,13 @@ public class TestResult {
|
||||||
});
|
});
|
||||||
scenarios.add(result);
|
scenarios.add(result);
|
||||||
}
|
}
|
||||||
|
for (String key : margeScenariMap.keySet()) {
|
||||||
|
if (margeScenariMap.get(key)) {
|
||||||
|
this.scenarioError++;
|
||||||
|
} else {
|
||||||
|
this.scenarioSuccess++;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
this.setScenarioTotal(this.margeScenariMap.size());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -597,7 +597,7 @@ public class ApiAutomationService {
|
||||||
}
|
}
|
||||||
report.setUpdateTime(System.currentTimeMillis());
|
report.setUpdateTime(System.currentTimeMillis());
|
||||||
report.setCreateTime(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.setCreateTime(System.currentTimeMillis() + 2000);
|
||||||
report.setUpdateTime(System.currentTimeMillis() + 2000);
|
report.setUpdateTime(System.currentTimeMillis() + 2000);
|
||||||
}
|
}
|
||||||
|
@ -751,8 +751,8 @@ public class ApiAutomationService {
|
||||||
// 环境检查
|
// 环境检查
|
||||||
this.checkEnv(request, apiScenarios);
|
this.checkEnv(request, apiScenarios);
|
||||||
|
|
||||||
if (request.getConfig() != null && request.getConfig().getMode().equals("serial")) {
|
if (request.getConfig() != null && request.getConfig().getMode().equals(RunModeConstants.SERIAL.toString())) {
|
||||||
if (StringUtils.isNotEmpty(request.getConfig().getReportName())) {
|
if (StringUtils.equals(request.getConfig().getReportType(), RunModeConstants.SET_REPORT.toString()) && StringUtils.isNotEmpty(request.getConfig().getReportName())) {
|
||||||
request.setExecuteType(ExecuteType.Completed.name());
|
request.setExecuteType(ExecuteType.Completed.name());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -806,7 +806,7 @@ public class ApiAutomationService {
|
||||||
|
|
||||||
// 生成集成报告
|
// 生成集成报告
|
||||||
String serialReportId = null;
|
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());
|
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(),
|
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());
|
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) {
|
private void run(Map<APIScenarioReportResult, HashTree> map, RunScenarioRequest request, String serialReportId) {
|
||||||
// 开始选择执行模式
|
// 开始选择执行模式
|
||||||
ExecutorService executorService = Executors.newFixedThreadPool(map.size());
|
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() {
|
Thread thread = new Thread(new Runnable() {
|
||||||
@Override
|
@Override
|
||||||
|
@ -1057,7 +1057,7 @@ public class ApiAutomationService {
|
||||||
|
|
||||||
public String run(RunScenarioRequest request) {
|
public String run(RunScenarioRequest request) {
|
||||||
if (request.getConfig() != null) {
|
if (request.getConfig() != null) {
|
||||||
if (request.getConfig().getMode().equals("parallel")) {
|
if (request.getConfig().getMode().equals(RunModeConstants.PARALLEL.toString())) {
|
||||||
// 校验并发数量
|
// 校验并发数量
|
||||||
int count = 50;
|
int count = 50;
|
||||||
BaseSystemConfigDTO dto = systemParameterService.getBaseInfo();
|
BaseSystemConfigDTO dto = systemParameterService.getBaseInfo();
|
||||||
|
|
|
@ -3,11 +3,15 @@ package io.metersphere.api.service;
|
||||||
import com.alibaba.fastjson.JSON;
|
import com.alibaba.fastjson.JSON;
|
||||||
import io.metersphere.api.dto.datacount.ExecutedCaseInfoResult;
|
import io.metersphere.api.dto.datacount.ExecutedCaseInfoResult;
|
||||||
import io.metersphere.api.jmeter.TestResult;
|
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.ApiDefinitionExecResultMapper;
|
||||||
import io.metersphere.base.mapper.ApiTestCaseMapper;
|
import io.metersphere.base.mapper.ApiTestCaseMapper;
|
||||||
import io.metersphere.base.mapper.ext.ExtApiDefinitionExecResultMapper;
|
import io.metersphere.base.mapper.ext.ExtApiDefinitionExecResultMapper;
|
||||||
import io.metersphere.commons.constants.ApiRunMode;
|
import io.metersphere.commons.constants.ApiRunMode;
|
||||||
|
import io.metersphere.commons.constants.DelimiterConstants;
|
||||||
import io.metersphere.commons.utils.DateUtils;
|
import io.metersphere.commons.utils.DateUtils;
|
||||||
import io.metersphere.commons.utils.SessionUtils;
|
import io.metersphere.commons.utils.SessionUtils;
|
||||||
import io.metersphere.track.dto.TestPlanDTO;
|
import io.metersphere.track.dto.TestPlanDTO;
|
||||||
|
@ -61,8 +65,8 @@ public class ApiDefinitionExecResultService {
|
||||||
saveResult.setCreateTime(item.getStartTime());
|
saveResult.setCreateTime(item.getStartTime());
|
||||||
saveResult.setUserId(result.getUserId());
|
saveResult.setUserId(result.getUserId());
|
||||||
saveResult.setName(item.getName());
|
saveResult.setName(item.getName());
|
||||||
if (item.getName().indexOf("<->") != -1) {
|
if (item.getName().indexOf(DelimiterConstants.SEPARATOR.toString()) != -1) {
|
||||||
saveResult.setName(item.getName().substring(0, item.getName().indexOf("<->")));
|
saveResult.setName(item.getName().substring(0, item.getName().indexOf(DelimiterConstants.SEPARATOR.toString())));
|
||||||
}
|
}
|
||||||
saveResult.setResourceId(item.getName());
|
saveResult.setResourceId(item.getName());
|
||||||
saveResult.setContent(JSON.toJSONString(item));
|
saveResult.setContent(JSON.toJSONString(item));
|
||||||
|
|
|
@ -583,8 +583,8 @@ public class ApiDefinitionService {
|
||||||
public void addResult(TestResult res) {
|
public void addResult(TestResult res) {
|
||||||
if (res != null && CollectionUtils.isNotEmpty(res.getScenarios()) && res.getScenarios().get(0) != null && CollectionUtils.isNotEmpty(res.getScenarios().get(0).getRequestResults())) {
|
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);
|
RequestResult result = res.getScenarios().get(0).getRequestResults().get(0);
|
||||||
if (result.getName().indexOf("<->") != -1) {
|
if (result.getName().indexOf(DelimiterConstants.SEPARATOR.toString()) != -1) {
|
||||||
result.setName(result.getName().substring(0, result.getName().indexOf("<->")));
|
result.setName(result.getName().substring(0, result.getName().indexOf(DelimiterConstants.SEPARATOR.toString())));
|
||||||
}
|
}
|
||||||
cache.put(res.getTestId(), result);
|
cache.put(res.getTestId(), result);
|
||||||
} else {
|
} else {
|
||||||
|
|
|
@ -396,6 +396,9 @@ public class ApiScenarioReportService {
|
||||||
testResult.setPassAssertions(testResult.getPassAssertions() + scenarioResult.getPassAssertions());
|
testResult.setPassAssertions(testResult.getPassAssertions() + scenarioResult.getPassAssertions());
|
||||||
testResult.setSuccess(testResult.getSuccess() + scenarioResult.getSuccess());
|
testResult.setSuccess(testResult.getSuccess() + scenarioResult.getSuccess());
|
||||||
testResult.setTotalAssertions(scenarioResult.getTotalAssertions() + testResult.getTotalAssertions());
|
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) {
|
} catch (Exception e) {
|
||||||
LogUtil.error(e.getMessage());
|
LogUtil.error(e.getMessage());
|
||||||
}
|
}
|
||||||
|
|
|
@ -45,6 +45,11 @@ public class SerialScenarioExecTask<T> implements Callable<T> {
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
// 执行失败了,恢复报告状态
|
||||||
|
if (index == 200 && report != null && report.getStatus().equals(APITestStatus.Running.name())) {
|
||||||
|
report.setStatus(APITestStatus.Error.name());
|
||||||
|
apiScenarioReportMapper.updateByPrimaryKey(report);
|
||||||
|
}
|
||||||
return (T) report;
|
return (T) report;
|
||||||
} catch (Exception ex) {
|
} catch (Exception ex) {
|
||||||
LogUtil.error(ex.getMessage());
|
LogUtil.error(ex.getMessage());
|
||||||
|
|
|
@ -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;
|
||||||
|
}
|
||||||
|
}
|
|
@ -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;
|
||||||
|
}
|
||||||
|
}
|
|
@ -6,6 +6,7 @@ import io.metersphere.base.mapper.LoadTestReportMapper;
|
||||||
import io.metersphere.base.mapper.TestPlanLoadCaseMapper;
|
import io.metersphere.base.mapper.TestPlanLoadCaseMapper;
|
||||||
import io.metersphere.base.mapper.TestPlanMapper;
|
import io.metersphere.base.mapper.TestPlanMapper;
|
||||||
import io.metersphere.base.mapper.ext.ExtTestPlanLoadCaseMapper;
|
import io.metersphere.base.mapper.ext.ExtTestPlanLoadCaseMapper;
|
||||||
|
import io.metersphere.commons.constants.RunModeConstants;
|
||||||
import io.metersphere.commons.constants.TestPlanStatus;
|
import io.metersphere.commons.constants.TestPlanStatus;
|
||||||
import io.metersphere.commons.exception.MSException;
|
import io.metersphere.commons.exception.MSException;
|
||||||
import io.metersphere.controller.request.OrderRequest;
|
import io.metersphere.controller.request.OrderRequest;
|
||||||
|
@ -129,7 +130,7 @@ public class TestPlanLoadCaseService {
|
||||||
}
|
}
|
||||||
|
|
||||||
public void runBatch(RunBatchTestPlanRequest request) {
|
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 {
|
try {
|
||||||
serialRun(request);
|
serialRun(request);
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
|
|
|
@ -23,7 +23,6 @@ import org.apache.jmeter.gui.Searchable;
|
||||||
import org.apache.jmeter.testelement.TestPlan;
|
import org.apache.jmeter.testelement.TestPlan;
|
||||||
import org.apache.jmeter.threads.JMeterContext.TestLogicalAction;
|
import org.apache.jmeter.threads.JMeterContext.TestLogicalAction;
|
||||||
import org.apache.jmeter.threads.JMeterContextService;
|
import org.apache.jmeter.threads.JMeterContextService;
|
||||||
import org.apache.jmeter.threads.JMeterVariables;
|
|
||||||
import org.apache.jmeter.util.JMeterUtils;
|
import org.apache.jmeter.util.JMeterUtils;
|
||||||
import org.apache.jorphan.util.JOrphanUtils;
|
import org.apache.jorphan.util.JOrphanUtils;
|
||||||
import org.slf4j.Logger;
|
import org.slf4j.Logger;
|
||||||
|
@ -164,12 +163,25 @@ public class SampleResult implements Serializable, Cloneable, Searchable {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 定制自定义添加 =================
|
||||||
|
*/
|
||||||
private String samplerId;
|
private String samplerId;
|
||||||
|
|
||||||
public String getSamplerId() {
|
public String getSamplerId() {
|
||||||
return this.samplerId;
|
return this.samplerId;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// 数据格式 List<id_name> 多层父级按照同级统计
|
||||||
|
private String scenario;
|
||||||
|
|
||||||
|
public String getScenario() {
|
||||||
|
return this.scenario;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 定制自定义添加 =================
|
||||||
|
*/
|
||||||
private SampleSaveConfiguration saveConfig;
|
private SampleSaveConfiguration saveConfig;
|
||||||
|
|
||||||
private SampleResult parent;
|
private SampleResult parent;
|
||||||
|
@ -336,6 +348,7 @@ public class SampleResult implements Serializable, Cloneable, Searchable {
|
||||||
Sampler sampler = JMeterContextService.getContext().getCurrentSampler();
|
Sampler sampler = JMeterContextService.getContext().getCurrentSampler();
|
||||||
if (sampler != null) {
|
if (sampler != null) {
|
||||||
this.samplerId = sampler.getPropertyAsString("MS-ID");
|
this.samplerId = sampler.getPropertyAsString("MS-ID");
|
||||||
|
this.scenario = sampler.getPropertyAsString("MS-SCENARIO");
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -26,6 +26,30 @@
|
||||||
</el-row>
|
</el-row>
|
||||||
</div>
|
</div>
|
||||||
<div class="split"></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%">
|
<div style="width: 50%">
|
||||||
<el-row type="flex" justify="space-around" align="middle">
|
<el-row type="flex" justify="space-around" align="middle">
|
||||||
<div class="metric-icon-box">
|
<div class="metric-icon-box">
|
||||||
|
@ -50,206 +74,209 @@
|
||||||
</template>
|
</template>
|
||||||
|
|
||||||
<script>
|
<script>
|
||||||
import MsChart from "@/business/components/common/chart/MsChart";
|
import MsChart from "@/business/components/common/chart/MsChart";
|
||||||
|
|
||||||
export default {
|
export default {
|
||||||
name: "MsMetricChart",
|
name: "MsMetricChart",
|
||||||
components: {MsChart},
|
components: {MsChart},
|
||||||
props: {
|
props: {
|
||||||
content: Object,
|
content: Object,
|
||||||
totalTime: Number
|
totalTime: Number
|
||||||
},
|
},
|
||||||
data() {
|
data() {
|
||||||
return {
|
return {
|
||||||
hour: 0,
|
hour: 0,
|
||||||
minutes: 0,
|
minutes: 0,
|
||||||
seconds: 0,
|
seconds: 0,
|
||||||
time: 0,
|
time: 0,
|
||||||
}
|
scenarioTotal: 0,
|
||||||
},
|
scenarioSuccess: 0,
|
||||||
created() {
|
scenarioError: 0,
|
||||||
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"
|
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
},
|
created() {
|
||||||
computed: {
|
this.initTime()
|
||||||
options() {
|
},
|
||||||
return {
|
methods: {
|
||||||
color: ['#67C23A', '#F56C6C'],
|
initTime() {
|
||||||
tooltip: {
|
this.time = this.totalTime
|
||||||
trigger: 'item',
|
this.seconds = Math.floor(this.time / 1000)
|
||||||
formatter: '{b}: {c} ({d}%)'
|
if (this.seconds >= 1) {
|
||||||
},
|
if (this.seconds > 60) {
|
||||||
title: [{
|
this.minutes = Math.round(this.time / 60)
|
||||||
text: this.content.total,
|
this.seconds = Math.round(this.time % 60)
|
||||||
subtext: this.$t('api_report.request'),
|
this.time = this.minutes + "min" + this.seconds + "s"
|
||||||
top: 'center',
|
}
|
||||||
left: 'center',
|
if (this.seconds > 60) {
|
||||||
textStyle: {
|
this.minutes = Math.round(this.time / 60)
|
||||||
rich: {
|
this.seconds = Math.round(this.time % 60)
|
||||||
align: 'center',
|
this.time = this.minutes + "min" + this.seconds + "s"
|
||||||
value: {
|
}
|
||||||
fontSize: 32,
|
if (this.minutes > 60) {
|
||||||
fontWeight: 'bold',
|
this.hour = Math.round(this.minutes / 60)
|
||||||
padding: [10, 0]
|
this.minutes = Math.round(this.minutes % 60)
|
||||||
},
|
this.time = this.hour + "hour" + this.minutes + "min" + this.seconds + "s"
|
||||||
name: {
|
}
|
||||||
fontSize: 14,
|
|
||||||
fontWeight: 'normal',
|
this.time = (this.seconds) + "s"
|
||||||
color: '#7F7F7F',
|
} 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: [
|
||||||
series: [
|
{
|
||||||
{
|
type: 'pie',
|
||||||
type: 'pie',
|
radius: ['80%', '90%'],
|
||||||
radius: ['80%', '90%'],
|
avoidLabelOverlap: false,
|
||||||
avoidLabelOverlap: false,
|
hoverAnimation: false,
|
||||||
hoverAnimation: false,
|
itemStyle: {
|
||||||
itemStyle: {
|
normal: {
|
||||||
normal: {
|
borderColor: "#FFF",
|
||||||
borderColor: "#FFF",
|
shadowColor: '#E1E1E1',
|
||||||
shadowColor: '#E1E1E1',
|
shadowBlur: 10
|
||||||
shadowBlur: 10
|
}
|
||||||
}
|
},
|
||||||
},
|
labelLine: {
|
||||||
labelLine: {
|
show: false
|
||||||
show: false
|
},
|
||||||
},
|
data: [
|
||||||
data: [
|
{value: this.content.success},
|
||||||
{value: this.content.success},
|
{value: this.content.error},
|
||||||
{value: this.content.error},
|
]
|
||||||
]
|
}
|
||||||
}
|
]
|
||||||
]
|
};
|
||||||
};
|
},
|
||||||
},
|
|
||||||
|
|
||||||
fail() {
|
fail() {
|
||||||
return (this.content.error / this.content.total * 100).toFixed(0) + "%";
|
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>
|
</script>
|
||||||
|
|
||||||
<style scoped>
|
<style scoped>
|
||||||
.metric-container {
|
.metric-container {
|
||||||
padding: 20px;
|
padding: 20px;
|
||||||
}
|
}
|
||||||
|
|
||||||
.metric-container #chart {
|
.metric-container #chart {
|
||||||
width: 140px;
|
width: 140px;
|
||||||
height: 140px;
|
height: 140px;
|
||||||
margin-right: 40px;
|
margin-right: 40px;
|
||||||
}
|
}
|
||||||
|
|
||||||
.metric-container .split {
|
.metric-container .split {
|
||||||
margin: 20px;
|
margin: 20px;
|
||||||
height: 100px;
|
height: 100px;
|
||||||
border-left: 1px solid #D8DBE1;
|
border-left: 1px solid #D8DBE1;
|
||||||
}
|
}
|
||||||
|
|
||||||
.metric-container .circle {
|
.metric-container .circle {
|
||||||
width: 12px;
|
width: 12px;
|
||||||
height: 12px;
|
height: 12px;
|
||||||
border-radius: 50%;
|
border-radius: 50%;
|
||||||
box-shadow: 0 0 20px 1px rgba(200, 216, 226, .42);
|
box-shadow: 0 0 20px 1px rgba(200, 216, 226, .42);
|
||||||
display: inline-block;
|
display: inline-block;
|
||||||
margin-right: 10px;
|
margin-right: 10px;
|
||||||
vertical-align: middle;
|
vertical-align: middle;
|
||||||
}
|
}
|
||||||
|
|
||||||
.metric-container .circle.success {
|
.metric-container .circle.success {
|
||||||
background-color: #67C23A;
|
background-color: #67C23A;
|
||||||
}
|
}
|
||||||
|
|
||||||
.metric-container .circle.fail {
|
.metric-container .circle.fail {
|
||||||
background-color: #F56C6C;
|
background-color: #F56C6C;
|
||||||
}
|
}
|
||||||
|
|
||||||
.metric-box {
|
.metric-box {
|
||||||
display: inline-block;
|
display: inline-block;
|
||||||
text-align: center;
|
text-align: center;
|
||||||
}
|
}
|
||||||
|
|
||||||
.metric-box .value {
|
.metric-box .value {
|
||||||
font-size: 32px;
|
font-size: 32px;
|
||||||
font-weight: 600;
|
font-weight: 600;
|
||||||
letter-spacing: -.5px;
|
letter-spacing: -.5px;
|
||||||
}
|
}
|
||||||
|
|
||||||
.metric-time .value {
|
.metric-time .value {
|
||||||
font-size: 25px;
|
font-size: 25px;
|
||||||
font-weight: 400;
|
font-weight: 400;
|
||||||
letter-spacing: -.5px;
|
letter-spacing: -.5px;
|
||||||
}
|
}
|
||||||
|
|
||||||
.metric-box .name {
|
.metric-box .name {
|
||||||
font-size: 16px;
|
font-size: 16px;
|
||||||
letter-spacing: -.2px;
|
letter-spacing: -.2px;
|
||||||
color: #404040;
|
color: #404040;
|
||||||
}
|
}
|
||||||
|
|
||||||
.metric-icon-box {
|
.metric-icon-box {
|
||||||
text-align: center;
|
text-align: center;
|
||||||
margin: 0 10px;
|
margin: 0 10px;
|
||||||
}
|
}
|
||||||
|
|
||||||
.metric-icon-box .value {
|
.metric-icon-box .value {
|
||||||
font-size: 20px;
|
font-size: 20px;
|
||||||
font-weight: 600;
|
font-weight: 600;
|
||||||
letter-spacing: -.4px;
|
letter-spacing: -.4px;
|
||||||
line-height: 28px;
|
line-height: 28px;
|
||||||
vertical-align: middle;
|
vertical-align: middle;
|
||||||
}
|
}
|
||||||
|
|
||||||
.metric-icon-box .name {
|
.metric-icon-box .name {
|
||||||
font-size: 13px;
|
font-size: 13px;
|
||||||
letter-spacing: 1px;
|
letter-spacing: 1px;
|
||||||
color: #BFBFBF;
|
color: #BFBFBF;
|
||||||
line-height: 18px;
|
line-height: 18px;
|
||||||
}
|
}
|
||||||
|
|
||||||
.metric-icon-box .fail {
|
.metric-icon-box .fail {
|
||||||
color: #F56C6C;
|
color: #F56C6C;
|
||||||
font-size: 40px;
|
font-size: 40px;
|
||||||
}
|
}
|
||||||
|
|
||||||
.metric-icon-box .assertions {
|
.metric-icon-box .assertions {
|
||||||
font-size: 40px;
|
font-size: 40px;
|
||||||
}
|
}
|
||||||
|
|
||||||
.metric-icon-box .total {
|
.metric-icon-box .total {
|
||||||
font-size: 40px;
|
font-size: 40px;
|
||||||
}
|
}
|
||||||
|
|
||||||
</style>
|
</style>
|
||||||
|
|
|
@ -994,7 +994,7 @@
|
||||||
},
|
},
|
||||||
getApiScenario() {
|
getApiScenario() {
|
||||||
this.loading = true;
|
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);
|
this.currentScenario.tags = JSON.parse(this.currentScenario.tags);
|
||||||
}
|
}
|
||||||
if (!this.currentScenario.variables) {
|
if (!this.currentScenario.variables) {
|
||||||
|
|
Loading…
Reference in New Issue