fix(测试跟踪): 测试计划实时报告显示执行了的用例的环境

测试计划实时报告显示执行了的用例的环境
This commit is contained in:
song-tianyang 2022-07-14 14:26:02 +08:00 committed by TIanyang
parent bed0ed6faf
commit e4d1cfa9a2
13 changed files with 659 additions and 470 deletions

View File

@ -4,6 +4,7 @@ import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject; import com.alibaba.fastjson.JSONObject;
import com.alibaba.fastjson.parser.Feature; import com.alibaba.fastjson.parser.Feature;
import io.metersphere.api.dto.EnvironmentType; import io.metersphere.api.dto.EnvironmentType;
import io.metersphere.api.dto.RunModeConfigWithEnvironmentDTO;
import io.metersphere.api.dto.ScenarioEnv; import io.metersphere.api.dto.ScenarioEnv;
import io.metersphere.api.dto.automation.ApiScenarioDTO; import io.metersphere.api.dto.automation.ApiScenarioDTO;
import io.metersphere.api.dto.automation.RunScenarioRequest; import io.metersphere.api.dto.automation.RunScenarioRequest;
@ -22,6 +23,7 @@ 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;
import io.metersphere.commons.utils.LogUtil; import io.metersphere.commons.utils.LogUtil;
import io.metersphere.dto.RunModeConfigDTO;
import io.metersphere.plugin.core.MsTestElement; import io.metersphere.plugin.core.MsTestElement;
import io.metersphere.service.EnvironmentGroupProjectService; import io.metersphere.service.EnvironmentGroupProjectService;
import io.metersphere.service.ProjectService; import io.metersphere.service.ProjectService;
@ -471,4 +473,74 @@ public class ApiScenarioEnvService {
} }
return returnMap; return returnMap;
} }
public Map<String, List<String>> selectProjectEnvMapByTestPlanScenarioIds(List<String> resourceIds) {
Map<String, List<String>> returnMap = new LinkedHashMap<>();
if (CollectionUtils.isNotEmpty(resourceIds)) {
List<String> reportEnvConfList = testPlanApiScenarioMapper.selectReportEnvConfByResourceIds(resourceIds);
reportEnvConfList.forEach(envConf -> {
LinkedHashMap<String, List<String>> projectEnvMap = this.getProjectEnvMapByEnvConfig(envConf);
for (Map.Entry<String, List<String>> entry : projectEnvMap.entrySet()) {
String projectName = entry.getKey();
List<String> envNameList = entry.getValue();
if (StringUtils.isEmpty(projectName) || CollectionUtils.isEmpty(envNameList)) {
continue;
}
if (returnMap.containsKey(projectName)) {
envNameList.forEach(envName -> {
if (!returnMap.get(projectName).contains(envName)) {
returnMap.get(projectName).add(envName);
}
});
} else {
returnMap.put(projectName, envNameList);
}
}
});
}
return returnMap;
}
public LinkedHashMap<String, List<String>> getProjectEnvMapByEnvConfig(String envConfig) {
LinkedHashMap<String, List<String>> returnMap = new LinkedHashMap<>();
//运行设置中选择的环境信息批量执行时在前台选择了执行信息
Map<String, String> envMapByRunConfig = null;
//执行时选择的环境信息 一般在集合报告中会记录
Map<String, List<String>> envMapByExecution = null;
try {
JSONObject jsonObject = JSONObject.parseObject(envConfig);
if (jsonObject.containsKey("executionEnvironmentMap")) {
RunModeConfigWithEnvironmentDTO configWithEnvironment = JSONObject.parseObject(envConfig, RunModeConfigWithEnvironmentDTO.class);
if (MapUtils.isNotEmpty(configWithEnvironment.getExecutionEnvironmentMap())) {
envMapByExecution = configWithEnvironment.getExecutionEnvironmentMap();
} else {
envMapByRunConfig = configWithEnvironment.getEnvMap();
}
} else {
RunModeConfigDTO config = JSONObject.parseObject(envConfig, RunModeConfigDTO.class);
envMapByRunConfig = config.getEnvMap();
}
} catch (Exception e) {
LogUtil.error("解析RunModeConfig失败!参数:" + envConfig, e);
}
returnMap.putAll(this.selectProjectNameAndEnvName(envMapByExecution));
if (MapUtils.isNotEmpty(envMapByRunConfig)) {
for (Map.Entry<String, String> entry : envMapByRunConfig.entrySet()) {
String projectId = entry.getKey();
String envId = entry.getValue();
String projectName = projectService.selectNameById(projectId);
String envName = apiTestEnvironmentService.selectNameById(envId);
if (StringUtils.isNoneEmpty(projectName, envName)) {
returnMap.put(projectName, new ArrayList<>() {{
this.add(envName);
}});
}
}
}
return returnMap;
}
} }

