0

我正在使用带有 Fitnesse 的 Rest Fixture 向返回非 xml 响应的 url 发出 GET 请求。有没有办法可以在返回的内容中验证文本/字符串(没有 xpath)?

4

3 回答 3

0

您可以使用适合模式 + NetRunner 插件(用于 .Net)。

请参阅此处示例,如何将输入行解析为对象。

于 2014-12-23T18:10:09.457 回答
0

我找到了这个解决方案。TEXT 是 XML 和 JSON 中受支持的内容处理程序。可以将内容处理程序覆盖为 TEXT 并期望内容。正则表达式也可用于预期内容。

| Table:smartrics.rest.fitnesse.fixture.RestFixtureConfig | overridesContentHandlerConfig|
| restfixture.content.handlers.map | application/smil=TEXT |
!| Table:smartrics.rest.fitnesse.fixture.RestFixture | ${host} ||overridesContentHandlerConfig |
| GET | www.someurl.com | 200 | | [\s\w\d<>/=\:'.]*stringtoverify[\s\w\d<>/=\:'.]* |    
于 2014-12-04T12:47:13.500 回答
0

另一种方法是使用自定义比较器。这为您在自定义/复杂结果的自定义验证方面提供了更大的灵活性。

使用自定义比较器:在此处记录(搜索“CustomComparators”)

所需属性:CustomComparators = <prefix:classname>[,<prefix:class name>]

动机:Slim 协议都是 String 值。这意味着复杂数据类型的预期结果和实际结果的比较仅限于字符串相等或正则表达式匹配。如果这还不够,自定义比较器可以进行更复杂的比较。注册后,自定义比较器由其前缀触发,后跟一个冒号,位于预期值前面。

示例比较器实现:

public class JSONAssertComparator implements CustomComparator {
    @Override   
    public boolean matches(String actual, String expected) {
        try {
            JSONAssert.assertEquals(expected, actual, false);
            return true;
        } catch (JSONException e) {
            throw new RuntimeException(e.getMessage(), e);
        }
    }
}

示例 plugins.properties:

CustomComparators = json:com.acme.JSONAssertComparator

示例 ScriptTable 用法:

|script|Customer                                | 
|check|get|cust1|json:{id:cust1,name:"John Doe"}|
于 2015-12-01T06:58:52.103 回答