Performance Testing

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

By Test Guild
  • Share:
Join the Guild for FREE

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

  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. Jeevak Kasarkod » Thanks Jeevak for your feedback. My apologies but HP’s Service Test’s User Guide does call it a REST service. In your opinion what would you consider the be a good example of a REST service? How about Twitter’s REST API or one of Amazon’s services? Cheers~Joe

  3. 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 :

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

  5. 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 \

  6. 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

  7. 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?

  8. kumar » Hi – not sure I understand your question. Normally you create a Vuser script and run in the LoadRunner Controller where you can specify how many vusers to run.

  9. 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 :(

  10. 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

  11. Hi Joe,

    I want to learn abt RESTful web service testing using HP’s LoadRunner. can you guide?

  12. Hi Joe,

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

  13. 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

  14. 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

  15. 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

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

Comments are closed.

{"email":"Email address invalid","url":"Website address invalid","required":"Required field missing"}

Unlock the Power of Continuous Performance Engineering

Posted on 03/25/2024

With the current demand for software teams to high quality product in a ...

16 Top Load Testing Software Tools for 2024 (Open Source Guide)

Posted on 03/12/2024

In the world of software development, testing is vital. No matter how well ...

What is Response Time Testing (Performance)

Posted on 03/01/2024

Unhappy user experience and lost revenue are all side-effects if you don't get ...