feat(接口自动化): 共享cookie
This commit is contained in:
parent
419d5b2129
commit
23f0c5d116
|
@ -44,10 +44,14 @@ public class MsScenario extends MsTestElement {
|
|||
@JSONField(ordinal = 23)
|
||||
private List<KeyValue> variables;
|
||||
|
||||
@JSONField(ordinal = 24)
|
||||
private boolean enableCookieShare;
|
||||
|
||||
public void toHashTree(HashTree tree, List<MsTestElement> hashTree, ParameterConfig config) {
|
||||
if (!this.isEnable()) {
|
||||
return;
|
||||
}
|
||||
config.setEnableCookieShare(enableCookieShare);
|
||||
if (StringUtils.isNotEmpty(environmentId)) {
|
||||
ApiTestEnvironmentService environmentService = CommonBeanFactory.getBean(ApiTestEnvironmentService.class);
|
||||
ApiTestEnvironmentWithBLOBs environment = environmentService.get(environmentId);
|
||||
|
|
|
@ -5,6 +5,7 @@ import lombok.Data;
|
|||
import lombok.EqualsAndHashCode;
|
||||
import org.apache.commons.collections.CollectionUtils;
|
||||
import org.apache.jmeter.control.LoopController;
|
||||
import org.apache.jmeter.protocol.http.control.CookieManager;
|
||||
import org.apache.jmeter.save.SaveService;
|
||||
import org.apache.jmeter.testelement.TestElement;
|
||||
import org.apache.jmeter.threads.ThreadGroup;
|
||||
|
@ -17,9 +18,17 @@ import java.util.List;
|
|||
@JSONType(typeName = "ThreadGroup")
|
||||
public class MsThreadGroup extends MsTestElement {
|
||||
private String type = "ThreadGroup";
|
||||
private boolean enableCookieShare;
|
||||
|
||||
public void toHashTree(HashTree tree, List<MsTestElement> hashTree, ParameterConfig config) {
|
||||
final HashTree groupTree = tree.add(getThreadGroup());
|
||||
if ((config != null && config.isEnableCookieShare()) || enableCookieShare) {
|
||||
CookieManager cookieManager = new CookieManager();
|
||||
cookieManager.setName("CookieManager");
|
||||
cookieManager.setClearEachIteration(false);
|
||||
cookieManager.setControlledByThread(false);
|
||||
groupTree.add(cookieManager);
|
||||
}
|
||||
if (CollectionUtils.isNotEmpty(hashTree)) {
|
||||
hashTree.forEach(el -> {
|
||||
el.toHashTree(groupTree, el.getHashTree(), config);
|
||||
|
|
|
@ -12,4 +12,7 @@ public class ParameterConfig {
|
|||
private EnvironmentConfig config;
|
||||
// 公共场景参数
|
||||
private List<KeyValue> variables;
|
||||
// 公共Cookie
|
||||
private boolean enableCookieShare;
|
||||
|
||||
}
|
||||
|
|
|
@ -1 +1 @@
|
|||
Subproject commit b5643ac73fb4a2db3f11b23a81848990d8e78703
|
||||
Subproject commit 61397c16728a63493507679f7e0940d9099f337f
|
|
@ -93,6 +93,7 @@
|
|||
let threadGroup = createComponent('ThreadGroup');
|
||||
threadGroup.hashTree = [];
|
||||
threadGroup.name = this.runData.name ? this.runData.name : "Debug-Scenario";
|
||||
threadGroup.enableCookieShare = this.runData.enableCookieShare;
|
||||
threadGroup.hashTree.push(this.runData);
|
||||
testPlan.hashTree.push(threadGroup);
|
||||
let reqObj = {id: this.reportId, reportId: this.reportId, environmentId: this.environment, testElement: testPlan};
|
||||
|
|
|
@ -123,15 +123,18 @@
|
|||
<el-col :span="6" class="ms-col-one">
|
||||
{{currentScenario.name ===undefined || ''? $t('api_test.scenario.name') : currentScenario.name}}
|
||||
</el-col>
|
||||
<el-col :span="4" class="ms-col-one">
|
||||
<el-col :span="3" class="ms-col-one">
|
||||
{{$t('api_test.automation.step_total')}}:{{scenarioDefinition.length}}
|
||||
</el-col>
|
||||
<el-col :span="4" class="ms-col-one">
|
||||
<el-link style="font-size: 13px" @click="showScenarioParameters">{{$t('api_test.automation.scenario_total')}}:
|
||||
<el-col :span="3" class="ms-col-one">
|
||||
<el-link class="head" @click="showScenarioParameters">{{$t('api_test.automation.scenario_total')}}:
|
||||
{{this.currentScenario.variables!=undefined?this.currentScenario.variables.length-1: 0}}
|
||||
</el-link>
|
||||
</el-col>
|
||||
<el-col :span="8">
|
||||
<el-col :span="3">
|
||||
<el-checkbox v-model="currentScenario.enableCookieShare" style="margin-top: 5px">{{ '共享cookie' }}</el-checkbox>
|
||||
</el-col>
|
||||
<el-col :span="7">
|
||||
{{$t('api_test.definition.request.run_env')}}:
|
||||
<el-select v-model="currentEnvironmentId" size="small" class="ms-htt-width"
|
||||
:placeholder="$t('api_test.definition.request.run_env')"
|
||||
|
@ -588,7 +591,7 @@
|
|||
}
|
||||
this.debugData = {
|
||||
id: this.currentScenario.id, name: this.currentScenario.name, type: "scenario",
|
||||
variables: this.currentScenario.variables, referenced: 'Created',
|
||||
variables: this.currentScenario.variables, referenced: 'Created', enableCookieShare: this.currentScenario.enableCookieShare,
|
||||
environmentId: this.currentEnvironmentId, hashTree: this.scenarioDefinition
|
||||
};
|
||||
this.reportId = getUUID().substring(0, 8);
|
||||
|
@ -732,6 +735,7 @@
|
|||
if (obj) {
|
||||
this.currentEnvironmentId = obj.environmentId;
|
||||
this.currentScenario.variables = obj.variables;
|
||||
this.currentScenario.enableCookieShare = obj.enableCookieShare;
|
||||
this.scenarioDefinition = obj.hashTree;
|
||||
}
|
||||
}
|
||||
|
@ -748,7 +752,7 @@
|
|||
this.currentScenario.modulePath = this.getPath(this.currentScenario.apiScenarioModuleId);
|
||||
// 构建一个场景对象 方便引用处理
|
||||
let scenario = {
|
||||
id: this.currentScenario.id, name: this.currentScenario.name, variables: this.currentScenario.variables,
|
||||
id: this.currentScenario.id, enableCookieShare: this.currentScenario.enableCookieShare, name: this.currentScenario.name, variables: this.currentScenario.variables,
|
||||
type: "scenario", referenced: 'Created', environmentId: this.currentEnvironmentId, hashTree: this.scenarioDefinition
|
||||
};
|
||||
this.currentScenario.scenarioDefinition = scenario;
|
||||
|
@ -909,4 +913,9 @@
|
|||
/deep/ .el-drawer__header {
|
||||
margin-bottom: 0px;
|
||||
}
|
||||
|
||||
.head {
|
||||
border-bottom: 1px solid #dedede;
|
||||
font-size: 13px;
|
||||
}
|
||||
</style>
|
||||
|
|
|
@ -1 +1 @@
|
|||
Subproject commit 010ad7a5f072a5e9d368c756a2473bbd20781433
|
||||
Subproject commit d39dafaf84b9c7a56cb51f2caf67dd7dfde5938c
|
Loading…
Reference in New Issue