简体   繁体   English

我如何比较两个测试步骤的Json结果!? 在一个带有Groovy脚本的测试用例中?

[英]how can I compare two test steps Json results!? in one test case with Groovy script?soapUI

I do appreciate if anyone can help me with this error ,tried to compare Json responses in two test steps of one of my test cases. 如果有人可以帮助我解决这个错误,我非常感激,力图在一个测试用例的两个测试步骤中比较Json响应。 the first step adds a task, and the second step gets a list of all tasks. 第一步添加任务,第二步获取所有任务的列表。 all I have in my Json file from first step is a number which is the TaskId of last added task. 从第一步开始,我在Json文件中拥有的只是一个数字,它是最后添加的任务的TaskId。 and i need to check in the second test step Json response whether that taskid exists or no? 我需要在第二个测试步骤Json响应中检查该taskid是否存在? My Groovy assertion is : 我的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

but I am getting this error : 但我收到此错误:

" java.lang.illegalargumentexception:Text must not be null ,error at line:3 " “ java.lang.illegalargumentexception:文本不能为null,第3行错误”

is there any chance to direct me to get solve this issue ? 有没有机会指导我解决这个问题? checked the end points they are the same and the URL is correct. 检查了端点是否相同,URL是否正确。

solved I could fix it : 解决了我可以解决它:

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!"`

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM