Showing posts with label performance testing. Show all posts
Showing posts with label performance testing. 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.

Calculate Vusers for load testing

In this How to Calculate Vusers for load testing,you will learn calculate virtual users for your load testing or stress testing in order to achieve results which mimics real world.

What is load testing?


Load testing is describes how your application behaves for a given load at peak hours as well as how much time it will take to provide response for a particular request to verify your application speed,performance of the application.Load testing can be done with JMeter(Learn JMeter) or any other open source tool but in open source tool you can't run with more VUsers to check behavior of your applications.

Calculate Vusers for load testing


You can calculate number of vusers required for load testing with a basic formula as below

No of Vusers = TPS * (Response Time + Think Time)
TPS – Transactions per Second

Now here you can't simply provide 50,70,100,250,500 etc VUsers to test load on your applications,above requirements are given by the clients in below formats,then you have to calculate based on client requirements.

Business NFR:


Business NFR contains business requirements about application under test,in order to verify application performance with load testing.

Details:


Details will contain test scenarios.

Example : Verify Bank account details.

Business Rules:


Business rules contains actual results as per 3 months old data or 6 months old data with the help of analytic,Business Remarks gives below details about application(AUT).

Number of Transactions per Seconds : 600
Average Response Time : 3 sec
Think Time : 3 sec

So now it is easy to calculate number of virtual users required for a test scenario as below
Number of Virtual Users = 200*(2+1)
Number Of Virtual Users = 200*3
Number of Virtual Users = 600

So required virtual users for your test scenario is 600 VUsers for peak loads,some time users will vary may be less or more but in peak time users will increase suppose example as Festival time most of the companies running promotions on their applications to attract new users at that time number of users automatically increase,this is called peak load time.