13 years ago
populate date(and time) using groovy script for Test Request
Hi All
Kindly request you to please clarify.
I have a REST Test Request which takes XML input of below form:
Now, I want to populate date and time as shown above using Groovy Script and populate the same to the REST Test Request xml elements shown above using below code in the REST Test Request and using below Groovy Script.
I tried below Groovy Script test but it did not help.
Kindly request you to please clarify.
I have a REST Test Request which takes XML input of below form:
<EffectiveDate1>2013-03-18T40:00:00</EffectiveDate1>
<EffectiveDate2>2013-03-18</EffectiveDate2>
Now, I want to populate date and time as shown above using Groovy Script and populate the same to the REST Test Request xml elements shown above using below code in the REST Test Request and using below Groovy Script.
...
<EffectiveDate1>${#EffectiveDate1}</EffectiveDate1>
<EffectiveDate2>${#EffectiveDate2}</EffectiveDate2>
...
I tried below Groovy Script test but it did not help.
import com.eviware.soapui.impl.wsdl.*
import java.util.Calendar;
import java.text.SimpleDateFormat;
String timestamp = HeaderHelper.createTimestamp()
String DATE_FORMAT = "MM/dd/yyyy";
String REQUEST_DATE_FORMAT = "yyyy-MM-dd";
SimpleDateFormat sdf_Date = new SimpleDateFormat(DATE_FORMAT);
SimpleDateFormat sdf_Request_Date = new SimpleDateFormat(REQUEST_DATE_FORMAT);
Calendar c1 = Calendar.getInstance();
def testStep = context.testCase.getTestStepList()
testStep.each {
if ((it.config.type)=='restrequest') {
def stepRequestName = it.name
def tp = new com.eviware.soapui.support.GroovyUtils( context )
tp.setPropertyValue(stepRequestName,'EffectiveDate1', sdf_Date.format(c1.getTime()))
tp.setPropertyValue(stepRequestName,'EffectiveDate2', sdf_Date.format(c1.getTime()))
} }