feat(接口测试): XPath断言支持html响应内容断言
https://www.tapd.cn/55049933/prong/stories/view/1155049933001012508?url_cache_key=from_url_story_list_2a3025da4c2d5d63c2ec0ca99fdfe730&action_entry_type=stories Signed-off-by: fit2-zhao <yong.zhao@fit2cloud.com>
This commit is contained in:
parent
59ea61761a
commit
842de54408
|
@ -24,6 +24,7 @@ import java.util.List;
|
|||
@EqualsAndHashCode(callSuper = true)
|
||||
public class MsAssertions extends MsTestElement {
|
||||
private String clazzName = MsAssertions.class.getCanonicalName();
|
||||
private String xpathType;
|
||||
|
||||
private boolean scenarioAss;
|
||||
private List<MsAssertionRegex> regex;
|
||||
|
@ -87,9 +88,15 @@ public class MsAssertions extends MsTestElement {
|
|||
}
|
||||
|
||||
if (CollectionUtils.isNotEmpty(this.getXpath2())) {
|
||||
this.getXpath2().stream().filter(MsAssertionXPath2::isValid).forEach(assertion ->
|
||||
hashTree.add(xPath2Assertion(assertion))
|
||||
);
|
||||
if (StringUtils.equals("html", this.getXpathType())) {
|
||||
this.getXpath2().stream().filter(MsAssertionXPath2::isValid).forEach(assertion ->
|
||||
hashTree.add(xPathAssertion(assertion))
|
||||
);
|
||||
} else {
|
||||
this.getXpath2().stream().filter(MsAssertionXPath2::isValid).forEach(assertion ->
|
||||
hashTree.add(xPath2Assertion(assertion))
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
if (CollectionUtils.isNotEmpty(this.getJsr223())) {
|
||||
|
@ -178,6 +185,23 @@ public class MsAssertions extends MsTestElement {
|
|||
return assertion;
|
||||
}
|
||||
|
||||
private XPathAssertion xPathAssertion(MsAssertionXPath2 assertionXPath) {
|
||||
XPathAssertion assertion = new XPathAssertion();
|
||||
assertion.setEnabled(this.isEnable());
|
||||
assertion.setTolerant(true);
|
||||
assertion.setValidating(false);
|
||||
if (StringUtils.isNotEmpty(assertionXPath.getExpression())) {
|
||||
assertion.setName(this.getName() + delimiter + assertionXPath.getExpression());
|
||||
} else {
|
||||
assertion.setName(this.getName() + delimiter + "XPath2Assertion");
|
||||
}
|
||||
assertion.setProperty(TestElement.TEST_CLASS, XPathAssertion.class.getName());
|
||||
assertion.setProperty(TestElement.GUI_CLASS, SaveService.aliasToClass("XPathAssertionGui"));
|
||||
assertion.setXPathString(assertionXPath.getExpression());
|
||||
assertion.setNegated(false);
|
||||
return assertion;
|
||||
}
|
||||
|
||||
private DurationAssertion durationAssertion(MsAssertionDuration assertionDuration) {
|
||||
DurationAssertion assertion = new DurationAssertion();
|
||||
assertion.setEnabled(this.isEnable());
|
||||
|
|
|
@ -68,11 +68,7 @@
|
|||
:document="assertions.document"
|
||||
:callback="after"
|
||||
v-if="type === options.DOCUMENT" />
|
||||
<el-button
|
||||
v-if="!type"
|
||||
:disabled="true"
|
||||
type="primary"
|
||||
size="mini">
|
||||
<el-button v-if="!type" :disabled="true" type="primary" size="mini">
|
||||
{{ $t('api_test.request.assertions.add') }}
|
||||
</el-button>
|
||||
</el-col>
|
||||
|
@ -171,6 +167,11 @@ export default {
|
|||
deep: true,
|
||||
},
|
||||
},
|
||||
created() {
|
||||
if (!this.assertions.xpathType) {
|
||||
this.assertions.xpathType = 'xml';
|
||||
}
|
||||
},
|
||||
methods: {
|
||||
computeStep() {
|
||||
let ruleSize = 0;
|
||||
|
|
|
@ -25,7 +25,18 @@
|
|||
</div>
|
||||
|
||||
<div class="assertion-item-editing x_path" v-if="assertions.xpath2.length > 0">
|
||||
<div>{{ 'XPath' }}</div>
|
||||
<div>
|
||||
XPath
|
||||
<el-select v-model="assertions.xpathType" size="mini" v-loading="loading" @change="reload">
|
||||
<el-option v-for="item in options" :key="item.value" :label="item.label" :value="item.value"></el-option>
|
||||
</el-select>
|
||||
<el-tooltip placement="top">
|
||||
<div slot="content">
|
||||
{{ $t('api_test.request.assertions.assert_info') }}
|
||||
</div>
|
||||
<i class="el-icon-question" style="cursor: pointer" />
|
||||
</el-tooltip>
|
||||
</div>
|
||||
<div class="regex-item" v-for="(xPath, index) in assertions.xpath2" :key="index">
|
||||
<ms-api-assertion-x-path2
|
||||
:is-read-only="isReadOnly"
|
||||
|
@ -119,6 +130,10 @@ export default {
|
|||
data() {
|
||||
return {
|
||||
loading: false,
|
||||
options: [
|
||||
{ value: 'html', label: 'html' },
|
||||
{ value: 'xml', label: 'xml' },
|
||||
],
|
||||
};
|
||||
},
|
||||
computed: {
|
||||
|
|
|
@ -1924,6 +1924,7 @@ const message = {
|
|||
'Special characters "$ () * +. [] \\ ^ {} |" need to be escaped as "\\ "+"special characters", such as "\\$"',
|
||||
xpath_info:
|
||||
"Select the extraction method according to the content format of the request response",
|
||||
assert_info: "According to the content format of the request response, select the assertion method",
|
||||
regular_match: "Regular match",
|
||||
none: "Do not verify []",
|
||||
value_eq: "Value-equal to [value=]",
|
||||
|
|
|
@ -1858,6 +1858,7 @@ const message = {
|
|||
regex_info:
|
||||
'特殊字符"$ ( ) * + . [ ] \\ ^ { } |"需转义为"\\ "+"特殊字符",如"\\$"',
|
||||
xpath_info: "根据请求响应内容格式,选择提取方式",
|
||||
assert_info: "根据请求响应内容格式,选择断言方式",
|
||||
regular_match: "正则匹配",
|
||||
none: "不校验[]",
|
||||
value_eq: "值-等于[value=]",
|
||||
|
|
|
@ -1857,6 +1857,7 @@ const message = {
|
|||
regex_info:
|
||||
'特殊字符"$ ( ) * + . [ ] \\ ^ { } |"需轉義為"\\ "+"特殊字符",如"\\$"',
|
||||
xpath_info: "根據請求響應內容格式,選擇提取方式",
|
||||
assert_info: "根據請求響應內容格式,選擇断言方式",
|
||||
regular_match: "正則匹配",
|
||||
none: "不校驗[]",
|
||||
value_eq: "值-等於[value=]",
|
||||
|
|
Loading…
Reference in New Issue