【问题标题】:how can I compare two test steps Json results!? in one test case with Groovy script?soapUI如何比较两个测试步骤 Json 结果!?在一个带有 Groovy 脚本的测试用例中?soapUI
【发布时间】:2018-07-19 17:41:11
【问题描述】:

如果有人可以帮助我解决此错误,我非常感谢,我尝试在我的一个测试用例的两个测试步骤中比较 Json 响应。 第一步添加一个任务,第二步获取所有任务的列表。 从第一步开始,我在 Json 文件中的所有内容都是一个数字,它是最后添加的任务的 TaskId。我需要在第二个测试步骤 Json 响应中检查该 taskid 是否存在? 我的 Groovy 断言是:

import groovy.json.JsonSlurper
def Response1 = context.expand( '${#ApiSmartsTaskPhysicalsPost - add an 
Unplanned task#Response}' );
def JSON1 = new JsonSlurper().parseText Response1;
log.info JSON1

def Response2 = context.expand( '${#ApiSmartsTaskPhysicalsGet -Check if 
values have been updated#Response}' );
def JSON2 = new JsonSlurper().parseText Response2;

log.info JSON2

assert JSON1 == JSON2

但我收到此错误:

" java.lang.illegalargumentexception:文本不能为空,错误在 行:3“

有没有机会指导我解决这个问题?检查端点是否相同,网址是否正确。

【问题讨论】:

    标签: json groovy automated-tests soapui assertion


    【解决方案1】:

    解决了,我可以修复它:

    import groovy.json.JsonSlurper
    def Response1 = context.expand( '${ApiSmartsTaskPost - add an 
    Unplanned task#Response}' );
    def JSON1 = new JsonSlurper().parseText(Response1);
    log.info JSON1
    def Response2 = context.expand( '${ApiSmartsTasksGet -check if task 
    has been added#Response}'.toString() );
    def JSON2 = new JsonSlurper().parseText(Response2);
    log.info JSON2
    assert JSON2.taskid.contains(JSON1), "Task has not been created!"`
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2018-05-24
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2021-03-09
      • 1970-01-01
      相关资源
      最近更新 更多