LoadRunner and Performance Center
cancel
Showing results for 
Search instead for 
Did you mean: 

Re: Load testing of a REST API, using HP LoadRunner’s web_custom_request

NaveenKumar N

Very insight article.

0 Kudos
About the Author

NaveenKumar N

Comments
NaveenKumar N

Very insight article.

NaveenKumar N

How to install/host TODOMVC in my laptop? Please guide me. Thanks!

_Buzzy

Hi,

 

I will ask Malcolm to attach the implementation for the todoMVC application I talk about in the blog post.

To install it you need to have node.js installed. Once installed extract the attached zip file to some directory. I will refer to this directory as "c:\todoMVC" but you can extract to any directory.

Open the node.js command prompt (Start -> All Programs -> node.js -> node.js command prompt).

A cmd window will open. In the opened cmd window go to the directory where you extracted the zip file (e.g. "cd c:\todoMVC"). Type "npm install" (without the quotes) to download all the dependencies. If you are behind a proxy you will need to specify it using the --proxy flag (e.g. "npm install --proxy http://web-proxy.hst.hp.com:8080").

Run the application server by typing "node app.js". You should see the text: "Listening on port 3000" appear in the console.

Open your favorite browser (please don't use IE)  and type "localhost:3000" in the address bar. You should see the application running.

To reset the application go back to the cmd window and press Control+C to stop it, then type "node app.js" to start it. Note that closing the browser does not restart the application as it runs in the cmd window and the browser is used to access it.

 

Good Luck,

Boris.

 

 

Anonymous_User1

Thanks _Buzzy.  I've attached the file to the blog, as todo_mvc_example.zip

NaveenKumar N

I installed node.js and the I tried above steps. But I am not able to navigate to C:\todo_mvc_example  where I extracted the example. 

 

 

Please see this screenshot http://prntscr.com/1n2jrq

 

Could you please help me out? Thanks!

_Buzzy

Hi NaveenKumar,

 

I think you ran "node.js" instead of the "node.js command prompt". 

Please follow the instructions I posted.

 

Thanks,

Boris.

SDMike

A timely article in my case.  I recently did this for an internal project.  I hadn't considered adding the body payload as a JSON file though and that may simplify things for some of my requests.

Anonymous_User1

That's great news, SDMike.  Thanks for the feedback!

Bhaskar Venkataramana

but when we get the response if there is any "&" char than loadrunner will capture as "&amp", how do we resolve this issues

_Buzzy

Hi,

 

Could you please describe the problem in detail. I didn't understand what the issue is.

Bhaskar Venkataramana

can you help in Search and replace a character in a string

 

for eg:

web_reg_save_param("IDValues1","Notfound=warning" ,"LB=24skiptoken""RB=\"/></feed>""Ord=1","IgnoreRedirections=Yes"LAST);

 

the IDValues1 = "&amp%24skiptoken=hNhpItje6%2BpyE5PPcO9pOz0a%3B1000"

 

now i need to replace "&amp" with "&"

_Buzzy

Hi,

 

It is hard to help you since you are not giving any context of the problem and I don't understand what you are trying to do and how.

 

From the two lines you posted it seems that you need HTML decode the string and not search and replace.

 

Please ask scripting questions at our support forum here:

http://h30499.www3.hp.com/t5/LoadRunner-Support-Forum/bd-p/sws-LoadRunner_SF

 

Thanks,

Boris.

JoeRohan

I tried this tecnique, but not geting a response on the POST. To validate that the GET is requesting and responding I'm looking in the Tree and then click on the HTTP view. I see a request and response. Very nice.

However when I try to validate a POST, I don't see a request or result in the Tree view. I tried putting a snapshot in the script, no results. Something else, the first time I ran this script today, I did get a result in the run-time viewer, but every run since then I never see a result. In the Replay log I see that the Action.c(38): web_custom_request("web_custom_request") was successful. But how do I know it was successful? I don't see a request or response. How do I know if the POST worked?

_Buzzy

Hi Joe,

 

From your comment I understand you are using an older version of LR (11.0X). I tested my script with LR 11.52 although it should theoretically work with 11.0X.

 

You should see a response from the server in the snapshot RAW view. The response should be 200 OK.

If you don't see a snapshot at all, make sure you followed the steps correctly and that you have all the fields defined (especially Resource=0).

 

Hope this helps,

Boris.

JoeRohan

I'm doing something similar to step 1 and step 2 in the example. I see raw response data for step one or the first web_custom_request (the GET), but no raw data for step 2 (the POST).  I am using Resource=0, here is the code.

I'm also doing EncType=application/xstream instead of JSON, thanks for your help.

 

Action()
{
    web_set_user("xxx12345",
        lr_decrypt("xxxx"),
        "xx.moo.com:xx");

    web_custom_request("gateway",
        "URL=https://xx.moo.com/GAP_WEB/rest/gateway",
        "Method=GET",
        "Resource=1",
        "RecContentType=text/plain",
        "Referer=",
        "Snapshot=t1.inf",
        LAST);

    web_custom_request("web_custom_request",
        "URL=https://xxxxxx.moo.xxx/GAP_WEB/rest/gateway/SearchGroupEvent",
        "Method=POST",
        "TargetFrame=",
        "Resource=0",
        "Referer=",
        "Mode=HTTP",
/*       "Snapshot=t2.inf",  */
       "EncType=application/xstream",
       "Body=<com.moo.gfs.gap.common.event.SearchGroupEvent>"
         "<profilingId>1389375050239</profilingId>"
         "<attributes>"
           "<entry>"
             "<string>operator_id</string>"
             "<string>xxx84470</string>"
           "</entry>"
         "</attributes>"
         "<validationMessages/>"
         "<warningMessages/>"
         "<warnOverride>false</warnOverride>"
         "<executionTime>0</executionTime>"
         "<searchRequest>"
           "<comments/>"
           "<validateUIErrors/>"
           "<trimmed>false</trimmed>"
           "<loadMethod>2</loadMethod>"
           "<groupName>Hall Test*</groupName>"
           "<city></city>"
           "<state></state>"
           "<zipCode></zipCode>"
           "<quoteNumber></quoteNumber>"
           "<groupExternalId></groupExternalId>"
         "</searchRequest>"
         "<isMaxResultReturned>false</isMaxResultReturned>"
       "</com.mutualofomaha.gfs.gap.common.event.SearchGroupEvent>",
               LAST);
    return 0;
}


_Buzzy

Hi,

 

It is hard to "debug" your script over a blog post comments. I don't see any problem with the script so there must be something specific to the application you are testing. Try to tweak it around some more and I am sure you will find the problem.

 

You can always open a support ticket and get one of our professional support people to help you with the script.

 

Thanks,

Boris.

sandeep bansal

Hi Boris,

 

Thanks for excelent article. the most i liked is passing json using BodyFilePath. The question i have is how do we do parameterization if we specify it as file as we need to replace hard coded values with parameterized expression. do we specify it in json body file itself?

Raguraman B

Hi,

 

My case is i dont have the front end UI & i am given a WADL for performance testing.

 

I have done scripting using WSDL but not used WADL in LR before. Is it possible to import the WADL similar to how we dit it for WSDL & test it ?

 

Please guide me.

 

Thanks
Ragu

_Buzzy

Hi,

 

Sorry for the late reply. I didn't get notifications on new comments until today :(

 

sandeep bansal: I don't know if your approach of adding the parameters in the file would work. You can try but I have a feeling you will have to put the content of the file in the script.

 

Raguraman: We don't currently support importing WADL out of the box but you can develop a VuGen extension to do it.

 

Thanks,

Boris.

 

swtb4

I want your help in getting perticuler param from json response in load runner.

 

for example in json response i am getting bellow response and i want to get value of id in parameter.

 

{

"content": "abcdefghijklmnopqrstuvwxyz",
"helpType": "FAQ",
"creationTimestamp": "Jul 11, 2014 1:13:18 PM",
"id": {
"id": "fd3d5111-6c2f-4bd9-acdf-36fade2ed79b"
}
}

Pavel Zaychik

Thanks for the article Boris. 

Can you help me out with adding basic authorization and more headers to the POST?

The POST request works fine from POSTMAN Chrome extension or from http://hurl.it and looks like that:

HEADERS

Accept: */*

Accept-Encoding: gzip, deflate

Authorization: Basic MTExMTExOjEyMzQ=

Cache-Control: no-cache

Content-Length: 27

Content-Type: application/json

Host: ec2-54-235-205-185.compute-1.amazonaws.com

Postman-Token: 4da3ad48-b5ed-da1d-e2b6-9dc6f13c37b9

User-Agent: runscope/0.1

 
BODY view raw
{"deviceId": "111111"}
 
I was not able to replicate it from Chrome Advance REST extension (can't figure out authorization setup) and can't figure out how to combine it with "web_set_user" Loadrunner function, which, when added in front of " web_custom_request" seams working. Basically, I think it comes to how to set up additional headers to the custom request.
Thanks in advance.
Pavel. 
Pavel Zaychik

I finally figured out how to add headers and authorization. This is a working REST POST script:

Action()
{
    web_set_user("111111", "1234",
                 "ec2-54-235-205-185.compute-1.amazonaws.com:9080");
    web_add_header ("Host","ec2-54-235-205-185.compute-1.amazonaws.com:9080");
    web_add_header ("Authorization","Basic MTExMTExOjEyMzQ=");
    web_custom_request("Login",
        "URL=http://ec2-54-235-205-185.compute-1.amazonaws.com:9080/mpos/gateway/sessions/login", 
        "Method=POST", 
        "Resource=0", 
        "EncType=application/json", 
        "Mode=HTTP",
        "Body={\"deviceId\" : \"111111\"}",
        LAST);
    return 0;
}

Awesome. Thanks Boris.

Also, many thanks to Vamsi Tokala and his blog at http://performancetestinginfo.blogspot.com/2010/05/testing-restful-web-services-using.html 

Pavel Zaychik

I'm trying to capture (for correlation purpose) the string returned by REST resonse body.

The script:

{
     
    lr_start_transaction("Login");
    web_reg_save_param_ex("ParamName=TokenParm", 
        "LB/IC={", 
        "RB/IC=ANNAPOLIS", 
        "Ordinal=all",  
        SEARCH_FILTERS, 
            "Scope=body",
        LAST);
    web_set_user("111111", "1234",
                 "ec2-54-235-205-185.compute-1.amazonaws.com:9080");
    web_add_header ("Host","ec2-54-235-205-185.compute-1.amazonaws.com:9080");
    web_add_header ("Authorization","Basic MTExMTExOjEyMzQ=");
    web_custom_request("Login",
        "URL=http://ec2-54-235-205-185.compute-1.amazonaws.com:9080/mpos/gateway/sessions/login", 
        "Method=POST", 
        "Resource=0", 
        "EncType=application/json", 
        "Mode=HTTP",
        "Body={\"deviceId\" : \"{deviceId}\"}",
        LAST);
    lr_output_message("Token value is: %s", lr_eval_string(TokenParm));
lr_end_transaction("Login", LR_AUTO);
    return 0;

 

The script works without lr_output_message. The compiler complains on unresolved parameter "TokenParm"...

Any suggestion would be appreciated.

pavel.

asr_Dennis

Hi Pavel,

 

Incorrect line: lr_output_message("Token value is: %s", lr_eval_string(TokenParm));

Use: lr_output_message("Token value is: %s", lr_eval_string("{TokenParm}));

Note the quotes and { } characters.

I assume that you use { } as parameter delimiters in VuGen.

 

With kind regards,

 

Dennis

 

asr_Dennis

Oops, 

 

lr_output_message("Token value is: %s", lr_eval_string("{TokenParm}"));

 

Forget an extra quote.

 

Sry

 

Dennis

Pavel Zaychik

Thanks Dennis. This one works fine:

    lr_output_message("Token value is: %s", lr_eval_string("{TokenVal_1}"));

VuGen addes _1 when registering the parameter... Would you please elaborate on it? 

Thanks in advance.

Pavel.

asr_Dennis

Hi Pavel,

 

It is correct you have to use "TokenVal_1".

I did not look at your web_reg_save_param_ex options.

 

In your web_reg_save_param_ex you are using the option "Ordinal=all" .

It means that if there are more then one hits, with the specified boundaries, then all values are stored in an array.

Starting from value 1 to the number of values found e.g. TokenVal_1, TokenVal_2, TokenVal_3, etc.

 

If you remove the line "Ordinal=all" , you can use "TokenVal" instead of "TokenVal_1".

 

Got it?

 

Dennis

Dineshkumar Chokkalingam

Hi,

 

I am using the "bodyfilepath" method to call the .json file to run the web service request. Here as i need to run for load test, i am in need to parameterize the .json script. In LR i am allowed to do parameterize but getting error while running the script. If i run without the parameterization then the script runs sucessfully. Kindly find the below code for your reference.

 

Action script:

 

 

Action()
{
         
    lr_start_transaction("getcustomeraddress");
    web_custom_request("getCustomerAddress",
          "URL=https://pre-prod-skpservicesinternal.nus.ironmountain.com/rmservices/api/recordsMgmt/manageCustomers",
          "Method=POST",
          "Resource=0",
          "EncType=application/json",
          "Mode=HTTP",
          "BodyFilePath=getcustomeraddress.json",LAST);
    lr_end_transaction("getcustomeraddress",LR_AUTO);
      
    return 0;
}

 

.Json Script;

{
    "method": "getCustomerAddress",
    "format": "application/json",
    "system": "amer",
    "companyId": "1234",
    "customerId": "{custid}" ,
    "filter": 
    {
    "addressCode": "{addrcode}"
    }
}

 

Please help me in this regard. 

Thanks in Advance.

asr_Dennis

@Dineshkumar Chokkalingam,

 

I think the problem might be in the parameter delimiters that you are using within VuGen.

The '{' and '}' are your default parameter delimeters.

You can change the default delimiters in VuGen under the menu: Tools -> Options -> Tab Scripting -> Parameters.

Change 'Left parameter delimiter' and 'Right parameter delimiter' to another cahracter like '[' and ']'.

Re-record your script and give it a try.

 

I have no problem using the '{' and '}' with a custom request like:

web_custom_request("ResultType",

        "URL=http://{prm_URL_Open}/_xxx_xxx/x.Services/x.svc/ResultType?year=2015", 
        "Method=POST", 
        "Resource=0", 
        "RecContentType=application/json", 
        "Referer=http://{prm_URL_Open}/x/x", 
        "Snapshot=t10.inf", 
        "Mode=HTML", 
        "EncType=application/json", 
        "Body={\"query\":\"{prm_x_Part1}\"}", 
        LAST);

 

This works fine for me.

 

With kind regards,

 

Dennis

Dunfoss
Hi I've tried using the bodypathfile option. I can see that the request is being sourced of this json file. The issue I am stuck with is, not being abLe to pass values to the parameters in the json file. I am yet to try modifying the delimiters but in the meanwhile if there is another solution, please share. Thank you.
jeffsui

hi,I notice that use NodeJs to be a server .

but I found Connect as a single module dont integration into Express4.x.

error log :

      throw new Error('Most middleware (like ' + name + ') is no longer bundled
with Express and must be installed separately. Please see https://github.com/sen
chalabs/connect#middleware.');
      ^

Error: Most middleware (like bodyParser) is no longer bundled with Express and m
ust be installed separately. Please see https://github.com/senchalabs/connect#mi
ddleware.
    at Function.Object.defineProperty.get (c:\mywork\code\todo_mvc_example\node_
modules\express\lib\express.js:99:13)
    at Object.<anonymous> (c:\mywork\code\todo_mvc_example\app.js:6:16)
    at Module._compile (module.js:434:26)
    at Object.Module._extensions..js (module.js:452:10)
    at Module.load (module.js:355:32)
    at Function.Module._load (module.js:310:12)
    at Function.Module.runMain (module.js:475:10)
    at startup (node.js:118:18)
    at node.js:952:3

so you should intall it separately.

npm install connect

express4.x start up use this command 

npm start

then you can visit http://localhost:3000 successfully.

 

Gholtzhausen

Hi,

Is there any major difference in usering web_custom_request compared to web_rest?

I used web_rest in my script for API requests which worked perfectly.

All the information was written to an file to be provided to the devloper after the performance test.

Sriharsha Puranik

Hi,

 

I need to use AWS Signature V4 authorization for a REST API POST request.  can anyone provide instructions on how to do it?

Events
June 6 - 8, 2017
Las Vegas, Nevada
Discover 2017 Las Vegas
Join us for HPE Discover 2017 in Las Vegas. The event will be held at the Venetian | Palazzo from June 6-8, 2017.
Read more
Each Month in 2017
Online
Software Expert Days - 2017
Join us online to talk directly with our Software experts during online Expert Days. Find information here about past, current, and upcoming Expert Da...
Read more
View all