feat(接口测试): 断言增加忽略状态

This commit is contained in:
q4speed 2020-10-19 12:59:29 +08:00
parent ae474fadd7
commit fb224d2289
8 changed files with 163 additions and 131 deletions

View File

@ -9,6 +9,7 @@ public class AssertionRegex extends AssertionType {
private String subject; private String subject;
private String expression; private String expression;
private String description; private String description;
private Boolean assumeSuccess;
public AssertionRegex() { public AssertionRegex() {
setType(AssertionType.REGEX); setType(AssertionType.REGEX);

View File

@ -13,8 +13,14 @@
<el-input :disabled="isReadOnly" v-model="regex.expression" size="small" show-word-limit <el-input :disabled="isReadOnly" v-model="regex.expression" size="small" show-word-limit
:placeholder="$t('api_test.request.assertions.expression')"/> :placeholder="$t('api_test.request.assertions.expression')"/>
</el-col> </el-col>
<el-col class="assertion-checkbox">
<el-checkbox v-model="regex.assumeSuccess" :disabled="isReadOnly">
{{ $t('api_test.request.assertions.ignore_status') }}
</el-checkbox>
</el-col>
<el-col class="assertion-btn"> <el-col class="assertion-btn">
<el-button :disabled="isReadOnly" type="danger" size="mini" icon="el-icon-delete" circle @click="remove" v-if="edit"/> <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="small" @click="add" v-else>Add</el-button> <el-button :disabled="isReadOnly" type="primary" size="small" @click="add" v-else>Add</el-button>
</el-col> </el-col>
</el-row> </el-row>
@ -91,6 +97,11 @@
width: 100%; width: 100%;
} }
.assertion-checkbox {
text-align: center;
width: 120px;
}
.assertion-btn { .assertion-btn {
text-align: center; text-align: center;
width: 60px; width: 60px;

View File

@ -23,6 +23,11 @@
<el-input :disabled="isReadOnly" v-model="value" maxlength="200" size="small" show-word-limit <el-input :disabled="isReadOnly" v-model="value" maxlength="200" size="small" show-word-limit
:placeholder="$t('api_test.request.assertions.value')"/> :placeholder="$t('api_test.request.assertions.value')"/>
</el-col> </el-col>
<el-col class="assertion-checkbox">
<el-checkbox v-model="assumeSuccess" :disabled="isReadOnly">
{{ $t('api_test.request.assertions.ignore_status') }}
</el-checkbox>
</el-col>
<el-col class="assertion-btn"> <el-col class="assertion-btn">
<el-button :disabled="isReadOnly" type="primary" size="small" @click="add">Add</el-button> <el-button :disabled="isReadOnly" type="primary" size="small" @click="add">Add</el-button>
</el-col> </el-col>
@ -50,6 +55,7 @@
subjects: ASSERTION_REGEX_SUBJECT, subjects: ASSERTION_REGEX_SUBJECT,
subject: "", subject: "",
condition: "", condition: "",
assumeSuccess: false,
value: "" value: ""
} }
}, },
@ -87,7 +93,8 @@
return new Regex({ return new Regex({
subject: this.subject, subject: this.subject,
expression: expression, expression: expression,
description: description description: description,
assumeSuccess: this.assumeSuccess
} }
); );
} }
@ -104,6 +111,11 @@
width: 100%; width: 100%;
} }
.assertion-checkbox {
text-align: center;
width: 120px;
}
.assertion-btn { .assertion-btn {
width: 60px; width: 60px;
} }

View File

