Forum Discussion

ABCDEFG's avatar
ABCDEFG
Contributor
13 years ago

Date Format issue with JSON string (soapUI Pro)

Hi,

I am facing this problem in my project.

I am using Data Driven testing using soapUI Pro. I have added DataSource as MS Excel and passing values to the JSON String. Date format which JSON string is designed to have is “09/05/2011”. But JSON response is giving as “Request is not valid” error message. I see issue is with the Date Format which JSON string is accepting with. Though, JSON string will accept “09-05-2011” with hyphen as delimiter.

Can somebody help to have a solution.

Appreciate your help in advance,

Any valid thoughts or suggestion are very welcome.

PS: I guess Groovy script can solve this problem. But how!!

^Thanks

4 Replies

  • Hi,

    If you are sure that your problem is because of date format then I guess you have to change this format before passing to JSON String.

    For ex: use groovy as

    def dt = "09/05/2011"
    dt=dt.replaceAll('/', '-');

    output of this will be 09-05-2011

    Regards,
    Rohit Shingalapur
  • Thank you Rohit for the Groovy code.

    instead of static date, we have to use dynamic date's in the DataSource. I have developed following code for this,

    def dt = testRunner.testCase.getTestStepByName("DataSource").getPropertyByNames("IntPayD");
    IntPayD=dt.replaceAll('/', '-');
    // Where DataSource is the data source name and "IntPayD" is the date field in the Data Source.

    But its not working, Needs to change all the date format's in the field of "IntPayD" of DataSource.

    Could please help

    ^Thanks
  • Hi,

    I hope that dt is array and if so then use the following code:

    def dt = testRunner.testCase.getTestStepByName("DataSource").getPropertyByNames("IntPayD");

    for(int i=0;i<dt.size();i++){
    dt=dt.replaceAll('/', '-');
    }

    Then the variable dt will contain the array of new values
    // Here you need to set back dt to JSON
  • Thanks Rohit for the update.

    error message is throwing, please find the attached.

    Things is, we need to loop the number of times of { Size of(IntPayD) }.

    def dt; //Date Definition
    def i;

    for(i=0;i<IntPayD.size();i++)
    {
    dt = testRunner.testCase.getTestStepByName("DataSource").getPropertyByNames("IntPayD"); //Accessing PayoutDate At ithe position
    dt=dt.replaceAll('/', '-'); //Change the Date Format
    testRunner.testCase.getTestStepByName("DataSource").setPropertyValue("dt",IntPayD); //Updating the new date format in the ith Position
    }

    But this is not working, Could you please help.

    wht do u think? To define IntPayD array?

    Appreciate your help in advance,

    ^Best regards