I only used SOAP UI to just test the WSDL/URL but not in this extent. I need to get the request url query parameters from SOAP UI and use them to test some stuff using groovy script.
Lets say i have a GetCustomers request url as follows
`http://myendpoint.com/customers?Id=111&ModeName=abc&DeltaId=023423`
i need the following from URL
Id=111
ModeName=abc
DeltaId=023423
I created a groovy script in SOAP UI which in the following hierarchy TestSuit->TestCase-> TestStep->GroovyScript
In the groovy script i tried
def id = testRunner.testCase.getPropertyValue("Id")
but when i print id
i am getting it as null. I am not sure of any other configurations i need to do in order to access those query params.
Is there a way I can get those query params and access those directly in my groovy script?
Supposing that your testStep request is called
GetCustomers
you can use the follow Groovy code to get the testStep and then the property with the endpoint value asString
:Then you can parse the endpoint using the
java.net.URL
class and usegetQuery()
method to extract the query parameters. Then split by&
to get each query name value pair and finally split again each pair with=
and put the result in aMap
. Altogether your code could be something like:There is another option without using
URL
class; which simply consists on splitting theURL
using?
to get the query parameters (asURL.getQuery()
does):