Tag Archives: Groovy

Prepare test case in SoapUI using SQL script and custom properties

When prepare test case in SOAPUI, you might need to select a bunch of data from database to create your test cases. This can be done by using JDBC request as test steps in SoapUI.

The next step is to save script result (data set) in properties that can be retrieved by other test steps for example SOAP request. But how to extract values from result xml and save as string list? Assume we need to read MEMBER field from above sample.

Here is the answer. We can add a new property transfer step in SoapUI. Use XQuery script to read MEMBER field from xml.

XQuery script:

<UID>
{
for $id in //Results[1]/ResultSet[1]/Row/MEMBER
return string($id)
}
</UID>

The output result: “12345678 23456789” will be saved into properties where you defined as target.

Almost there! As SQL script returns a list of member then we will read each individual member from list and populate them into SOAP request.image003

Groovy script: ${=testSuite.getPropertyValue(“abc”).tokenize(‘ ‘)[0]} utilize tokenize function that returns the first member in the list.

Create date-time UTC string in SOAPUI using groovy

When test web services in SOAPUI, the web service security policy might require current date-time stamp to be passed in security token. This is a bit annoy when test the web service you have to change the date-time string manually. You can use properties scripting provided by SOAPUI to resolve this issue.

When you pass an invalid timestamp in the request, the response will like this
soapui.invalidtimestamp

 

 

Here is the article to use properties in SOAPUI.
https://www.soapui.org/scripting—properties/property-expansion.html

There are two common cases of inserting dynamic date-time value in SOAPUI using groovy:
1. Insert formatted timestamp value. Use SimpleDateFormat in this case:
${=new java.text.SimpleDateFormat(“yyyy-MM-dd’T’HH:mm:ss”).format(new Date())}
2. Format timestamp as xsd:dateTime value. Use DatatypeFactory to create instance of newXMLGregorianCalendar:
${=javax.xml.datatype.DatatypeFactory.newInstance().newXMLGregorianCalendar(GregorianCalendar.getInstance())}

Then you can convert the date-time value into UTC format:
1. Insert formatted timestamp value. Use SimpleDateFormat in this case:
${=new java.text.SimpleDateFormat(“yyyy-MM-dd’T’HH:mm:ss.SSS’Z'”).format(new Date(System.currentTimeMillis()+5*60*1000))}
2. Format timestamp as xsd:dateTime value. Use DatatypeFactory to create instance of newXMLGregorianCalendar:
${=javax.xml.datatype.DatatypeFactory.newInstance().newXMLGregorianCalendar(GregorianCalendar.getInstance(TimeZone.getTimeZone(“UTC”)))}

Below is how it should look like in SOAPUI.soapui.properties

 

 

The last step is to include these properties in your web service request.soapui.request

 

 

 

This is useful when creating automation test suite.