Forum Discussion

PeterKlim's avatar
PeterKlim
Contributor
11 years ago

set a variable = to system time/date stamp

Hi, We need helping storing the current system time/date stamp into a variable.

The steps are:
DataSource > Property Transfer > CreateRequest (HTTP) > GetRequestID > Delay[1000] > CheckRequest (HTTP) > HandleResponse (GroovyScript) > DataSourceLoop

We need to set a variable = to system time/date stamp when CreateRequest and CheckRequest are submitted. Preferably it will include the hours, minutes and seconds. But right now I am unable to get system time/date value in any format at all. There are other variables we use to hold response values (such as requestID) and then write into an excel file. But we do not know how to capture the time/date stamp.
  • Cizo89's avatar
    Cizo89
    Frequent Contributor
    Hi,

    to get a system date and time, try this script, it should work for you (you can change the format to fit your requirements):

    def date = new java.text.SimpleDateFormat("dd/MM/yyyy HH:mm:SS")
    date.format(new Date())


    If you need to store this timestamp after a TestStep is submitted, I'd suggest that SubmitListener.afterSubmit event handler would be perfect for you.

    In case of any further questions, feel free to ask

    Regards,
    Marek
  • Cizo89's avatar
    Cizo89
    Frequent Contributor
    Hi Naveen,

    to your question in the screenshot - if I'm not wrong, that's the timestamp when the TestStep was submitted.

    Well, you can add it to a Groovy TestStep, but that might not give you the exact time.
    Better solution would be a custom event handler, more info here:
    http://www.soapui.org/Scripting-Propert ... dlers.html

    Here you can handle this timestamp - you can use DataSink TestStep or Groovy script to write it to Excel.

    P.S. Looking at my previous comment, it looks like I made a mistake - the correct format for the time part should be "HH:mm:ss", because "ss" represents seconds and "SS" represents miliseconds - I apologize for that.

    Regards,
    Marek
  • I generally use this and works everytime in the request body.


    PeterKlim wrote:
    Hi, We need helping storing the current system time/date stamp into a variable.

    The steps are:
    DataSource > Property Transfer > CreateRequest (HTTP) > GetRequestID > Delay[1000] > CheckRequest (HTTP) > HandleResponse (GroovyScript) > DataSourceLoop

    We need to set a variable = to system time/date stamp when CreateRequest and CheckRequest are submitted. Preferably it will include the hours, minutes and seconds. But right now I am unable to get system time/date value in any format at all. There are other variables we use to hold response values (such as requestID) and then write into an excel file. But we do not know how to capture the time/date stamp.

     

    "timestamp": "${=System.currentTimeMillis()}"

  • I use this in my request body

     

    "timestamp": "${=System.currentTimeMillis()}"

  • NaveenVanapalli's avatar
    NaveenVanapalli
    Occasional Contributor
    Hello Marek,

    Thanks for your response.

    FYI, Peter, Devi and me work together for this project, so anyone of us could reply to this post.

    The code snippet which you have attached will get the system date and time stamp but not the time stamp for the submitted request XMLs in the "CreateRequest (HTTP)" test step.
    That means i need to add the code snippet in a "Groovy" test step where this step should be added after the "CreateRequest (HTTP)" test step.

    Please see the screenshot attached to this post, also please clarify the one questioned in the screenshot.

    As per the attached screenshot, if at all the time stamps which are in the red box belongs to request XMLs submitted time stamp then that is what the time stamps we are looking to export into the excel file for each row in the data source.

    Below is the information copied from Peter's post, where we are looking request XML times stamps in both HTTP test steps (CreateRequest, CheckRequest)

    The steps are:
    DataSource > Property Transfer > CreateRequest (HTTP) > GetRequestID > Delay[1000] > CheckRequest (HTTP) > HandleResponse (GroovyScript) > DataSourceLoop


    Regards,
    Naveen
  • NaveenVanapalli's avatar
    NaveenVanapalli
    Occasional Contributor
    Hello Marek,

    Thanks for your response.

    I have gone through the link which is related to event handlers in soapui and added two events (SubmitListener.afterSubmit) for each of the HTTP request test step.
    I have tried in different ways of using groovy code in "Edit" pane to access the TimeStamp of each of the request but i could not find it.

    FYI, attached is the screenshot of how i have used in the soapui.

    Could you please let me know the best way of getting exact time stamp (what we have seen in the "Request Log" tab in my previous screenshot) using this event handler in soapui.

    Regards,
    Naveen
  • SmartBear_Suppo's avatar
    SmartBear_Suppo
    SmartBear Alumni (Retired)
    Hi,

    testRunner variable is not applicable for the SubmitListener.afterSubmit event handler. Replace testRunner with context variable i.e context.testCase.


    Regards,
    Marcus
    SmartBear Support