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,
来源:https://stackoverflow.com/questions/36762891/how-to-compare-values-from-response-of-two-different-requests-in-soap-ui-using-g