View File

@ -523,4 +523,12 @@ public class ApiDefinitionExecResultService {
}); });
return list; return list;
} }
public List<ApiDefinitionExecResultWithBLOBs> selectByResourceIdsAndMaxCreateTime(List<String> resourceIds) {
if (CollectionUtils.isNotEmpty(resourceIds)) {
return extApiDefinitionExecResultMapper.selectByResourceIdsAndMaxCreateTime(resourceIds);
} else {
return new ArrayList<>();
}
}
} }

View File

@ -156,6 +156,9 @@ public class ApiDefinitionService {
private ApiModuleService apiModuleService; private ApiModuleService apiModuleService;
@Resource @Resource
private ApiTestEnvironmentService apiTestEnvironmentService; private ApiTestEnvironmentService apiTestEnvironmentService;
@Lazy
@Resource
private ProjectService projectService;
private ThreadLocal<Long> currentApiOrder = new ThreadLocal<>(); private ThreadLocal<Long> currentApiOrder = new ThreadLocal<>();
private ThreadLocal<Long> currentApiCaseOrder = new ThreadLocal<>(); private ThreadLocal<Long> currentApiCaseOrder = new ThreadLocal<>();
@ -1344,6 +1347,27 @@ public class ApiDefinitionService {
return reportResult; return reportResult;
} }
public Map<String, List<String>> getProjectEnvNameByEnvConfig(String projectId, String envConfig) {
Map<String, List<String>> returnMap = new HashMap<>();
RunModeConfigDTO runModeConfigDTO = null;
try {
runModeConfigDTO = JSONObject.parseObject(envConfig, RunModeConfigDTO.class);
} catch (Exception e) {
LogUtil.error("解析" + envConfig + "为RunModeConfigDTO时失败", e);
}
if (StringUtils.isNotEmpty(projectId) && runModeConfigDTO != null && MapUtils.isNotEmpty(runModeConfigDTO.getEnvMap())) {
String envId = runModeConfigDTO.getEnvMap().get(projectId);
String envName = apiTestEnvironmentService.selectNameById(envId);
String projectName = projectService.selectNameById(projectId);
if (StringUtils.isNoneEmpty(envName, projectName)) {
returnMap.put(projectName, new ArrayList<>() {{
this.add(envName);
}});
}
}
return returnMap;
}
public String getEnvNameByEnvConfig(String projectId, String envConfig) { public String getEnvNameByEnvConfig(String projectId, String envConfig) {
String envName = null; String envName = null;
RunModeConfigDTO runModeConfigDTO = null; RunModeConfigDTO runModeConfigDTO = null;

View File

@ -4,7 +4,10 @@ import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONArray; import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject; import com.alibaba.fastjson.JSONObject;
import com.alibaba.fastjson.parser.Feature; import com.alibaba.fastjson.parser.Feature;
import io.metersphere.api.dto.*; import io.metersphere.api.dto.ApiScenarioReportBaseInfoDTO;
import io.metersphere.api.dto.ApiScenarioReportDTO;
import io.metersphere.api.dto.RequestResultExpandDTO;
import io.metersphere.api.dto.StepTreeDTO;
import io.metersphere.api.exec.scenario.ApiScenarioEnvService; import io.metersphere.api.exec.scenario.ApiScenarioEnvService;
import io.metersphere.api.exec.utils.ResultParseUtil; import io.metersphere.api.exec.utils.ResultParseUtil;
import io.metersphere.api.service.vo.ApiDefinitionExecResultVo; import io.metersphere.api.service.vo.ApiDefinitionExecResultVo;
@ -20,7 +23,6 @@ import io.metersphere.commons.utils.CommonBeanFactory;
import io.metersphere.commons.utils.LogUtil; import io.metersphere.commons.utils.LogUtil;
import io.metersphere.constants.RunModeConstants; import io.metersphere.constants.RunModeConstants;
import io.metersphere.dto.RequestResult; import io.metersphere.dto.RequestResult;
import io.metersphere.dto.RunModeConfigDTO;
import io.metersphere.service.ProjectService; import io.metersphere.service.ProjectService;
import io.metersphere.utils.LoggerUtil; import io.metersphere.utils.LoggerUtil;
import org.apache.commons.collections.CollectionUtils; import org.apache.commons.collections.CollectionUtils;
@ -545,48 +547,12 @@ public class ApiScenarioReportStructureService {
public void initProjectEnvironmentByEnvConfig(ApiScenarioReportDTO dto, String envConfig) { public void initProjectEnvironmentByEnvConfig(ApiScenarioReportDTO dto, String envConfig) {
if (StringUtils.isNotEmpty(envConfig)) { if (StringUtils.isNotEmpty(envConfig)) {
//运行设置中选择的环境信息批量执行时在前台选择了执行信息 LinkedHashMap<String, List<String>> projectEnvMap = apiScenarioEnvService.getProjectEnvMapByEnvConfig(envConfig);
Map<String, String> envMapByRunConfig = null;
//执行时选择的环境信息 一般在集合报告中会记录
Map<String, List<String>> envMapByExecution = null;
try {
JSONObject jsonObject = JSONObject.parseObject(envConfig);
if (jsonObject.containsKey("executionEnvironmentMap")) {
RunModeConfigWithEnvironmentDTO configWithEnvironment = JSONObject.parseObject(envConfig, RunModeConfigWithEnvironmentDTO.class);
if (MapUtils.isNotEmpty(configWithEnvironment.getExecutionEnvironmentMap())) {
envMapByExecution = configWithEnvironment.getExecutionEnvironmentMap();
} else {
envMapByRunConfig = configWithEnvironment.getEnvMap();
}
} else {
RunModeConfigDTO config = JSONObject.parseObject(envConfig, RunModeConfigDTO.class);
envMapByRunConfig = config.getEnvMap();
}
} catch (Exception e) {
LogUtil.error("解析RunModeConfig失败!参数:" + envConfig, e);
}
LinkedHashMap<String, List<String>> projectEnvMap = apiScenarioEnvService.selectProjectNameAndEnvName(envMapByExecution);
if (MapUtils.isNotEmpty(envMapByRunConfig)) {
for (Map.Entry<String, String> entry : envMapByRunConfig.entrySet()) {
String projectId = entry.getKey();
String envId = entry.getValue();
String projectName = projectService.selectNameById(projectId);
String envName = apiTestEnvironmentService.selectNameById(envId);
if (StringUtils.isNoneEmpty(projectName, envName)) {
projectEnvMap.put(projectName, new ArrayList<>() {{
this.add(envName);
}});
}
}
if (MapUtils.isNotEmpty(projectEnvMap)) { if (MapUtils.isNotEmpty(projectEnvMap)) {
dto.setProjectEnvMap(projectEnvMap); dto.setProjectEnvMap(projectEnvMap);
} }
} }
} }
}
private ApiScenarioReportDTO getReport(String reportId, boolean selectContent) { private ApiScenarioReportDTO getReport(String reportId, boolean selectContent) {

View File

@ -2,9 +2,10 @@ package io.metersphere.base.mapper;
import io.metersphere.base.domain.TestPlanApiScenario; import io.metersphere.base.domain.TestPlanApiScenario;
import io.metersphere.base.domain.TestPlanApiScenarioExample; import io.metersphere.base.domain.TestPlanApiScenarioExample;
import java.util.List;
import org.apache.ibatis.annotations.Param; import org.apache.ibatis.annotations.Param;
import java.util.List;
public interface TestPlanApiScenarioMapper { public interface TestPlanApiScenarioMapper {
long countByExample(TestPlanApiScenarioExample example); long countByExample(TestPlanApiScenarioExample example);
@ -33,4 +34,6 @@ public interface TestPlanApiScenarioMapper {
int updateByPrimaryKeyWithBLOBs(TestPlanApiScenario record); int updateByPrimaryKeyWithBLOBs(TestPlanApiScenario record);
int updateByPrimaryKey(TestPlanApiScenario record); int updateByPrimaryKey(TestPlanApiScenario record);
List<String> selectReportEnvConfByResourceIds(@Param("ids") List<String> resourceIds);
} }

View File

@ -37,7 +37,8 @@
</when> </when>
<when test="criterion.listValue"> <when test="criterion.listValue">
and ${criterion.condition} and ${criterion.condition}
<foreach close=")" collection="criterion.value" item="listItem" open="(" separator=","> <foreach close=")" collection="criterion.value" item="listItem" open="("
separator=",">
#{listItem} #{listItem}
</foreach> </foreach>
</when> </when>
@ -66,7 +67,8 @@
</when> </when>
<when test="criterion.listValue"> <when test="criterion.listValue">
and ${criterion.condition} and ${criterion.condition}
<foreach close=")" collection="criterion.value" item="listItem" open="(" separator=","> <foreach close=")" collection="criterion.value" item="listItem" open="("
separator=",">
#{listItem} #{listItem}
</foreach> </foreach>
</when> </when>
@ -78,13 +80,15 @@
</where> </where>
</sql> </sql>
<sql id="Base_Column_List"> <sql id="Base_Column_List">
id, test_plan_id, api_scenario_id, `status`, create_time, update_time, pass_rate, id
, test_plan_id, api_scenario_id, `status`, create_time, update_time, pass_rate,
last_result, report_id, create_user, `order`, environment_type, environment_group_id last_result, report_id, create_user, `order`, environment_type, environment_group_id
</sql> </sql>
<sql id="Blob_Column_List"> <sql id="Blob_Column_List">
environment environment
</sql> </sql>
<select id="selectByExampleWithBLOBs" parameterType="io.metersphere.base.domain.TestPlanApiScenarioExample" resultMap="ResultMapWithBLOBs"> <select id="selectByExampleWithBLOBs" parameterType="io.metersphere.base.domain.TestPlanApiScenarioExample"
resultMap="ResultMapWithBLOBs">
select select
<if test="distinct"> <if test="distinct">
distinct distinct
@ -100,7 +104,8 @@
order by ${orderByClause} order by ${orderByClause}
</if> </if>
</select> </select>
<select id="selectByExample" parameterType="io.metersphere.base.domain.TestPlanApiScenarioExample" resultMap="BaseResultMap"> <select id="selectByExample" parameterType="io.metersphere.base.domain.TestPlanApiScenarioExample"
resultMap="BaseResultMap">
select select
<if test="distinct"> <if test="distinct">
distinct distinct
@ -123,7 +128,8 @@
where id = #{id,jdbcType=VARCHAR} where id = #{id,jdbcType=VARCHAR}
</select> </select>
<delete id="deleteByPrimaryKey" parameterType="java.lang.String"> <delete id="deleteByPrimaryKey" parameterType="java.lang.String">
delete from test_plan_api_scenario delete
from test_plan_api_scenario
where id = #{id,jdbcType=VARCHAR} where id = #{id,jdbcType=VARCHAR}
</delete> </delete>
<delete id="deleteByExample" parameterType="io.metersphere.base.domain.TestPlanApiScenarioExample"> <delete id="deleteByExample" parameterType="io.metersphere.base.domain.TestPlanApiScenarioExample">
@ -235,12 +241,22 @@
</if> </if>
</trim> </trim>
</insert> </insert>
<select id="countByExample" parameterType="io.metersphere.base.domain.TestPlanApiScenarioExample" resultType="java.lang.Long"> <select id="countByExample" parameterType="io.metersphere.base.domain.TestPlanApiScenarioExample"
resultType="java.lang.Long">
select count(*) from test_plan_api_scenario select count(*) from test_plan_api_scenario
<if test="_parameter != null"> <if test="_parameter != null">
<include refid="Example_Where_Clause"/> <include refid="Example_Where_Clause"/>
</if> </if>
</select> </select>
<select id="selectReportEnvConfByResourceIds" resultType="java.lang.String">
SELECT env_config FROM api_scenario_report WHERE id IN (
select report_id FROM test_plan_api_scenario WHERE id IN
<foreach collection="ids" item="id" separator="," open="(" close=")">
#{id}
</foreach>
)
</select>
<update id="updateByExampleSelective" parameterType="map"> <update id="updateByExampleSelective" parameterType="map">
update test_plan_api_scenario update test_plan_api_scenario
<set> <set>

View File

@ -56,4 +56,6 @@ public interface ExtApiDefinitionExecResultMapper {
List<ApiDefinitionExecResultWithBLOBs> selectRerunResult(@Param("reportId") String reportId); List<ApiDefinitionExecResultWithBLOBs> selectRerunResult(@Param("reportId") String reportId);
List<String> selectByProjectIdAndLessThanTime(@Param("projectId") String projectId, @Param("time") long time); List<String> selectByProjectIdAndLessThanTime(@Param("projectId") String projectId, @Param("time") long time);
List<ApiDefinitionExecResultWithBLOBs> selectByResourceIdsAndMaxCreateTime(@Param("ids") List<String> resourceIds);
} }

View File

@ -416,6 +416,17 @@
</foreach> </foreach>
</update> </update>
<select id="selectByResourceIdsAndMaxCreateTime"
resultType="io.metersphere.base.domain.ApiDefinitionExecResultWithBLOBs">
SELECT resource_id,max(create_time) AS create_time, id, env_config, project_id FROM api_definition_exec_result
WHERE
resource_id IN
<foreach collection="ids" item="id" separator="," open="(" close=")">
#{id}
</foreach>
GROUP BY resource_id;
</select>
<select id="findByProjectIds" resultType="io.metersphere.base.domain.ApiDefinitionExecResult" <select id="findByProjectIds" resultType="io.metersphere.base.domain.ApiDefinitionExecResult"
parameterType="java.lang.String"> parameterType="java.lang.String">
select actuator ,id from api_definition_exec_result where status in ("running","starting","waiting") and select actuator ,id from api_definition_exec_result where status in ("running","starting","waiting") and
@ -431,10 +442,8 @@
</select> </select>
<select id="selectRerunResult" resultType="io.metersphere.base.domain.ApiDefinitionExecResultWithBLOBs"> <select id="selectRerunResult" resultType="io.metersphere.base.domain.ApiDefinitionExecResultWithBLOBs">
SELECT SELECT r.*
r.* FROM api_definition_exec_result r
FROM
api_definition_exec_result r
INNER JOIN api_test_case c ON r.resource_id = c.id INNER JOIN api_test_case c ON r.resource_id = c.id
AND c.`status` != 'Trash' AND c.`status` != 'Trash'
WHERE WHERE
@ -444,7 +453,10 @@
r.create_time ASC r.create_time ASC
</select> </select>
<select id="selectByProjectIdAndLessThanTime" resultType="java.lang.String"> <select id="selectByProjectIdAndLessThanTime" resultType="java.lang.String">
select id from api_definition_exec_result where project_id = #{projectId} and create_time &lt; #{time} select id
from api_definition_exec_result
where project_id = #{projectId}
and create_time &lt; #{time}
</select> </select>
</mapper> </mapper>

View File

@ -10,7 +10,9 @@ import io.metersphere.api.dto.definition.ApiTestCaseRequest;
import io.metersphere.api.dto.definition.BatchRunDefinitionRequest; import io.metersphere.api.dto.definition.BatchRunDefinitionRequest;
import io.metersphere.api.dto.definition.TestPlanApiCaseDTO; import io.metersphere.api.dto.definition.TestPlanApiCaseDTO;
import io.metersphere.api.exec.api.ApiCaseExecuteService; import io.metersphere.api.exec.api.ApiCaseExecuteService;
import io.metersphere.api.exec.scenario.ApiScenarioEnvService;
import io.metersphere.api.service.ApiDefinitionExecResultService; import io.metersphere.api.service.ApiDefinitionExecResultService;
import io.metersphere.api.service.ApiDefinitionService;
import io.metersphere.api.service.ApiTestCaseService; import io.metersphere.api.service.ApiTestCaseService;
import io.metersphere.base.domain.*; import io.metersphere.base.domain.*;
import io.metersphere.base.mapper.ApiTestCaseMapper; import io.metersphere.base.mapper.ApiTestCaseMapper;
@ -29,6 +31,7 @@ import io.metersphere.track.dto.TestCaseReportStatusResultDTO;
import io.metersphere.track.dto.TestPlanApiResultReportDTO; import io.metersphere.track.dto.TestPlanApiResultReportDTO;
import io.metersphere.track.dto.TestPlanSimpleReportDTO; import io.metersphere.track.dto.TestPlanSimpleReportDTO;
import io.metersphere.track.request.testcase.TestPlanApiCaseBatchRequest; import io.metersphere.track.request.testcase.TestPlanApiCaseBatchRequest;
import org.apache.commons.collections.MapUtils;
import org.apache.commons.lang3.StringUtils; import org.apache.commons.lang3.StringUtils;
import org.apache.ibatis.session.ExecutorType; import org.apache.ibatis.session.ExecutorType;
import org.apache.ibatis.session.SqlSession; import org.apache.ibatis.session.SqlSession;
@ -69,6 +72,11 @@ public class TestPlanApiCaseService {
private TestPlanService testPlanService; private TestPlanService testPlanService;
@Resource @Resource
private EnvironmentGroupProjectService environmentGroupProjectService; private EnvironmentGroupProjectService environmentGroupProjectService;
@Resource
private ApiDefinitionService apiDefinitionService;
@Resource
private ApiScenarioEnvService apiScenarioEnvService;
public TestPlanApiCase getInfo(String caseId, String testPlanId) { public TestPlanApiCase getInfo(String caseId, String testPlanId) {
TestPlanApiCaseExample example = new TestPlanApiCaseExample(); TestPlanApiCaseExample example = new TestPlanApiCaseExample();
@ -368,9 +376,66 @@ public class TestPlanApiCaseService {
return extTestPlanApiCaseMapper.getApiTestCaseById(testPlanApiCaseId); return extTestPlanApiCaseMapper.getApiTestCaseById(testPlanApiCaseId);
} }
/**
* 计算测试计划中接口用例的相关数据
*
* @param planId
* @param report
* @return 接口用例的最新执行报告
*/
public void calculatePlanReport(String planId, TestPlanSimpleReportDTO report) { public void calculatePlanReport(String planId, TestPlanSimpleReportDTO report) {
List<PlanReportCaseDTO> planReportCaseDTOS = extTestPlanApiCaseMapper.selectForPlanReport(planId); List<PlanReportCaseDTO> planReportCaseDTOS = extTestPlanApiCaseMapper.selectForPlanReport(planId);
//计算测试计划中接口用例的相关数据
calculatePlanReport(report, planReportCaseDTOS); calculatePlanReport(report, planReportCaseDTOS);
//记录接口用例的运行环境信息
List<String> idList = planReportCaseDTOS.stream().map(PlanReportCaseDTO::getId).collect(Collectors.toList());
this.initProjectEnvironment(report, idList, "ApiCase");
}
/**
* 初始化项目环境信息
*
* @param report
* @param resourceIds 资源ID
* @param resourceType 资源类型 ApiCase/Scenario
*/
public void initProjectEnvironment(TestPlanSimpleReportDTO report, List<String> resourceIds, String resourceType) {
if (!CollectionUtils.isEmpty(resourceIds)) {
if (StringUtils.equalsIgnoreCase("ApiCase", resourceType)) {
List<ApiDefinitionExecResultWithBLOBs> execResults = apiDefinitionExecResultService.selectByResourceIdsAndMaxCreateTime(resourceIds);
execResults.forEach(item -> {
String envConf = item.getEnvConfig();
String projectId = item.getProjectId();
Map<String, List<String>> projectEnvMap = apiDefinitionService.getProjectEnvNameByEnvConfig(projectId, envConf);
this.setProjectEnvMap(report, projectEnvMap);
});
} else if (StringUtils.equalsIgnoreCase("Scenario", resourceType)) {
Map<String, List<String>> projectEnvMap = apiScenarioEnvService.selectProjectEnvMapByTestPlanScenarioIds(resourceIds);
this.setProjectEnvMap(report, projectEnvMap);
}
}
}
private void setProjectEnvMap(TestPlanSimpleReportDTO report, Map<String, List<String>> projectEnvMap) {
if (report != null && MapUtils.isNotEmpty(projectEnvMap)) {
if (report.getProjectEnvMap() == null) {
report.setProjectEnvMap(new LinkedHashMap<>());
}
for (Map.Entry<String, List<String>> entry : projectEnvMap.entrySet()) {
String projectName = entry.getKey();
List<String> envNameList = entry.getValue();
if (report.getProjectEnvMap().containsKey(projectName)) {
envNameList.forEach(envName -> {
if (!report.getProjectEnvMap().get(projectName).contains(envName)) {
report.getProjectEnvMap().get(projectName).add(envName);
}
});
} else {
report.getProjectEnvMap().put(projectName, envNameList);
}
}
}
} }
public void calculatePlanReport(List<String> apiReportIds, TestPlanSimpleReportDTO report) { public void calculatePlanReport(List<String> apiReportIds, TestPlanSimpleReportDTO report) {

View File

@ -72,6 +72,8 @@ public class TestPlanScenarioCaseService {
private TestPlanService testPlanService; private TestPlanService testPlanService;
@Resource @Resource
private ProjectApplicationService projectApplicationService; private ProjectApplicationService projectApplicationService;
@Resource
private TestPlanApiCaseService testPlanApiCaseService;
public List<ApiScenarioDTO> list(TestPlanScenarioRequest request) { public List<ApiScenarioDTO> list(TestPlanScenarioRequest request) {
request.setProjectId(null); request.setProjectId(null);
@ -492,6 +494,9 @@ public class TestPlanScenarioCaseService {
public void calculatePlanReport(String planId, TestPlanSimpleReportDTO report) { public void calculatePlanReport(String planId, TestPlanSimpleReportDTO report) {
List<PlanReportCaseDTO> planReportCaseDTOS = extTestPlanScenarioCaseMapper.selectForPlanReport(planId); List<PlanReportCaseDTO> planReportCaseDTOS = extTestPlanScenarioCaseMapper.selectForPlanReport(planId);
calculatePlanReport(report, planReportCaseDTOS); calculatePlanReport(report, planReportCaseDTOS);
//记录接口用例的运行环境信息
List<String> idList = planReportCaseDTOS.stream().map(PlanReportCaseDTO::getId).collect(Collectors.toList());
testPlanApiCaseService.initProjectEnvironment(report, idList, "Scenario");
} }
public void calculatePlanReport(List<String> reportIds, TestPlanSimpleReportDTO report) { public void calculatePlanReport(List<String> reportIds, TestPlanSimpleReportDTO report) {

View File

@ -60,7 +60,8 @@
</template> </template>
<template v-slot:button v-if="!ifFromVariableAdvance"> <template v-slot:button v-if="!ifFromVariableAdvance">
<el-tooltip :content="$t('api_test.run')" placement="top" v-if="!loading"> <el-tooltip :content="$t('api_test.run')" placement="top" v-if="!loading">
<el-button :disabled="!request.enable" @click="run" icon="el-icon-video-play" class="ms-btn" size="mini" circle/> <el-button :disabled="!request.enable" @click="run" icon="el-icon-video-play" class="ms-btn" size="mini"
circle/>
</el-tooltip> </el-tooltip>
<el-tooltip :content="$t('report.stop_btn')" placement="top" :enterable="false" v-else> <el-tooltip :content="$t('report.stop_btn')" placement="top" :enterable="false" v-else>
<el-button @click.once="stop" size="mini" style="color:white;padding: 0 0.1px;width: 24px;height: 24px;" <el-button @click.once="stop" size="mini" style="color:white;padding: 0 0.1px;width: 24px;height: 24px;"
@ -167,7 +168,7 @@
</template> </template>
<script> <script>
import {getUUID, getCurrentProjectID, getCurrentWorkspaceId} from "@/common/js/utils"; import {getCurrentProjectID, getCurrentWorkspaceId, getUUID} from "@/common/js/utils";
import {getUrl} from "@/business/components/api/automation/scenario/component/urlhelper"; import {getUrl} from "@/business/components/api/automation/scenario/component/urlhelper";
const requireComponent = require.context('@/business/components/xpack/', true, /\.vue$/); const requireComponent = require.context('@/business/components/xpack/', true, /\.vue$/);
@ -645,7 +646,7 @@ export default {
resource.protocol = 'DUBBO' resource.protocol = 'DUBBO'
} }
let definitionData = this.$router.resolve({ let definitionData = this.$router.resolve({
name: 'ApiDefinition', name: 'ApiDefinitionWithQuery',
params: { params: {
redirectID: getUUID(), redirectID: getUUID(),
dataType: "api", dataType: "api",

View File

@ -32,9 +32,14 @@
</template> </template>
<template v-slot:behindHeaderLeft> <template v-slot:behindHeaderLeft>
<el-tag size="small" class="ms-tag" v-if="scenario.referenced==='Deleted'" type="danger">{{ $t('api_test.automation.reference_deleted') }}</el-tag> <el-tag size="small" class="ms-tag" v-if="scenario.referenced==='Deleted'" type="danger">
{{ $t('api_test.automation.reference_deleted') }}
</el-tag>
<el-tag size="small" class="ms-tag" v-if="scenario.referenced==='Copy'">{{ $t('commons.copy') }}</el-tag> <el-tag size="small" class="ms-tag" v-if="scenario.referenced==='Copy'">{{ $t('commons.copy') }}</el-tag>
<el-tag size="small" class="ms-tag" v-if="scenario.referenced==='REF'">{{ $t('api_test.scenario.reference') }}</el-tag> <el-tag size="small" class="ms-tag" v-if="scenario.referenced==='REF'">{{
$t('api_test.scenario.reference')
}}
</el-tag>
<span class="ms-tag ms-step-name-api">{{ getProjectName(scenario.projectId) }}</span> <span class="ms-tag ms-step-name-api">{{ getProjectName(scenario.projectId) }}</span>
</template> </template>
<template v-slot:debugStepCode> <template v-slot:debugStepCode>
@ -42,16 +47,19 @@
<i class="el-icon-loading" style="font-size: 16px"/> <i class="el-icon-loading" style="font-size: 16px"/>
{{ $t('commons.testing') }} {{ $t('commons.testing') }}
</span> </span>
<span class="ms-step-debug-code" :class="node.data.code ==='error'?'ms-req-error':'ms-req-success'" v-if="!loading && node.data.debug && !node.data.testing"> <span class="ms-step-debug-code" :class="node.data.code ==='error'?'ms-req-error':'ms-req-success'"
v-if="!loading && node.data.debug && !node.data.testing">
{{ getCode() }} {{ getCode() }}
</span> </span>
</template> </template>
<template v-slot:button v-if="!ifFromVariableAdvance"> <template v-slot:button v-if="!ifFromVariableAdvance">
<el-tooltip :content="$t('api_test.run')" placement="top" v-if="!scenario.run"> <el-tooltip :content="$t('api_test.run')" placement="top" v-if="!scenario.run">
<el-button :disabled="!scenario.enable" @click="run" icon="el-icon-video-play" style="padding: 5px" class="ms-btn" size="mini" circle/> <el-button :disabled="!scenario.enable" @click="run" icon="el-icon-video-play" style="padding: 5px"
class="ms-btn" size="mini" circle/>
</el-tooltip> </el-tooltip>
<el-tooltip :content="$t('report.stop_btn')" placement="top" :enterable="false" v-else> <el-tooltip :content="$t('report.stop_btn')" placement="top" :enterable="false" v-else>
<el-button :disabled="!scenario.enable" @click.once="stop" size="mini" style="color:white;padding: 0 0.1px;width: 24px;height: 24px;" class="stop-btn" circle> <el-button :disabled="!scenario.enable" @click.once="stop" size="mini"
style="color:white;padding: 0 0.1px;width: 24px;height: 24px;" class="stop-btn" circle>
<div style="transform: scale(0.66)"> <div style="transform: scale(0.66)">
<span style="margin-left: -4.5px;font-weight: bold;">STOP</span> <span style="margin-left: -4.5px;font-weight: bold;">STOP</span>
</div> </div>
@ -286,8 +294,14 @@ export default {
}, },
gotoTurn(resource, workspaceId, isTurnSpace) { gotoTurn(resource, workspaceId, isTurnSpace) {
let automationData = this.$router.resolve({ let automationData = this.$router.resolve({
name: 'ApiAutomation', name: 'ApiAutomationWithQuery',
params: {redirectID: getUUID(), dataType: "scenario", dataSelectRange: 'edit:' + resource.id, projectId: resource.projectId, workspaceId: workspaceId} params: {
redirectID: getUUID(),
dataType: "scenario",
dataSelectRange: 'edit:' + resource.id,
projectId: resource.projectId,
workspaceId: workspaceId
}
}); });
if (isTurnSpace) { if (isTurnSpace) {
window.open(automationData.href, '_blank'); window.open(automationData.href, '_blank');

View File

@ -6,7 +6,7 @@
</el-form-item> </el-form-item>
<el-row type="flex" class="select-time" <el-row type="flex" class="select-time"
v-if="report.envGroupName || report.projectEnvMap"> v-if="report.envGroupName || report.projectEnvMap">
<span> {{ $t('commons.environment') + ':' }} </span> <el-form-item :label="$t('commons.environment') + ':'" style="width: 100%">
<div v-if="report.envGroupName" style="margin-left: 12px"> <div v-if="report.envGroupName" style="margin-left: 12px">
<ms-tag type="danger" :content="$t('commons.group')"></ms-tag> <ms-tag type="danger" :content="$t('commons.group')"></ms-tag>
{{ report.envGroupName }} {{ report.envGroupName }}
@ -18,6 +18,7 @@
style="margin-left: 2px"/> style="margin-left: 2px"/>
</div> </div>
</div> </div>
</el-form-item>
</el-row> </el-row>
<el-row type="flex" justify="space-between" class="select-time"> <el-row type="flex" justify="space-between" class="select-time">
<el-col :span="8"> <el-col :span="8">