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

PerfectoTopAd

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

    21 comments
    Jeevak Kasarkod - January 24, 2012

    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

      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

    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

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

    Reply
      Joe Colantonio - July 7, 2012

      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

    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

      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

    How run this scenario for multiple Vusers?

    Reply
      Joe Colantonio - March 25, 2013

      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

    How to perform load test on this?

    Reply
      Joe Colantonio - March 14, 2013

      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

        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

          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

    Hi Joe,

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

    Reply
    Prakash - May 1, 2013

    Hi Joe,

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

    Reply
    XXYYZZ - September 17, 2013

    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

    Reply
    smaz - September 17, 2013

    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

    Reply
    sivakumar - September 2, 2014

    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

    Reply
    rajesh - June 3, 2015

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

    Reply
    Click here to add a comment

    Leave a comment: