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

by Joe Colantonio on January 18, 2012

Post image for LoadRunner – How to test a RESTful web service using HP’s LoadRunner

Does LoadRunner support testing RESTful Web Services?

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:
  • "URL=http://localhost:24240/HPFlights_REST/Flights?DepartureCity=Denver&ArrivalCity=London", "Resource=0",
    "RecContentType=text/xml",
    "Snapshot=t1.inf",
    "Mode=HTML",
    LAST);

  • 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 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!!

    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

    { 17 comments… read them below or add one }

    Jeevak Kasarkod January 24, 2012 at 12:05 am

    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.

    Reply

    Joe Colantonio January 24, 2012 at 1:02 am

    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

    Reply

    Preethi June 26, 2012 at 10:35 am

    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 :

    Reply

    Preethi June 26, 2012 at 11:27 am

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

    Reply

    Joe Colantonio July 7, 2012 at 11:31 pm

    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 \

    Reply

    Naveen September 28, 2012 at 12:27 am

    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

    Reply

    Joe Colantonio September 28, 2012 at 4:16 pm

    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?

    Reply

    kumar March 12, 2013 at 9:28 pm

    How run this scenario for multiple Vusers?

    Reply

    Joe Colantonio March 25, 2013 at 8:56 pm

    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.

    Reply

    kumar March 12, 2013 at 9:37 pm

    How to perform load test on this?

    Reply

    Joe Colantonio March 14, 2013 at 1:43 pm

    kumar » Do you have a specific issue? To use you could add to the LoadRunner controller and add the amount of Vusers that you need to use.

    Reply

    Hema April 25, 2013 at 6:15 am

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

    Reply

    Hema April 29, 2013 at 5:34 am

    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

    Reply

    Jean April 30, 2013 at 6:48 am

    Hi Joe,

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

    Reply

    Joe Colantonio May 3, 2013 at 3:00 pm

    Jean » Hi Jean – what type of info are you looking for?

    Reply

    Prakash May 1, 2013 at 1:49 am

    Hi Joe,

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

    Reply

    Joe Colantonio May 3, 2013 at 3:08 pm

    Prakash » You can usually use web_set_user for basic authentication info

    Reply

    Leave a Comment

    Previous post:

    Next post: