How to compare values from response of two different requests in SOAP UI using groovy?

牧云@^-^@ 提交于 2019-12-08 08:45:38

问题


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.


回答1:


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,



来源:https://stackoverflow.com/questions/36762891/how-to-compare-values-from-response-of-two-different-requests-in-soap-ui-using-g

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!