Forum Discussion
tjdurden
14 years agoFrequent Contributor
Hi Deb,
One way to approach this is to use a Groovy script TestStep to create a timestamp and save the timestamp to a property (within a Property TestStep). Once the value is stored inside the Property step, this can be used within your SOAP request.
1) The Groovy TestStep
Place the following code inside a Groovy step, which should be the first item in your Test Case (or at least, before the property step and soap request):
2) Create a Property TestStep
Add a property that will hold your timestamp. The above Groovy assumed you call your Property TestStep "myProperties", and you create a property inside that step called "currentTimestamp".
3) Alter your XML to use your dynamic property.
Having done the above, you will need to add a reference to to your property (the timestamp) within the SOAP request itself. To do this, simple add "${currentTimestamp}" in the request where you want the timestamp to be added. This can be added multiple times.
Example:
Kind regards,
Tim
One way to approach this is to use a Groovy script TestStep to create a timestamp and save the timestamp to a property (within a Property TestStep). Once the value is stored inside the Property step, this can be used within your SOAP request.
1) The Groovy TestStep
Place the following code inside a Groovy step, which should be the first item in your Test Case (or at least, before the property step and soap request):
// Get the current date/time
def startDate = new Date()
// Format as necessary
def timeStamp = startDate.format("yyyy-MM-dd'T'HH:mm:ss SSS")
// Write to log to show it works as we want it to...
log.info("The time sponsored by SoapUI is: " + timeStamp);
// create a holder for properties
def myProps = new java.util.Properties();
// get the properties step from your test case
myProps = testRunner.testCase.getTestStepByName("myProperties");
// Save the current timestamp to a property
myProps.setPropertyValue("currentTimestamp",timeStamp);
2) Create a Property TestStep
Add a property that will hold your timestamp. The above Groovy assumed you call your Property TestStep "myProperties", and you create a property inside that step called "currentTimestamp".
3) Alter your XML to use your dynamic property.
Having done the above, you will need to add a reference to to your property (the timestamp) within the SOAP request itself. To do this, simple add "${currentTimestamp}" in the request where you want the timestamp to be added. This can be added multiple times.
Example:
<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:enum="http://www.example.org/someExample/">
<soapenv:Header/>
<soapenv:Body>
<enum:elem1>${currentTimestamp}</enum:elem1>
</soapenv:Body>
</soapenv:Envelope>
Kind regards,
Tim