How to test a RESTful web service using HP’s LoadRunner

Loadrunner Published on:
API Testing Tools

Need to test a RESTful webservice using LoadRunner, but aren't sure if LoadRunner supports RESTFul? Did you try using the Web Services protocol without any luck? Actually, LoadRunner does support RESTful web services using the HTTP/HTML protocol with the web_url function.

Using web_url

REST is a very simple technology that uses XML for communication combined with URL patters. Also RESTFul web services work with most HTTP methods that many services expose. For example:

  • GET is used to perform a query or to obtain data. The data returned from the web service is a representation of the request info.
  • POST can be used to create a new resource. Typically, a web service will respond with data or a status of success or failure.

(For more detail check out this Oracle article on RESTful Web Services)

Using LoadRunners's web_url allows you to GET a request from a RESTFul service using its URL argument.

Using LoadRunner to test a RESTful example

  • For this example, I'll use the Sample Flight Application that comes with Service Test 11.20


  • I'm using the REST URL for my server plus the web service operations with its DepartureCity and ArrivalCity parameters/values. In LoadRunner add a web_url function with the following values:

  • Next, bring up the Run-time Settings enable the Extended Log with all its options:

  • Run the script should return the response from the RESTful service. Your LR's Replay log should contain the response body for the Flights operation:

Modify LoadRunner script

If you wanted to capture the first FlightNumber returned, you would use the same method you would normally use with the web_reg_save_param. The full script should look like this:

Action()

web_reg_save_param(“CheckFlightNum”,
“LB=”,
“RB=”,
“Ord=1”,
“RelFrameId=1”,
“Search=Body”,
“IgnoreRedirections=Yes”,
LAST);

web_url(“xml”,
“URL=http://localhost:24240/HPFlights_REST/Flights?DepartureCity=Denver&ArrivalCity=London”,
“Resource=0”,
“RecContentType=text/xml”,
“Referer=”,
“Snapshot=t1.inf”,
“Mode=HTML”,
LAST);

lr_output_message(“This is the first flightnumber %s”,lr_eval_string(“{CheckFlightNum}”));
return 0;
}

Be Restful with LoadRunner!!

To see how to test a NON-RESTful web service using LoadRunner check out my post How to test a web service using HP's LoadRunner

21 responses to “How to test a RESTful web service using HP’s LoadRunner”

  1. The example provided by HP in Service Test is not a RESTful web service, at best it is RPC URI tunneling through HTTP. You should rename this blog post to testing XML over HTTP services using LoadRunner.

  2. I followed the same steps, however the data return is like this Registerid”:” 13123123123123123″}”,with other data in the GET method, i have the read only 13123123123123123, i user web_save_param, but when i gave LB as Registerid”:” and RB as “}, am getting compilation error, how to solve this issue as :

  3. web_reg_save_param(“Reg_GUI_ID”,
    “LB=”RegisterGuid”:””,
    “RB=”}”;,
    “Ord=1”,
    “Search=Body”,
    “RelFrameId=1”,
    LAST);

    • Preethi » Hi Preethi — did you resolve this yet? Looks like an issue with the quotes since it is a special character in LR. Special characters in the boundaries must be “escaped” by a backslash \

  4. Hey Joe

    Which is the best tool for performance testing a enterprise solution that is on .Net REST services and GUI designed in ASP and other MS technologies.

    i have HP Loadrunner, NeoLoad, LoadUI we are currently evaluating the tools to see which one best fits in. Any thing that you know off along with cost options.

    Probably we might be running a 5k concurrent user load tests against our application at Max. and all these are HTTP requests

    • Naveen » Hi Naveen – I have to admit that I am biased towards LoadRunner. But I know that it does cost big $$ so it may not be an option for you. I don’t know enough about loadUI and NeoLoad to make a fair comparison. Does anyone else have any experience with either of these tools?

      • Hi, I have created a script with web_url in Vugen. After this, I have created a scenario of 10 vusers running for 5 mins, with a user ramping up every 10 seconds.
        The scenario runs without any issues. But the average response time comes as 0 for the Rest services! There are transactions logged against the Rest service, but response time is always 0.
        These services get loaded on Login. The only transaction that has response time more than 0 is Login.
        My script has a main transaction as Login and the Rest services as sub transactions. But I dont see any response time getting logged for the REST services :(

        • Hi, I have created a script with web_url in Vugen. After this, I have created a scenario of 10 vusers running for 5 mins, with a user ramping up every 10 seconds.
          The scenario runs without any issues. But the average response time comes as 0 for the Rest services! There are transactions logged against the Rest service, but response time is always 0.
          These services get loaded on Login. The only transaction that has response time more than 0 is Login.
          My script has a main transaction as Login and the Rest services as sub transactions. But I dont see any response time getting logged for the REST services

  5. Hi Joe,

    Thanks for sharing the detailed steps. Is there any way that we can add authentication(like tokens) to the request?

  6. Do you have any example related to post method. I have a web services with JMX and I am not able to configure in LoadRunner. Please sent me any examples that can takes username and password login in Rest ful web servicce and the output format should be in Json format

  7. getting content media mismatch error on my script. Actually I have a a web service project and developer create it on JMX . it is very simple all I need to do just passing username and password but I am not able to create it. please let me know how to configure this in loadrunner

  8. hi,
    I have a scenario like, need to download a file with REST api GET request using loadrunner. For that i added required headers with the function web_add_header and used web_url function for the REST api GET request. I am not able to download file, could you please help me on that. Thank you..

    Regards
    SivaKumar

  9. We are doing testing of rest services with most method,can you please show us post method how to test using post method

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.

API Testing Tools