Forum Discussion

KeyofSea123's avatar
KeyofSea123
Contributor
12 years ago

REST POST service

I have built automatted test suites for many Soap services. I have also built automatted test suites for several REST GET services.

In the Soap calls, I have
1) a DataSource,
2) a Groovy script of the full Soap/XML call,
3) a Groovy script that reads the DataSource and removes elements that are not needed for that particular Soap call,
4) a Soap step for the main call,
5) a Groovy script that creates a .txt log,
6) a Groovy script that validates the requested data with the response data and validate the response data with our Oracle database,
7) a DataSource Loop.

I need to be able to "build" the REST POST content in the same way that I do for the XML. I know that it's not exactly the same - I won't need a step with all of the elements like I do for Soap. I need to write a Groovy script that will create the REST POST call. I know how to write the script but I have no idea how to then get that data in the REST step.

I've Googled and searched the forum but I haven't been able to find any help.

Thanks,
Trish

5 Replies

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

    If I've understood your question correctly, my advice is that you do the following. From a groovy script, you can create properties containing what you need for your REST request, and then you can use property expansion (http://www.soapui.org/Scripting-Propert ... nsion.html) to extract that data from the properties to create your REST request. When you select a REST resource, there's a "Resource Path" field at the top where you can use property expansion.

    If this answer isn't clear, or I've misunderstood your question, let me know and I'll assist you further.

    Regards,

    Arian
    SmartBear Sweden
  • Thanks for your help. I think that you understood my question well.

    I'm a little confused but I'll work on that today and get back to you.
  • I can't find an example of what the raw request for a POST request should look like. So I'm not sure that I'm scripting it correctly. I can build the string of fields and their values (like for a GET request) but I have two problems with that.

    1) By the time the string gets to the raw request, the '=' and '&' have all been converted to '%27%26%27' and '%27%3D%27' respectively.
    2) I'm not sure that I have the correct format.

    I've thought of something else that I want to try so I don't need an answer for #1 at this time. However, I would like to see a POST raw request example.

    Thanks,
    Trish
  • By using the Post QueryString, I was able to get it working!! All I had to do was check the box.

    This is an example of what I wrote in my script:

    def firstName = context.expand( '${DataSource POST PD#FirstName}' )
    def baseString = startDate.format("yyyy_MM_dd'T'HH_mm_ss_SSS")

    if (partyName.compareToIgnoreCase("Random") == 0)
    {
    firstName = "First" + baseString
    testRunner.testCase.setPropertyValue( "FirstName", firstName )
    }

    Then I used ${#TestCase#FirstName} for the value of first_name in the POST step. The value in the REST request was first_name=First2013_04_04T16_24_04_779.

    Success for my first POST request! Thanks so much for your help along the way.

    Trish
  • SmartBear_Suppo's avatar
    SmartBear_Suppo
    SmartBear Alumni (Retired)
    Awesome! Great to hear it worked out for you. Let us know if you ever have any more problems and we'll gladly assist.

    Regards,

    Arian
    SmartBear Sweden