fix(接口测试): 接口执行脚本没有设置项目参数

This commit is contained in:
AgAngle 2024-04-07 14:34:05 +08:00 committed by 刘瑞斌
parent c97d58629c
commit 5ceccd1a77
6 changed files with 22 additions and 2 deletions

View File

@ -1,5 +1,5 @@
package io.metersphere.plugin.api.constants;
public enum ElementProperty {
MS_RESOURCE_ID, MS_STEP_ID, MS_FAKE_ERROR, MS_REPORT_ID, PROJECT_ID,SCENARIO_CONSTANT_TIMER
MS_RESOURCE_ID, MS_STEP_ID, MS_FAKE_ERROR, MS_REPORT_ID, PROJECT_ID, SCENARIO_CONSTANT_TIMER
}

View File

@ -42,6 +42,11 @@ public class ApiScenarioScheduleJob extends BaseScheduleJob {
parseParam.setEnvironmentId(apiRunModeConfigDTO.getEnvironmentId());
parseParam.setGrouped(apiRunModeConfigDTO.getGrouped());
if (StringUtils.isBlank(apiRunModeConfigDTO.getEnvironmentId())) {
parseParam.setEnvironmentId(apiScenarioDetail.getEnvironmentId());
parseParam.setGrouped(apiScenarioDetail.getGrouped());
}
if (StringUtils.isBlank(apiRunModeConfigDTO.getPoolId())) {
apiRunModeConfigDTO.setPoolId(apiExecuteService.getProjectApiResourcePoolId(apiScenarioDetail.getProjectId()));
}

View File

@ -42,6 +42,7 @@ public class MsCommonElementConverter extends AbstractJmeterElementConverter<MsC
@Override
public void toHashTree(HashTree tree, MsCommonElement element, ParameterConfig config) {
element.setProjectId(element.getParent().getProjectId());
EnvironmentInfoDTO envInfo = getEnvInfo(element, config);
// 解析前置处理器包括环境前置
addProcessors(tree, element, config, envInfo, true);
@ -78,7 +79,10 @@ public class MsCommonElementConverter extends AbstractJmeterElementConverter<MsC
}
assertionConfig.getAssertions()
.forEach(assertion -> AssertionConverterFactory.getConverter(assertion.getClass()).parse(tree, assertion, config, isIgnoreAssertStatus(assertions)));
.forEach(assertion -> {
assertion.setProjectId(element.getProjectId());
AssertionConverterFactory.getConverter(assertion.getClass()).parse(tree, assertion, config, isIgnoreAssertStatus(assertions));
});
}
/**

View File

@ -255,6 +255,7 @@ public class ApiExecuteService {
MsScriptElement msScriptElement = new MsScriptElement();
msScriptElement.setEnableCommonScript(true);
msScriptElement.setName(runRequest.getReportId());
msScriptElement.setProjectId(runRequest.getProjectId());
CommonScriptInfo commonScriptInfo = new CommonScriptInfo();
commonScriptInfo.setId(runRequest.getProjectId());
commonScriptInfo.setParams(runRequest.getParams());

View File

@ -2098,6 +2098,11 @@ public class ApiScenarioService extends MoveNodeService {
if (isRefOrPartialScenario(step)) {
List<ApiScenarioStepDTO> scenarioSteps = scenarioStepMap.get(step.getResourceId());
if (CollectionUtils.isEmpty(scenarioSteps)) {
continue;
}
scenarioSteps.forEach(item -> {
// 如果步骤的场景ID不等于当前场景的ID说明是引用的步骤如果 parentId 为空说明是一级子步骤重新挂载到对应的场景中
if (StringUtils.isEmpty(item.getParentId())) {

View File

@ -43,4 +43,9 @@ public abstract class MsAssertion {
* id
*/
private String id;
/**
* 项目ID
* 执行时设置
*/
private String projectId;
}