如何使用groovy比较SOAP UI中两个不同请求的响应值? [英] How to compare values from response of two different requests in SOAP UI using groovy?
问题描述
我正在使用SOAP UI Pro进行测试自动化,我是新的。我正在使用Rest API自动化工具。
我发送了POST服务请求并获得了一些响应,例如:唯一标识,名字,姓氏。
现在我发送另一个带有输入参数的GET请求,作为我以前的POST请求响应中的名字,姓氏(使用属性传送步骤),并作为响应,我得到了另一个唯一的ID (GET的响应)。
我的要求是使用groovy比较这两个不同响应的这两个独特ID,并根据结果标记测试通过或失败。请帮忙。
您可以访问要比较和执行的属性,
您对您的问题发表了评论,指出您正在使用媒体转移步骤,但您并未告知应将结果存储到何处例如,我假设您将值存储在 TestCase 属性中:
// you' ('firstName_firstResponse')
def fn2 = testRunner.testCase.getPropertyValue('firstName_secondResponse')$使用您在属性传输步骤中设置的属性名称
def fn = testRunner.testCase.getPropertyValue b $ b assert fn == fn2,第一个名字不相等
在 groovy script testStep 上下文中,您可以使用 testCase
来访问 testRunner
对象, testSuite
...然后获得所需的属性。
另一种可能的方法是做同样的事情,属性直接来自你的 testStep 的响应
并执行 XPat h ,那么你可以使用下面的 groovy脚本:
def fn = context.expand('$ {TestStepName_2#response#*:// firstName}')
def fn2 = context.expand('$ {TestStepName_2#response#*:// firstName}')
assert fn == fn2,第一个名字不等于
像 testRunner
context
对象已经在groovy testStep 的上下文中。在 context.expand
中使用的表示法是 $ {Test Step Name#response#XPath}
。
希望它有帮助,
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.
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).
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.
You can access the properties you want to compare and perform and assert
checking your required condition in groovy script.
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"
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.
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"
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}
.
Hope it helps,
这篇关于如何使用groovy比较SOAP UI中两个不同请求的响应值?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!