我正在使用QAF常见的步骤,并在getMessageBody()中获得null。还打印标题、状态等及其返回的适当值。
System.out.println("Status is:" + new RestTestBase().getResponse().getStatus().name());
System.out.println("Header is:" + new RestTestBase().getResponse().getHeaders());
System.out.println("Body is:" + new RestTestBase().getResponse().getMessageBody());
WsStep.responseShouldHaveValueContainsIgnoringCase(expectedvalue, jpath);输出:状态为:OK标头为:{CF=708ac4150dcfa03f-sin,.charset=utf-8]} Body为:null
我有过

使用下面的方法获得适当的响应。
public static void responseShouldHaveValueIgnoringCase(String expectedValue, String path) {
Object actual = JsonPath.read(new RestTestBase().getResponse().getMessageBody(), getPath(path));
assertThat(String.valueOf(actual), Matchers.equalToIgnoringCase(expectedValue));
}注意:我使用的是下面的版本,并带有空值。3.1.0并在3.0.1中验证了这一步骤,使用了9种以上的全局。新RestTestBase().getResponse().getMessageBody(),getPath(Path);
参考资料:https://github.com/qmetry/qaf-support-ws/blob/master/src/com/qmetry/qaf/automation/step/WsStep.java
发布于 2022-11-29 18:34:50
我在上面尝试过使用qaf-存储库编辑器,它工作得很好,没有问题。对于使用xpath的验证步骤,我在pom中添加了下面的依赖项。
<!-- https://mvnrepository.com/artifact/commons-jxpath/commons-jxpath -->
<dependency>
<groupId>commons-jxpath</groupId>
<artifactId>commons-jxpath</artifactId>
<version>1.3</version>
<exclusions>
<exclusion>
<groupId>com.mockrunner</groupId>
</exclusion>
</exclusions>
</dependency>我试着按照步骤来做,效果很好。
response has value "Asia" at xpath "//tContinent[sCode[contains(.,'AS')]]/sName"

https://stackoverflow.com/questions/72173450
复制相似问题