Forum Discussion

khanchett's avatar
khanchett
Contributor
5 years ago

Ready API 3.3.1 - messed date up

I just updated my SoapUI to 3.3.1 and now my Groovy dates don't work.  I keep getting errors "groovy.lang.MissingMethodException: No signature of method: java.util.Date.format() ..."  Has anyone else had this and do they have a fix?  To recreate I have 2 different ways:

1. in a Groovy script:  String todaysDate = new Date().format("YYYYMMdd")

2. in XML injection ${new Date().format("YYYYMMdd")}

 

Everything was running fine.  I did the update, made no changes and now this doesn't work.  I'm going back to 3.3.0 for now due to this is a complete stop for me.

 

I appreciate any help someone can provide.

  • Using Java 8 or more?

     

    Please check the below:

     

    log.info java.time.LocalDateTime.now().format(java.time.format.DateTimeFormatter.ofPattern('yyyy-MM-dd'))

     

    In xml

     

    <!-- assuming date is element; change as you needed-->
    <date>${= java.time.LocalDateTime.now().format(java.time.format.DateTimeFormatter.ofPattern('yyyy-MM-dd'))}</date>
  • nmrao's avatar
    nmrao
    Champion Level 3

    Using Java 8 or more?

     

    Please check the below:

     

    log.info java.time.LocalDateTime.now().format(java.time.format.DateTimeFormatter.ofPattern('yyyy-MM-dd'))

     

    In xml

     

    <!-- assuming date is element; change as you needed-->
    <date>${= java.time.LocalDateTime.now().format(java.time.format.DateTimeFormatter.ofPattern('yyyy-MM-dd'))}</date>
    • khanchett's avatar
      khanchett
      Contributor

      I'm not sure what you mean by using Java 8? 

           I'm just using ReadyAPI, so it's the Java version that is wrapped in it. 

       

      Is there a way to use the other class or is that deprecated? 

           We will have to do a bunch of rewrites along with manipulating the date by adding or subtracting a day as well. 

       

      If we can load in the class that allows us to use the previous way then that would buy us some time.  Is that possible?

      • PrathapR's avatar
        PrathapR
        Frequent Contributor

        khanchett 

        Even I'm facing same issue, all of my test cases used date.format function, so all of them are failing.

        Not sure how local JDK version matters to ReadyAPI, anyway I'm having Java 8, but still facing issue, I'm also reverting to 3.3.0. Hope SmartBear will fix it soon.

         

         

         

    • API_Guy's avatar
      API_Guy
      Occasional Contributor

      a piece of code in groovy which was working fine up to ReadyAPI version 3.2.5

      Once I have updated the version, the format () function stopped working.

      Can anyone suggest how I can manipulate the date? Like, I want a random date after 6 months from today.

       

      Upto ReadyAPI 3.2.5 I have used - 

      use(TimeCategory) {
      def date = (today + (new Random().nextInt(12)).months).format(yyyy-MM-DD).toString());

      }

      But the format () function not working in ReadyAPi 3.3.1. Any leads would be appreciated.

       

      Thanks in advance!

      • PrathapR's avatar
        PrathapR
        Frequent Contributor

        Hi API_Guy 

         

        Can you please try below snippet

         

        import groovy.time.TimeCategory
        import java.text.SimpleDateFormat

         

        use(TimeCategory) {
        date = ((new Date() + (new Random().nextInt(12)).months))
        sdf = new SimpleDateFormat("yyyy-MM-dd")
        newDate = sdf.format(date)
        }

         

        Thanks!

         

  • nmrao's avatar
    nmrao
    Champion Level 3
    By the way, the issue is not with the tool, but with the underlying java version.
  • ank2555's avatar
    ank2555
    Regular Visitor

    Hi Smart Bear Team ,

     

     

     

     Thanks for this Solution but this solution works only when we change the Script and it is very difficult to change every script in each and every Automation Pack let say suppose  60 Automation pack  around 30 Script in Generate Test Data and Grooy script 

     

    That would be very very difficult to change the script to fix this issue 

    So we want proper solution like in change in Jar file or some classes change so it should be one time change / one time activity  to fix this issue

     

    we are using Pro Version and need it to fix other wise we wont be able to continue to next level of version