可以fitnesse验证非xml输出

时间:2014-12-04 10:50:49

标签: fitnesse fitnesse-slim

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

3 个答案:

答案 0 :(得分: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<>/=\:'.]* |    

答案 1 :(得分:0)

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

参见here示例,如何解析对象的输入行。

答案 2 :(得分:0)

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

使用自定义比较器: 记录here(搜索&#39; CustomComparators&#39;)

  

必需属性: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"}|