fix(接口测试): 断言增加单步启用禁用操作
--bug=1011471 --user=赵勇 【接口测试】api-test-断言规则设置-断言配置记录无启用/禁用开关 https://www.tapd.cn/55049933/s/1122111
This commit is contained in:
parent
5971675a61
commit
c5717c8cad
|
@ -13,6 +13,6 @@ public class MsAssertionDuration extends MsAssertionType {
|
|||
}
|
||||
|
||||
public boolean isValid() {
|
||||
return value > 0;
|
||||
return value > 0 && isEnable();
|
||||
}
|
||||
}
|
||||
|
|
|
@ -20,6 +20,6 @@ public class MsAssertionJSR223 extends MsAssertionType {
|
|||
}
|
||||
|
||||
public boolean isValid() {
|
||||
return StringUtils.isNotBlank(script) && StringUtils.isNotBlank(scriptLanguage);
|
||||
return StringUtils.isNotBlank(script) && StringUtils.isNotBlank(scriptLanguage) && isEnable();
|
||||
}
|
||||
}
|
||||
|
|
|
@ -17,6 +17,6 @@ public class MsAssertionJsonPath extends MsAssertionType {
|
|||
}
|
||||
|
||||
public boolean isValid() {
|
||||
return StringUtils.isNotBlank(expression);
|
||||
return StringUtils.isNotBlank(expression) && isEnable();
|
||||
}
|
||||
}
|
||||
|
|
|
@ -18,6 +18,6 @@ public class MsAssertionRegex extends MsAssertionType {
|
|||
}
|
||||
|
||||
public boolean isValid() {
|
||||
return StringUtils.isNotBlank(subject) && StringUtils.isNotBlank(expression);
|
||||
return StringUtils.isNotBlank(subject) && StringUtils.isNotBlank(expression) && isEnable();
|
||||
}
|
||||
}
|
||||
|
|
|
@ -10,6 +10,7 @@ public class MsAssertionType {
|
|||
public final static String JSR223 = "JSR223";
|
||||
public final static String TEXT = "Text";
|
||||
public final static String XPATH2 = "XPath2";
|
||||
private boolean enable = true;
|
||||
|
||||
private String type;
|
||||
}
|
||||
|
|
|
@ -14,6 +14,6 @@ public class MsAssertionXPath2 extends MsAssertionType {
|
|||
}
|
||||
|
||||
public boolean isValid() {
|
||||
return StringUtils.isNotBlank(expression);
|
||||
return StringUtils.isNotBlank(expression) && isEnable();
|
||||
}
|
||||
}
|
||||
|
|
|
@ -50,7 +50,7 @@ public class MsAssertions extends MsTestElement {
|
|||
|
||||
private void addAssertions(HashTree hashTree) {
|
||||
// 增加JSON文档结构校验
|
||||
if (this.getDocument() != null && this.getDocument().getType().equals("JSON")) {
|
||||
if (this.getDocument() != null && this.getDocument().getType().equals("JSON") && this.getDocument().isEnable()) {
|
||||
if (StringUtils.isNotEmpty(this.getDocument().getData().getJsonFollowAPI()) && !this.getDocument().getData().getJsonFollowAPI().equals("false")) {
|
||||
ApiDefinitionService apiDefinitionService = CommonBeanFactory.getBean(ApiDefinitionService.class);
|
||||
this.getDocument().getData().setJson(apiDefinitionService.getDocument(this.getDocument().getData().getJsonFollowAPI(), "JSON"));
|
||||
|
@ -60,7 +60,9 @@ public class MsAssertions extends MsTestElement {
|
|||
}
|
||||
}
|
||||
// 增加XML文档结构校验
|
||||
if (this.getDocument() != null && this.getDocument().getType().equals("XML") && CollectionUtils.isNotEmpty(this.getDocument().getData().getXml())) {
|
||||
if (this.getDocument() != null && this.getDocument().getType().equals("XML")
|
||||
&& CollectionUtils.isNotEmpty(this.getDocument().getData().getXml())
|
||||
&& this.getDocument().isEnable()) {
|
||||
if (StringUtils.isNotEmpty(this.getDocument().getData().getXmlFollowAPI()) && !this.getDocument().getData().getXmlFollowAPI().equals("false")) {
|
||||
ApiDefinitionService apiDefinitionService = CommonBeanFactory.getBean(ApiDefinitionService.class);
|
||||
this.getDocument().getData().setXml(apiDefinitionService.getDocument(this.getDocument().getData().getXmlFollowAPI(), "XML"));
|
||||
|
@ -112,8 +114,8 @@ public class MsAssertions extends MsTestElement {
|
|||
assertion.setAssumeSuccess(assertionRegex.isAssumeSuccess());
|
||||
assertion.addTestString(assertionRegex.getExpression());
|
||||
assertion.setToContainsType();
|
||||
if(assertionRegex.getTestType() != 2){
|
||||
assertion.setProperty("Assertion.test_type",assertionRegex.getTestType());
|
||||
if (assertionRegex.getTestType() != 2) {
|
||||
assertion.setProperty("Assertion.test_type", assertionRegex.getTestType());
|
||||
}
|
||||
|
||||
switch (assertionRegex.getSubject()) {
|
||||
|
|
|
@ -4,6 +4,7 @@ import lombok.Data;
|
|||
|
||||
@Data
|
||||
public class MsAssertionDocument {
|
||||
private boolean enable = true;
|
||||
private String type;
|
||||
private Document data;
|
||||
}
|
||||
|
|
|
@ -44,6 +44,35 @@ export function getProtocolFilter(protocolType) {
|
|||
}
|
||||
}
|
||||
|
||||
export function parse(item) {
|
||||
if (item.jsonPath) {
|
||||
item.jsonPath.forEach(node => {
|
||||
node.enable = item.enable;
|
||||
})
|
||||
}
|
||||
if (item.jsr223) {
|
||||
item.jsr223.forEach(node => {
|
||||
node.enable = item.enable;
|
||||
})
|
||||
}
|
||||
if (item.regex) {
|
||||
item.regex.forEach(node => {
|
||||
node.enable = item.enable;
|
||||
});
|
||||
}
|
||||
if (item.xpath2) {
|
||||
item.xpath2.forEach(node => {
|
||||
node.enable = item.enable;
|
||||
})
|
||||
}
|
||||
if (item.duration && item.duration.value > 0) {
|
||||
item.duration.enable = item.enable;
|
||||
}
|
||||
if (item.document && item.document.data && (item.document.data.json.length > 0 || item.document.data.xml.length > 0)) {
|
||||
item.document.enable = item.enable;
|
||||
}
|
||||
}
|
||||
|
||||
export function hisDataProcessing(array, request) {
|
||||
let assertions = new Assertions({id: getUUID()});
|
||||
if (!request.hashTree) {
|
||||
|
@ -56,13 +85,23 @@ export function hisDataProcessing(array, request) {
|
|||
let item = array[index];
|
||||
if (item.type === "Assertions" && isOne) {
|
||||
assertions = JSON.parse(JSON.stringify(item));
|
||||
parse(assertions);
|
||||
isOne = false;
|
||||
assertionsIndex.push(item);
|
||||
} else if (item.type === "Assertions") {
|
||||
assertions.jsonPath.push(...item.jsonPath);
|
||||
assertions.jsr223.push(...item.jsr223);
|
||||
assertions.regex.push(...item.regex);
|
||||
assertions.xpath2.push(...item.xpath2);
|
||||
parse(item);
|
||||
if (item.jsonPath) {
|
||||
assertions.jsonPath.push(...item.jsonPath);
|
||||
}
|
||||
if (item.jsr223) {
|
||||
assertions.jsr223.push(...item.jsr223);
|
||||
}
|
||||
if (item.regex) {
|
||||
assertions.regex.push(...item.regex);
|
||||
}
|
||||
if (item.xpath2) {
|
||||
assertions.xpath2.push(...item.xpath2);
|
||||
}
|
||||
assertionsIndex.push(item);
|
||||
if (item.duration && item.duration.value > 0) {
|
||||
assertions.duration = item.duration;
|
||||
|
|
|
@ -5,7 +5,10 @@
|
|||
<el-input :disabled="isReadOnly" :value="value" v-bind="$attrs" step="100" size="small" type="number" @change="change" @input="input" :min="0"
|
||||
:placeholder="$t('api_test.request.assertions.response_in_time')"/>
|
||||
</el-col>
|
||||
<el-col :class="edit?'assertion-remove-btn': 'assertion-btn'">
|
||||
<el-col class="assertion-btn">
|
||||
<el-tooltip :content="$t('test_resource_pool.enable_disable')" placement="top" v-if="edit">
|
||||
<el-switch v-model="duration.enable" class="enable-switch" size="mini" :disabled="isReadOnly" style="width: 30px;margin-right: 10px"/>
|
||||
</el-tooltip>
|
||||
<el-button :disabled="isReadOnly" type="danger" size="mini" icon="el-icon-delete" circle @click="remove" v-if="edit"/>
|
||||
<el-button :disabled="isReadOnly" type="primary" size="mini" @click="add" v-else>
|
||||
{{ $t('api_test.request.assertions.add') }}
|
||||
|
@ -35,6 +38,7 @@ export default {
|
|||
add() {
|
||||
if (this.validate()) {
|
||||
this.duration.value = this.value;
|
||||
this.duration.enable = true;
|
||||
this.callback();
|
||||
}
|
||||
},
|
||||
|
@ -62,10 +66,6 @@ export default {
|
|||
</script>
|
||||
|
||||
<style scoped>
|
||||
.assertion-remove-btn {
|
||||
text-align: center;
|
||||
width: 40px;
|
||||
}
|
||||
|
||||
.assertion-btn {
|
||||
text-align: center;
|
||||
|
|
|
@ -23,6 +23,9 @@
|
|||
</el-tooltip>
|
||||
</el-col>
|
||||
<el-col class="assertion-btn">
|
||||
<el-tooltip :content="$t('test_resource_pool.enable_disable')" placement="top" v-if="edit">
|
||||
<el-switch v-model="jsonPath.enable" class="enable-switch" size="mini" :disabled="isReadOnly" style="width: 30px;margin-right: 10px"/>
|
||||
</el-tooltip>
|
||||
<el-button :disabled="isReadOnly" type="danger" size="mini" icon="el-icon-delete" circle @click="remove" v-if="edit"/>
|
||||
<el-button :disabled="isReadOnly" type="primary" size="mini" @click="add" v-else>
|
||||
{{ $t('api_test.request.assertions.add') }}
|
||||
|
@ -88,6 +91,7 @@
|
|||
},
|
||||
getJSONPath() {
|
||||
let jsonPath = new JSONPath(this.jsonPath);
|
||||
jsonPath.enable = true;
|
||||
jsonPath.description = jsonPath.expression + " expect: " + (jsonPath.expect ? jsonPath.expect : '');
|
||||
return jsonPath;
|
||||
},
|
||||
|
@ -115,6 +119,6 @@
|
|||
|
||||
.assertion-btn {
|
||||
text-align: center;
|
||||
width: 60px;
|
||||
width: 80px;
|
||||
}
|
||||
</style>
|
||||
|
|
|
@ -20,6 +20,9 @@
|
|||
<div class="assertion-item btn circle">
|
||||
<i class="el-icon-view el-button el-button--primary el-button--mini is-circle" circle @click="showPage"/>
|
||||
<el-button :disabled="isReadOnly" type="success" size="mini" icon="el-icon-edit" circle @click="detail"/>
|
||||
<el-tooltip :content="$t('test_resource_pool.enable_disable')" placement="top">
|
||||
<el-switch v-model="assertion.enable" class="enable-switch" size="mini" :disabled="isReadOnly" style="width: 30px;margin:0px 10px 0px 10px"/>
|
||||
</el-tooltip>
|
||||
<el-button :disabled="isReadOnly" type="danger" size="mini" icon="el-icon-delete" circle @click="remove"/>
|
||||
</div>
|
||||
</el-row>
|
||||
|
|
|
@ -18,7 +18,11 @@
|
|||
{{ $t('api_test.request.assertions.ignore_status') }}
|
||||
</el-checkbox>
|
||||
</el-col>
|
||||
<el-col :class="edit?'assertion-remove-btn':'assertion-btn'">
|
||||
<el-col class="assertion-btn">
|
||||
<el-tooltip :content="$t('test_resource_pool.enable_disable')" placement="top" v-if="edit">
|
||||
<el-switch v-model="regex.enable" class="enable-switch" size="mini" :disabled="isReadOnly" style="width: 30px;margin-right:10px" />
|
||||
</el-tooltip>
|
||||
|
||||
<el-button :disabled="isReadOnly" type="danger" size="mini" icon="el-icon-delete" circle @click="remove"
|
||||
v-if="edit"/>
|
||||
<el-button :disabled="isReadOnly" type="primary" size="mini" @click="add" v-else>
|
||||
|
@ -79,6 +83,7 @@ export default {
|
|||
},
|
||||
getRegex() {
|
||||
let regex = new Regex(this.regex);
|
||||
regex.enable = true;
|
||||
regex.description = regex.subject + " has: " + regex.expression;
|
||||
return regex;
|
||||
},
|
||||
|
@ -107,8 +112,4 @@ export default {
|
|||
text-align: center;
|
||||
width: 80px;
|
||||
}
|
||||
.assertion-remove-btn {
|
||||
text-align: center;
|
||||
width: 50px;
|
||||
}
|
||||
</style>
|
||||
|
|
|
@ -5,7 +5,10 @@
|
|||
<el-input :disabled="isReadOnly" v-model="xPath2.expression" maxlength="500" size="small" show-word-limit
|
||||
:placeholder="$t('api_test.request.extract.xpath_expression')"/>
|
||||
</el-col>
|
||||
<el-col :class="edit?'assertion-remove-btn':'assertion-btn'">
|
||||
<el-col class="assertion-btn">
|
||||
<el-tooltip :content="$t('test_resource_pool.enable_disable')" placement="top" v-if="edit">
|
||||
<el-switch v-model="xPath2.enable" class="enable-switch" size="mini" :disabled="isReadOnly" style="width: 30px;margin-right:10px"/>
|
||||
</el-tooltip>
|
||||
<el-button :disabled="isReadOnly" type="danger" size="mini" icon="el-icon-delete" circle @click="remove" v-if="edit"/>
|
||||
<el-button :disabled="isReadOnly" type="primary" size="mini" @click="add" v-else>
|
||||
{{ $t('api_test.request.assertions.add') }}
|
||||
|
@ -56,21 +59,8 @@ export default {
|
|||
</script>
|
||||
|
||||
<style scoped>
|
||||
.assertion-select {
|
||||
width: 250px;
|
||||
}
|
||||
|
||||
.assertion-item {
|
||||
width: 100%;
|
||||
}
|
||||
|
||||
.assertion-btn {
|
||||
text-align: center;
|
||||
width: 80px;
|
||||
}
|
||||
|
||||
.assertion-remove-btn {
|
||||
text-align: center;
|
||||
width: 40px;
|
||||
}
|
||||
</style>
|
||||
|
|
|
@ -63,6 +63,9 @@
|
|||
{{ assertions.document.type }}-{{ $t("api_test.definition.request.document_structure") }}
|
||||
</el-col>
|
||||
<el-col class="assertion-remove-btn">
|
||||
<el-tooltip :content="$t('test_resource_pool.enable_disable')" placement="top">
|
||||
<el-switch v-model="assertions.enable" class="enable-switch" size="mini" :disabled="assertions.disabled" style="width: 30px;margin-right: 10px"/>
|
||||
</el-tooltip>
|
||||
<el-tooltip effect="dark" :content="$t('commons.remove')" placement="top-start">
|
||||
<el-button icon="el-icon-delete" type="danger" size="mini" circle @click="remove()"
|
||||
:disabled="(assertions.disabled && !assertions.root)"/>
|
||||
|
@ -169,6 +172,6 @@ export default {
|
|||
|
||||
.assertion-remove-btn {
|
||||
text-align: center;
|
||||
width: 40px;
|
||||
width: 80px;
|
||||
}
|
||||
</style>
|
||||
|
|
|
@ -833,7 +833,7 @@ export class AssertionJSR223 extends AssertionType {
|
|||
this.operator = undefined;
|
||||
this.value = undefined;
|
||||
this.desc = undefined;
|
||||
|
||||
this.enable = true;
|
||||
this.name = undefined;
|
||||
this.script = undefined;
|
||||
this.scriptLanguage = "beanshell";
|
||||
|
@ -903,6 +903,7 @@ export class Regex extends AssertionType {
|
|||
this.expression = undefined;
|
||||
this.description = undefined;
|
||||
this.assumeSuccess = false;
|
||||
this.enable = true;
|
||||
|
||||
this.set(options);
|
||||
}
|
||||
|
@ -936,6 +937,7 @@ export class XPath2 extends AssertionType {
|
|||
super(ASSERTION_TYPE.XPATH2);
|
||||
this.expression = undefined;
|
||||
this.description = undefined;
|
||||
this.enable = true;
|
||||
this.set(options);
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue