Hi I am using SoapUI for testing web services. I need to create a customer record with email address and password. Create customer record service contains emailid and password, when I click the run(submit request) button in create customer record in SoapUI, I should get the emailid appended with current time of creation and any password.
How to do this with groovy?
String newDate = Date. parse('MM/dd/yyyy',dt). format("yyyy-MM-dd'T'HH:mm:ss'Z'");
In SOAPUI you can use groovy code directly in your SOAP Request using the follow notation ${=groovy expression} , so in your case you can use ${=new java. text. SimpleDateFormat("yyyy-MM-dd"). format(new java.
Date object and will have the Default formatting of 'E MMM dd HH:mm:ss z yyyy'. So the string date of '2012-12-11 00:00:00' will now appear as 'Tue Dec 11 00:00:00 EST 2012'. If you wish to change from the default date formatting you can append a . format() to function and pass it a string paramater.
Create and Test a Groovy Script in a SoapUI ToolStep 1: Select the CalculatorSoap TestSuite and then select the Test Case in which we are going to create the Groovy script. Right-click on the Test Steps, and then go to the Add Step to select the Groovy Script from the available service, as shown below.
There are two common cases of inserting dynamic dateTime value in soapUI using groovy:
Insert formatted timestamp value. Use SimpleDateFormat in this case:
${=new java.text.SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ssZ").format(new Date())}
Format timestamp as xsd:dateTime value. Use DatatypeFactory to create instance of newXMLGregorianCalendar:
${=javax.xml.datatype.DatatypeFactory.newInstance().newXMLGregorianCalendar(GregorianCalendar.getInstance())}
I think that the first case works for you. Insert the code in your request and adjust timestamp format for your needs. BTW, it also works in responses for mock servers.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With