@ -415,7 +415,7 @@ export class ResponseAssertion extends DefaultTestElement {
this.assertion = assertion || {}; this.assertion = assertion || {};
this.stringProp('Assertion.test_field', this.assertion.field); this.stringProp('Assertion.test_field', this.assertion.field);
this.boolProp('Assertion.assume_success', false); this.boolProp('Assertion.assume_success', this.assertion.assumeSuccess);
this.intProp('Assertion.test_type', this.assertion.type); this.intProp('Assertion.test_type', this.assertion.type);
this.stringProp('Assertion.custom_message', this.assertion.message); this.stringProp('Assertion.custom_message', this.assertion.message);
@ -440,11 +440,12 @@ export class JSONPathAssertion extends DefaultTestElement {
} }
export class ResponseCodeAssertion extends ResponseAssertion { export class ResponseCodeAssertion extends ResponseAssertion {
constructor(testName, type, value, message) { constructor(testName, type, value, assumeSuccess, message) {
let assertion = { let assertion = {
field: 'Assertion.response_code', field: 'Assertion.response_code',
type: type, type: type,
value: value, value: value,
assumeSuccess: assumeSuccess,
message: message, message: message,
} }
super(testName, assertion) super(testName, assertion)
@ -452,11 +453,12 @@ export class ResponseCodeAssertion extends ResponseAssertion {
} }
export class ResponseDataAssertion extends ResponseAssertion { export class ResponseDataAssertion extends ResponseAssertion {
constructor(testName, type, value, message) { constructor(testName, type, value, assumeSuccess, message) {
let assertion = { let assertion = {
field: 'Assertion.response_data', field: 'Assertion.response_data',
type: type, type: type,
value: value, value: value,
assumeSuccess: assumeSuccess,
message: message, message: message,
} }
super(testName, assertion) super(testName, assertion)
@ -464,11 +466,12 @@ export class ResponseDataAssertion extends ResponseAssertion {
} }
export class ResponseHeadersAssertion extends ResponseAssertion { export class ResponseHeadersAssertion extends ResponseAssertion {
constructor(testName, type, value, message) { constructor(testName, type, value, assumeSuccess, message) {
let assertion = { let assertion = {
field: 'Assertion.response_headers', field: 'Assertion.response_headers',
type: type, type: type,
value: value, value: value,
assumeSuccess: assumeSuccess,
message: message, message: message,
} }
super(testName, assertion) super(testName, assertion)

View File

@ -785,6 +785,7 @@ export class Regex extends AssertionType {
this.subject = undefined; this.subject = undefined;
this.expression = undefined; this.expression = undefined;
this.description = undefined; this.description = undefined;
this.assumeSuccess = false;
this.set(options); this.set(options);
} }
@ -1423,13 +1424,14 @@ class JMXGenerator {
let name = regex.description; let name = regex.description;
let type = JMX_ASSERTION_CONDITION.CONTAINS; // 固定用Match自己写正则 let type = JMX_ASSERTION_CONDITION.CONTAINS; // 固定用Match自己写正则
let value = regex.expression; let value = regex.expression;
let assumeSuccess = regex.assumeSuccess;
switch (regex.subject) { switch (regex.subject) {
case ASSERTION_REGEX_SUBJECT.RESPONSE_CODE: case ASSERTION_REGEX_SUBJECT.RESPONSE_CODE:
return new ResponseCodeAssertion(name, type, value); return new ResponseCodeAssertion(name, type, value, assumeSuccess);
case ASSERTION_REGEX_SUBJECT.RESPONSE_DATA: case ASSERTION_REGEX_SUBJECT.RESPONSE_DATA:
return new ResponseDataAssertion(name, type, value); return new ResponseDataAssertion(name, type, value, assumeSuccess);
case ASSERTION_REGEX_SUBJECT.RESPONSE_HEADERS: case ASSERTION_REGEX_SUBJECT.RESPONSE_HEADERS:
return new ResponseHeadersAssertion(name, type, value); return new ResponseHeadersAssertion(name, type, value, assumeSuccess);
} }
} }

View File

@ -526,6 +526,7 @@ export default {
expect: "Expect Value", expect: "Expect Value",
expression: "Expression", expression: "Expression",
response_in_time: "Response in time", response_in_time: "Response in time",
ignore_status: "Ignore Status"
}, },
extract: { extract: {
label: "Extract from response", label: "Extract from response",

View File

@ -527,6 +527,7 @@ export default {
expect: "期望值", expect: "期望值",
expression: "Perl型正则表达式", expression: "Perl型正则表达式",
response_in_time: "响应时间在...毫秒以内", response_in_time: "响应时间在...毫秒以内",
ignore_status: "忽略状态"
}, },
extract: { extract: {
label: "提取", label: "提取",

View File

@ -527,6 +527,7 @@ export default {
expect: "期望值", expect: "期望值",
expression: "Perl型正則表達式", expression: "Perl型正則表達式",
response_in_time: "響應時間在...毫秒以內", response_in_time: "響應時間在...毫秒以內",
ignore_status: "忽略狀態"
}, },
extract: { extract: {
label: "提取", label: "提取",