以StringReader格式断言REST响应

时间:2017-02-21 05:09:36

标签: json rest testing groovy automation

我需要声明一个java.io.StringReader格式的响应。 。当我使用response.data时,我能够以{“isValid”:false}获得正确的响应。但是当我尝试使用

来断言这个响应时
<a class="hello">Copy It</a>
<a class="goodbye"></a>


(function($) {
    $('.hello').click(function() {

      $(this).clone().appendTo( ".goodbye" );
    });
})(jQuery);

我收到以下错误。

response.data == '{"isValid": false}'

如何解析StringReader格式。

2 个答案:

答案 0 :(得分:0)

如何将isValid视为false

assert !response.data.isValid, 'isValid is not matching the expected value'

编辑:基于OP的评论。

def str = '''{"isValid": false}​​​​'''
def value = new groovy.json.JsonSlurper().parseText(str)​.isValid​

assert response.data == value, 'isValid is not matching the expected value'

答案 1 :(得分:0)

我发现了。 def jsonSlurper = new JsonSlurper()。parse(response.data)jsonSlurper == [virtualCard:false]

相关问题