Submit and vote on feature ideas.

Welcome to the new Parasoft forums! We hope you will enjoy the site and try out some of the new features, like sharing an idea you may have for one of our products or following a category.

Scripting Example for SystemTime

LegacyForum
LegacyForum Posts: 1,664 ✭✭
edited December 2016 in SOAtest
Does any one have an example how to script or retrieve systemtime with JYTHON in SOA Test 4.1?
-LeapTester
Tagged:

Comments

  • LegacyForum
    LegacyForum Posts: 1,664 ✭✭
    edited January 2006
    Hey LeapTester,

    CODE
    from java.lang import *

    def getTime():
       time = System.currentTimeMillis()
       print time
       return time

    That should do it. Good luck testing!
  • LegacyForum
    LegacyForum Posts: 1,664 ✭✭
    edited January 2006
    In one of my testmethod , i have one field(input parameter) set effective date:
    I want to write script for setting effective date which includes format like:2006-01-20T15:16:20.035Z
    Can you please provide me javascript or python example for setting this effective date and also
    manipulating this date with '+' or' '-' some days.

    Thanks
    LeapTester
  • LegacyForum
    LegacyForum Posts: 1,664 ✭✭
    To get a date in this format, you can use Java's SimpleDateFormat class and use the Calendar class to mess with the day information:

    CODE
    from java.util import *
    from java.text import *

    def getTime():
       # Get an instance of the calendar
       calendar = Calendar.getInstance()

       # Set the day in the calendar
       day = calendar.get(Calendar.DAY_OF_WEEK)
       calendar.set(Calendar.DAY_OF_WEEK, day+1)

       # Retreive the date from the calendar
       date = calendar.getTime()

       # Create the date formatter
       myFormat = "yyyy-MM-dd'T'HH:mm:ss.SSS'Z'"
       formatter = SimpleDateFormat(myFormat)

       # Create, print, and return the timestamp
       timestamp = formatter.format(date)
       print timestamp
       return timestamp

    Where I set the day in the calendar you can see that I have incremented it by one. You can include any additional logic to modify the day as you would like. Just FYI: that day number is automatically wrapped so that if you go past the number of days in the month, it will automatically increment (or decrement) the month as well.
  • LegacyForum
    LegacyForum Posts: 1,664 ✭✭
    Dudes you guys rule! Now if you would support Perl as well as Python/Jython that would make me even happier:D.

    thanks again,

    LeapTester