free seo tool

soapUI Groovy Date Formats

This is a simple date format Groovy Script which uses the java class simpleDateFormat. Date is one are which can cause error while doing automation scripting.

In this Groovy Date example, there are few lines which are commented to show how can we get other groovy date formats as well. This groovy date formats cam be written in a user defined function for soapUI and can be used as a utility function.


// Groovy date format example
import java.text.SimpleDateFormat 
Date currentDate = new Date();
def formatter = new SimpleDateFormat("MM/dd/yyyy");
//def formatter = new SimpleDateFormat("dd/MMM/yyyy");
//def formatter = new SimpleDateFormat("MM-dd-yyyy");
//def formatter = new SimpleDateFormat("dd-MM-yyyy");
//def formatter = new SimpleDateFormat("dd-MMM-yyyy");
String formatedDate = formatter.format(currentDate);
log.info(formatedDate)
1 comments:
  • Anonymous says:
    April 24, 2015

    In your XML request you can put

    Example 1 :
    ${=((new Date() - 20).format("ddMMMyy")).toUpperCase()}
    which will result in puting the date of today - 20 days formate as
    04APR15

    Example 2:
    ${=(new Date() + 05).format("ddMMyy")}
    which will result in puting the date of today + 5 days formated as
    290415

    Useful ! ;o)

Post a Comment

This is a new website mainly for SOA Testers using soapUI. Let me know your thoughts/ suggestions.