如何使用groovy比较SOAP UI中两个不同请求的响应值? [英] How to compare values from response of two different requests in SOAP UI using groovy?

查看:29
本文介绍了如何使用groovy比较SOAP UI中两个不同请求的响应值?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用 SOAP UI Pro 进行测试自动化,而且我是新手.我正在使用此工具进行 Rest API 自动化.我发送了一个 POST 服务请求并得到了一些响应,例如:唯一 ID、名字、姓氏.

I am using SOAP UI Pro for test automation and I am new for that. I am using this tool for Rest API automation. I sent a POST service request and got some response for example : unique id, first name, last name.

现在我发送另一个 GET 请求,其中输入参数作为名字,姓氏来自我之前的 POST 请求响应(使用属性传输步骤),作为响应,我得到了另一个唯一 ID(GET 响应).

Now I send another GET request with input parameters as first name, last name from my previous POST request response (using property transfer step) and in response I got another unique id (response of GET).

我的要求是使用 groovy 比较来自这两个不同响应的这两个唯一 ID,并根据结果标记测试通过或失败.请帮忙.

My requirement is to compare these two unique ids from these two different responses using groovy and mark test pass or fail based on the outcome. Please help.

推荐答案

您可以访问要比较和执行的属性,并在 groovy 脚本assert 检查所需的条件>.

You can access the properties you want to compare and perform and assert checking your required condition in groovy script.

您在问题中评论说您正在使用财产转移步骤,但是您没有告诉您将结果存储在哪里,因为我想例如您将值存储在TestCase 属性:

You comment in your question that you're using a Property transfer step however you didn't tell where you're storing your results due I suppose for example that you're storing the values in TestCase properties:

// you've to use the name of the property you set in the property transfer step
def fn = testRunner.testCase.getPropertyValue('firstName_firstResponse')
def fn2 = testRunner.testCase.getPropertyValue('firstName_secondResponse')
assert fn == fn2, "THE FIRST NAME AREN'T EQUALS"

groovy 脚本 testStep 上下文中,您有一个 testRunner 对象,您可以使用它来访问 testCasetestSuite...然后获得所需的属性.

In the groovy script testStep context you've a testRunner object which you can use to access testCase, testSuite... and then get the desired property.

另一种可能的方法是执行相同的操作,但直接从 testStepresponse 获取属性并执行 XPath,这样做您可以使用以下 groovy 脚本:

Another possible approach is to do the same but getting the properties directly from the response of your testStep and performing XPath, to do so you can use the follow groovy script:

def fn = context.expand('${TestStepName_1#response#*://firstName}')
def fn2 = context.expand('${TestStepName_2#response#*://firstName}')
assert fn == fn2, "THE FIRST NAME AREN'T EQUALS"

testRunner 一样,context 对象已经在groovy testStep 的上下文中.context.expand 中使用的符号是 ${Test Step Name#response#XPath}.

Like testRunner the context object is already on the context of groovy testStep. The notation used in context.expand is ${Test Step Name#response#XPath}.

希望能帮到你,

这篇关于如何使用groovy比较SOAP UI中两个不同请求的响应值?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