2014-12-04 30 views
0

我正在使用Fit Fixse的Rest Fixture向返回非xml响应的url发出GET请求。有没有一种方法可以验证返回的内容中的文本/字符串(没有xpath)?Can fitnesse验证非xml输出

回答

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<>/=\:'.]* |  
0

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

请参阅here示例,如何解析输入行到对象。

0

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

要使用自定义的比较: 记录here(搜索 'CustomComparators')

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

动机:亭亭玉立的协议是所有字符串值。这意味着 比较复杂数据类型的预期结果和实际结果是 限于字符串相等或正则表达式匹配。如果这是 不足够,自定义比较器可以做更复杂的 比较。一旦注册,自定义比较器就会以其前缀 触发,然后在期望值前加冒号。

实施例比较实施:

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"}|