Showing posts with label Correlation in Loadrunner. Show all posts
Showing posts with label Correlation in Loadrunner. Show all posts

REST API Services Testing using loadrunner

REST API Services Testing using loadrunner,rest api services uses web http/html protocol while creating REST API Services scripts using virtual user generator,which is a loadrunner component.Most of the companies are using REST API services in order provide better security in customer data,fast execution for communication between
multiple applications.

Please read Complete Loadrunner Tutorial

[embed]https://youtu.be/jYlUPEC1WfE[/embed]

REST API Services Testing using loadrunner


In this post we will create REST API Services script in Virtual User Generator i.e VUGen,Please follow below steps to create script for REST API services using VUgen.

Steps:


1.REST API URL
2.Which Protocol should use
3.What is the input parameters
4.What is the output Response
5.Content- Type
6.Method - GET,POST,DELETE etc.

Once you know all above details then it is easy to create the script with the help of below simple syntax ,plesae use below syntax for all rest api services for load testing.
web_custom_request("Card_validation",
"URL=http://ipaddress:portno/cardApi/api1/card/linkcard",
"Method=POST",
"Resource=0",
"EncType=application/json",
"Mode=HTTP",
"Body="Body={\"cardNo\":\"9898989898989898\",\"cardType\":\"CreditCard\",\"MobileNo\":\"1111111111\"}",
LAST);

CODE Explanation:


As you see above code i have used web_custom_request() function which is allow users to create custom HTTP request with any useful method(POST,GET,DELETE etc)

1.Card_validation : Request Name

List of Resources:


URL
Method
Resource
EncType
Mode
Body

Method=POST:


As based on above resources we will create REST API Services scripting as you see "Method=POST" which is posting the values to database,in case you want to get the details from the database then you can use "Method=GET".

EncType=application/json:


As i have used application/json because content-Type of REST API service is developed with Media Type,as REST API Services has below Media Types,those are

1.application/json
2.application/xml
3.text/xml
4.multipart/form-data
5.multipart/mixed

Most of the REST API services are developed with application/json,application/xml and text/xml media types,this one provided by developer.

Mode=HTTP:


As i mention in first paragraph REST API service is developed with HTTP protocol for data transfering to multiple systems.While creating the REST API script you need to select
Web-HTTP/HTML protocol.

Body:


Body resource which contains input request parameters as i written in above script.The main rest api input request is as below
{
"cardNo":"9898989898989898",
"cardType":"CreditCard",
"MobileNo":"1111111111"
}

You can write above input request into below code in order to mention in Body resource.Please check below code.
"Body={\"cardNo\":\"9898989898989898\",\"cardType\":\"CreditCard\",\"MobileNo\":\"1111111111\"}"

LAST:


LAST argument which tells a market which indicates the end of the field list.This total web_custom_request() function returns LR_FAIL(1) or LR_PASS(0) on successful and on failure of web_custom_request()
function execution.

Parameterization:


We can perform Parameterization for input parameters as we mention in Body ,Please read Correlation in loadrunner post,you will get clear idea about manual and automatic correlation for any script whether it could be a web request,rest api or Web-Services.

Thank you for reading,i hope you got good knowledge about REST API Services Testing using loadrunner,please provide your valuable comments and suggestions on this post.

Extrares in Loadrunner

Extrares in Loadrunner which generates while recording WEB-HTTP/HTML protocol applications i.e web applications. Extrares records all available resources for each and every particular web url for example http://www.wikishown.com. We will see Extrares with examples and how it impact the response time of your web applications.

Extrares in Loadrunner


What is Extrares in Loadrunner,While generating or recording the test scripts in VUGen (Virtual User Generator) records each and every web url and in order to load that particular url it will check what are the extra files are associated with particular web url. As Extrares loads see below recorded code for more information.
web_url("wikishown", 
"URL=http://www.wikishown.com",
"Resource=0",
"RecContentType=text/html",
"Referer=",
"Snapshot=t8.inf",
"Mode=HTML",
EXTRARES,
"Url=images/bb_h_img2.jpg", ENDITEM,
"Url=images/bb_h_img1.jpg", ENDITEM,
"Url=images/bb_h_img3.jpg", ENDITEM,
"Url=images/loadingAnimation.gif", ENDITEM,
"Url=../favicon.ico", "Referer=", ENDITEM,
LAST);

EXTRARES recording all available images,java-script,j query, css files before loading the particular URL or pages in Virtual User Generator and while executing the Action first of all it will load all available resources i.e images,css etc files then it move to next step for execution,Here you will face problems for downloading resources because some time VUGen takes more time ,some time takes less times.

What should do in case Timeout for downloading resources


You can take below following below steps in order to overcome the problems,those are

1.Comment the EXTRARES in the script.
2.Increase Step download Timeout(Sec).
3.You can use web_set_timeout() function.

In case EXTRARES are commented while executing the Test script then it is not possible to estimate or calculate average response time for application transactions.It will look like below with comments.As per below script EXTRARES will not load and it will execute the step successfully.
web_url("wikishown", 
"URL=http://www.wikishown.com",
"Resource=0",
"RecContentType=text/html",
"Referer=",
"Snapshot=t8.inf",
"Mode=HTML",
/*EXTRARES,
"Url=images/bb_h_img2.jpg", ENDITEM,
"Url=images/bb_h_img1.jpg", ENDITEM,
"Url=images/bb_h_img3.jpg", ENDITEM,
"Url=images/loadingAnimation.gif", ENDITEM,
"Url=../favicon.ico", "Referer=", ENDITEM, */
LAST);

Step Download Timeout


Step download Timeout is one of the run time setting menu under Internet Protocols,please read Step Download Timeout(Sec) post for more details.Coming to third point you can use web_set_timeout("STEP","") function to increase the timeout before web_url() in order to specify more time for downloading available resources.The script looks like below with web_set_timeout().
web_set_timeout("STEP","60");
web_url("wikishown",
"URL=http://www.wikishown.com",
"Resource=0",
"RecContentType=text/html",
"Referer=",
"Snapshot=t8.inf",
"Mode=HTML",
/*EXTRARES,
"Url=images/bb_h_img2.jpg", ENDITEM,
"Url=images/bb_h_img1.jpg", ENDITEM,
"Url=images/bb_h_img3.jpg", ENDITEM,
"Url=images/loadingAnimation.gif", ENDITEM,
"Url=../favicon.ico", "Referer=", ENDITEM, */
LAST);

Let's understand the line web_set_timeout("STEP","60") ,here STEP indicates Time–out on each VuGen step ,indicates on which step timeout should apply.
STEP - indicates on which step timeout should apply
60 - Indicates how many seconds.

I hope you got good information on Extrares in Loadrunner,in case you like my post please provide your valuable comments and suggestions.Thank you for reading my website.