feat(接口测试): 断言增加忽略状态
This commit is contained in:
parent
ae474fadd7
commit
fb224d2289
|
@ -9,6 +9,7 @@ public class AssertionRegex extends AssertionType {
|
|||
private String subject;
|
||||
private String expression;
|
||||
private String description;
|
||||
private Boolean assumeSuccess;
|
||||
|
||||
public AssertionRegex() {
|
||||
setType(AssertionType.REGEX);
|
||||
|
|
|
@ -13,8 +13,14 @@
|
|||
<el-input :disabled="isReadOnly" v-model="regex.expression" size="small" show-word-limit
|
||||
:placeholder="$t('api_test.request.assertions.expression')"/>
|
||||
</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-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-col>
|
||||
</el-row>
|
||||
|
@ -22,77 +28,82 @@
|
|||
</template>
|
||||
|
||||
<script>
|
||||
import {ASSERTION_REGEX_SUBJECT, Regex} from "../../model/ScenarioModel";
|
||||
import {ASSERTION_REGEX_SUBJECT, Regex} from "../../model/ScenarioModel";
|
||||
|
||||
export default {
|
||||
name: "MsApiAssertionRegex",
|
||||
export default {
|
||||
name: "MsApiAssertionRegex",
|
||||
|
||||
props: {
|
||||
regex: {
|
||||
type: Regex,
|
||||
default: () => {
|
||||
return new Regex();
|
||||
}
|
||||
},
|
||||
edit: {
|
||||
type: Boolean,
|
||||
default: false
|
||||
},
|
||||
index: Number,
|
||||
list: Array,
|
||||
callback: Function,
|
||||
isReadOnly: {
|
||||
type: Boolean,
|
||||
default: false
|
||||
props: {
|
||||
regex: {
|
||||
type: Regex,
|
||||
default: () => {
|
||||
return new Regex();
|
||||
}
|
||||
},
|
||||
|
||||
data() {
|
||||
return {
|
||||
subjects: ASSERTION_REGEX_SUBJECT,
|
||||
}
|
||||
edit: {
|
||||
type: Boolean,
|
||||
default: false
|
||||
},
|
||||
index: Number,
|
||||
list: Array,
|
||||
callback: Function,
|
||||
isReadOnly: {
|
||||
type: Boolean,
|
||||
default: false
|
||||
}
|
||||
},
|
||||
|
||||
watch: {
|
||||
'regex.subject'() {
|
||||
this.setRegexDescription();
|
||||
},
|
||||
'regex.expression'() {
|
||||
this.setRegexDescription();
|
||||
}
|
||||
data() {
|
||||
return {
|
||||
subjects: ASSERTION_REGEX_SUBJECT,
|
||||
}
|
||||
},
|
||||
|
||||
watch: {
|
||||
'regex.subject'() {
|
||||
this.setRegexDescription();
|
||||
},
|
||||
'regex.expression'() {
|
||||
this.setRegexDescription();
|
||||
}
|
||||
},
|
||||
|
||||
methods: {
|
||||
add: function () {
|
||||
this.list.push(this.getRegex());
|
||||
this.callback();
|
||||
},
|
||||
remove: function () {
|
||||
this.list.splice(this.index, 1);
|
||||
},
|
||||
getRegex() {
|
||||
let regex = new Regex(this.regex);
|
||||
regex.description = regex.subject + " has: " + regex.expression;
|
||||
return regex;
|
||||
},
|
||||
setRegexDescription() {
|
||||
this.regex.description = this.regex.subject + " has: " + this.regex.expression;
|
||||
}
|
||||
methods: {
|
||||
add: function () {
|
||||
this.list.push(this.getRegex());
|
||||
this.callback();
|
||||
},
|
||||
remove: function () {
|
||||
this.list.splice(this.index, 1);
|
||||
},
|
||||
getRegex() {
|
||||
let regex = new Regex(this.regex);
|
||||
regex.description = regex.subject + " has: " + regex.expression;
|
||||
return regex;
|
||||
},
|
||||
setRegexDescription() {
|
||||
this.regex.description = this.regex.subject + " has: " + this.regex.expression;
|
||||
}
|
||||
}
|
||||
}
|
||||
</script>
|
||||
|
||||
<style scoped>
|
||||
.assertion-select {
|
||||
width: 250px;
|
||||
}
|
||||
.assertion-select {
|
||||
width: 250px;
|
||||
}
|
||||
|
||||
.assertion-item {
|
||||
width: 100%;
|
||||
}
|
||||
.assertion-item {
|
||||
width: 100%;
|
||||
}
|
||||
|
||||
.assertion-btn {
|
||||
text-align: center;
|
||||
width: 60px;
|
||||
}
|
||||
.assertion-checkbox {
|
||||
text-align: center;
|
||||
width: 120px;
|
||||
}
|
||||
|
||||
.assertion-btn {
|
||||
text-align: center;
|
||||
width: 60px;
|
||||
}
|
||||
</style>
|
||||
|
|
|
@ -23,88 +23,100 @@
|
|||
<el-input :disabled="isReadOnly" v-model="value" maxlength="200" size="small" show-word-limit
|
||||
:placeholder="$t('api_test.request.assertions.value')"/>
|
||||
</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-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-row>
|
||||
</div>
|
||||
</template>
|
||||
|
||||
<script>
|
||||
import {Regex, ASSERTION_REGEX_SUBJECT} from "../../model/ScenarioModel";
|
||||
import {Regex, ASSERTION_REGEX_SUBJECT} from "../../model/ScenarioModel";
|
||||
|
||||
export default {
|
||||
name: "MsApiAssertionText",
|
||||
export default {
|
||||
name: "MsApiAssertionText",
|
||||
|
||||
props: {
|
||||
list: Array,
|
||||
callback: Function,
|
||||
isReadOnly: {
|
||||
type: Boolean,
|
||||
default: false
|
||||
}
|
||||
props: {
|
||||
list: Array,
|
||||
callback: Function,
|
||||
isReadOnly: {
|
||||
type: Boolean,
|
||||
default: false
|
||||
}
|
||||
},
|
||||
|
||||
data() {
|
||||
return {
|
||||
subjects: ASSERTION_REGEX_SUBJECT,
|
||||
subject: "",
|
||||
condition: "",
|
||||
assumeSuccess: false,
|
||||
value: ""
|
||||
}
|
||||
},
|
||||
|
||||
methods: {
|
||||
add: function () {
|
||||
this.list.push(this.toRegex());
|
||||
this.callback();
|
||||
},
|
||||
|
||||
data() {
|
||||
return {
|
||||
subjects: ASSERTION_REGEX_SUBJECT,
|
||||
subject: "",
|
||||
condition: "",
|
||||
value: ""
|
||||
toRegex: function () {
|
||||
let expression = "";
|
||||
let description = this.subject;
|
||||
switch (this.condition) {
|
||||
case "CONTAINS":
|
||||
expression = ".*" + this.value + ".*";
|
||||
description += " contains: " + this.value;
|
||||
break;
|
||||
case "NOT_CONTAINS":
|
||||
expression = "(?s)^((?!" + this.value + ").)*$";
|
||||
description += " not contains: " + this.value;
|
||||
break;
|
||||
case "EQUALS":
|
||||
expression = "^" + this.value + "$";
|
||||
description += " equals: " + this.value;
|
||||
break;
|
||||
case "START_WITH":
|
||||
expression = "^" + this.value;
|
||||
description += " start with: " + this.value;
|
||||
break;
|
||||
case "END_WITH":
|
||||
expression = this.value + "$";
|
||||
description += " end with: " + this.value;
|
||||
break;
|
||||
}
|
||||
},
|
||||
|
||||
methods: {
|
||||
add: function () {
|
||||
this.list.push(this.toRegex());
|
||||
this.callback();
|
||||
},
|
||||
toRegex: function () {
|
||||
let expression = "";
|
||||
let description = this.subject;
|
||||
switch (this.condition) {
|
||||
case "CONTAINS":
|
||||
expression = ".*" + this.value + ".*";
|
||||
description += " contains: " + this.value;
|
||||
break;
|
||||
case "NOT_CONTAINS":
|
||||
expression = "(?s)^((?!" + this.value + ").)*$";
|
||||
description += " not contains: " + this.value;
|
||||
break;
|
||||
case "EQUALS":
|
||||
expression = "^" + this.value + "$";
|
||||
description += " equals: " + this.value;
|
||||
break;
|
||||
case "START_WITH":
|
||||
expression = "^" + this.value;
|
||||
description += " start with: " + this.value;
|
||||
break;
|
||||
case "END_WITH":
|
||||
expression = this.value + "$";
|
||||
description += " end with: " + this.value;
|
||||
break;
|
||||
return new Regex({
|
||||
subject: this.subject,
|
||||
expression: expression,
|
||||
description: description,
|
||||
assumeSuccess: this.assumeSuccess
|
||||
}
|
||||
return new Regex({
|
||||
subject: this.subject,
|
||||
expression: expression,
|
||||
description: description
|
||||
}
|
||||
);
|
||||
}
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
</script>
|
||||
|
||||
<style scoped>
|
||||
.assertion-select {
|
||||
width: 250px;
|
||||
}
|
||||
.assertion-select {
|
||||
width: 250px;
|
||||
}
|
||||
|
||||
.assertion-item {
|
||||
width: 100%;
|
||||
}
|
||||
.assertion-item {
|
||||
width: 100%;
|
||||
}
|
||||
|
||||
.assertion-btn {
|
||||
width: 60px;
|
||||
}
|
||||
.assertion-checkbox {
|
||||
text-align: center;
|
||||
width: 120px;
|
||||
}
|
||||
|
||||
.assertion-btn {
|
||||
width: 60px;
|
||||
}
|
||||
</style>
|
||||
|
|
|
@ -415,7 +415,7 @@ export class ResponseAssertion extends DefaultTestElement {
|
|||
this.assertion = assertion || {};
|
||||
|
||||
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.stringProp('Assertion.custom_message', this.assertion.message);
|
||||
|
||||
|
@ -440,11 +440,12 @@ export class JSONPathAssertion extends DefaultTestElement {
|
|||
}
|
||||
|
||||
export class ResponseCodeAssertion extends ResponseAssertion {
|
||||
constructor(testName, type, value, message) {
|
||||
constructor(testName, type, value, assumeSuccess, message) {
|
||||
let assertion = {
|
||||
field: 'Assertion.response_code',
|
||||
type: type,
|
||||
value: value,
|
||||
assumeSuccess: assumeSuccess,
|
||||
message: message,
|
||||
}
|
||||
super(testName, assertion)
|
||||
|
@ -452,11 +453,12 @@ export class ResponseCodeAssertion extends ResponseAssertion {
|
|||
}
|
||||
|
||||
export class ResponseDataAssertion extends ResponseAssertion {
|
||||
constructor(testName, type, value, message) {
|
||||
constructor(testName, type, value, assumeSuccess, message) {
|
||||
let assertion = {
|
||||
field: 'Assertion.response_data',
|
||||
type: type,
|
||||
value: value,
|
||||
assumeSuccess: assumeSuccess,
|
||||
message: message,
|
||||
}
|
||||
super(testName, assertion)
|
||||
|
@ -464,11 +466,12 @@ export class ResponseDataAssertion extends ResponseAssertion {
|
|||
}
|
||||
|
||||
export class ResponseHeadersAssertion extends ResponseAssertion {
|
||||
constructor(testName, type, value, message) {
|
||||
constructor(testName, type, value, assumeSuccess, message) {
|
||||
let assertion = {
|
||||
field: 'Assertion.response_headers',
|
||||
type: type,
|
||||
value: value,
|
||||
assumeSuccess: assumeSuccess,
|
||||
message: message,
|
||||
}
|
||||
super(testName, assertion)
|
||||
|
|
|
@ -785,6 +785,7 @@ export class Regex extends AssertionType {
|
|||
this.subject = undefined;
|
||||
this.expression = undefined;
|
||||
this.description = undefined;
|
||||
this.assumeSuccess = false;
|
||||
|
||||
this.set(options);
|
||||
}
|
||||
|
@ -1423,13 +1424,14 @@ class JMXGenerator {
|
|||
let name = regex.description;
|
||||
let type = JMX_ASSERTION_CONDITION.CONTAINS; // 固定用Match,自己写正则
|
||||
let value = regex.expression;
|
||||
let assumeSuccess = regex.assumeSuccess;
|
||||
switch (regex.subject) {
|
||||
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:
|
||||
return new ResponseDataAssertion(name, type, value);
|
||||
return new ResponseDataAssertion(name, type, value, assumeSuccess);
|
||||
case ASSERTION_REGEX_SUBJECT.RESPONSE_HEADERS:
|
||||
return new ResponseHeadersAssertion(name, type, value);
|
||||
return new ResponseHeadersAssertion(name, type, value, assumeSuccess);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -526,6 +526,7 @@ export default {
|
|||
expect: "Expect Value",
|
||||
expression: "Expression",
|
||||
response_in_time: "Response in time",
|
||||
ignore_status: "Ignore Status"
|
||||
},
|
||||
extract: {
|
||||
label: "Extract from response",
|
||||
|
|
|
@ -527,6 +527,7 @@ export default {
|
|||
expect: "期望值",
|
||||
expression: "Perl型正则表达式",
|
||||
response_in_time: "响应时间在...毫秒以内",
|
||||
ignore_status: "忽略状态"
|
||||
},
|
||||
extract: {
|
||||
label: "提取",
|
||||
|
|
|
@ -527,6 +527,7 @@ export default {
|
|||
expect: "期望值",
|
||||
expression: "Perl型正則表達式",
|
||||
response_in_time: "響應時間在...毫秒以內",
|
||||
ignore_status: "忽略狀態"
|
||||
},
|
||||
extract: {
|
||||
label: "提取",
|
||||
|
|
Loading…
Reference in New Issue