LoadRunner - Basic Questions 1

Difference between lr_exit() and lr_abort()?

lr_exit(): 

  • lr_exit(LR_EXIT_ACTION_AND_CONTINUE, LR_AUTO); Exit without any condition, and go directly to end action
  • lr_exit(LR_EXIT_MAIN_ITERATION_AND_CONTINUE, LR_AUTO);Stop current action, and go to the next action
  • lr_exit(LR_EXIT_ITERATION_AND_CONTINUE, LR_AUTO); Stop current iteration, and go to the next iteration. If called from within a block iteration, only the block iteration will be exited, and not the global iteration
  • lr_exit(LR_EXIT_VUSER_AFTER_ITERATION, LR_AUTO); Run until the end of the current iteration and then exit
  • lr_exit(LR_EXIT_VUSER_AFTER_ACTION, LR_AUTO); Run until the end of the current action and then exit


lr_abort():
The lr_abort function is used to abort the execution of a Vuser script. 
It instructs the Vuser to stop executing the Actions section, execute the vuser_end section and end the execution

How to set correlation rules?

Pre-requisite:  You know the left and right boundary for the session ID

Step 1: Open the recording option -> Correlation -> Check "Enable correlation during recording"
Step 2: Click on New Application and enter the name of the application. 
Step 3: Select the application in the left panel and Click on New Rule. Then enter the rule name "Session ID". In the right hand side, you need to update the left and right boundary value. Also provide the correlation variable name. For example "Param_SessionID".
Step 4: Click on Advance button. Check "Replace with parameter only for exact parameter". Then click on OK.
Step 5: Start recording the business flow. Once the recording is done, check the script. 

VuGen automatically done the correlation for Session ID and replaces all the occurrences.

Difference between Application and Web server?

1. Application Server supports distributed transaction and EJB. While Web Server only supports Servlets and JSP.
2. Application Server can contain web server in them. most of App server e.g. JBoss or WAS has Servlet and JSP container.
3. Though its not limited to Application Server but they used to provide services like Connection pooling, Transaction management, messaging, clustering, load balancing and persistence. Now Apache tomcat also provides connection pooling.
4. In terms of logical difference between web server and application server. web server is supposed to provide http protocol level service while application server provides support to web service and expose business level service e.g. EJB.
5. Application server are more heavy than web server in terms of resource utilization.

Example: Apache Tomcat HTTP Server is Web Server and Oracle WebLogic is Application Server.

What is and does Standard deviation indicates?

The Standard Deviation is a measure of how response time is spread out around the Mean. Simply say, the smaller the Standard Deviation, the more consistent the response time.

Scripting REST API in LoadRunner

With example for bot GET and POST

GET:

You will have a URL with all variables in it.
Test it manually in SOAP UI
Try to observe the difference in passed and failed transaction to add conditon in LR script

In Load Runner:

Take Protocol as Web HTTP/HTML
Get web_custom_request from View - Step Tool Box.
Put URL and Click OK.
Parameterize the variable in URL

web_reg_save_param("c_response","LB=","RB=",LAST);

    web_reg_save_param("c_employeeName","LB=\"employee_name\":\"","RB=\",\"",LAST);
   
    lr_start_transaction("Start_transaction_1");

    web_custom_request("web_custom_request",

        "URL=http://dummy.restapiexample.com/api/v1/employee/{p_EmployeeId}",
        "Method=GET",
        "TargetFrame=",
        "Resource=0",
        "Referer=",
        "Body=",
        LAST);
lr_end_transaction("Start_transaction_1"LR_AUTO);


POST:
You will have a URL with all variables in it.
Test it manually in SOAP UI
Try to observe the difference in passed and failed transaction to add conditon in LR script

In Load Runner:

Take Protocol as Web HTTP/HTML
Get web_custom_request from View - Step Tool Box.
Put URL, request and convert it in C format bt right click option
Parameterize the input variables

web_reg_save_param("c_full","LB=","RB=",LAST);

    web_reg_save_param("c_id","LB=\"id\":\"","RB=\"}",LAST);
   
    lr_start_transaction("POST_Transaction");
    web_custom_request("web_custom_request",
        "URL=http://dummy.restapiexample.com/api/v1/create",
        "Method=POST",
        "TargetFrame=",
        "Resource=0",
        "Referer=",
        "Body={\"name\":\"{p_name}\",\"salary\":\"{p_salary}\",\"age\":\"{p_age}\"}",
        LAST);
    lr_end_transaction("POST_Transaction"LR_AUTO);

Data Source and DB connection

How to check Data source:

Login to weblogic console. In Domain structure tree, Go to Services, then select Data Sources,
On the Summary of Data Sources page, click the data source name.
Select the Monitoring: Statistics tab.
Statistics are displayed for each deployed instance of the data source.

How to check Database connection:

YOu need to have db permission to access below query:
select sid, serial#, osuser, machine, program, module from v$session;
SELECT SID, Serial#, UserName, Status, SchemaName, Logon_Time FROM V$Session WHERE Status='ACTIVE' AND UserName IS NOT NULL;

History Table:
v$active_session_history

Trigger LoadRunner scenario from Jenkins

In this blog we will see how to trigger LoadRunner Scenario from Jenkins

First we need to create a LR scenario and set the SLA configuration (mandatory) and  result settings. 

Using Command Line:

We have a provision in LR to run the scenario using Windows Command prompt by using Wlrun.exe and CLIControllerApp.exe based on the version you have.

Syntax:
LoadRunner\bin\Wlrun.exe -Run -TestPath C:\scenario.lrs -ResultName C:\ControllerResultPath\Res

LoadRunner\bin\CLIControllerApp.exe -TestPath C:\scenario.lrs -CollateAndAnalyze -ResultName C:\ControllerResultPath\Res

We will continue with Wlrun.exe example for now:

Create Jenkins projects and Go to Configure.

In Build section click on 'Add build step' dropdown and choose 'Execute Windows batch command'

Since Jenkins takes one command only, we use below syntax. Please use double quote ("")  which your path contains space (white space).

cd "C:\Program Files (x86)\HPE\LoadRunner\bin\" & Wlrun.exe -Run -TestPath "C:\Users\OneDrive - USER\Scenario\Test_Scenarios.lrs" -ResultName "C:\Users\OneDrive - USER\Result\Res"

Apply and save and you will find results update once test is completed.

Open Issue:

  • Controller wasn't launching but manually on Command prompt using same command it is launcing.
  • Below command is working on Command prompt but not in jenkins:
Call "C:\Program Files (x86)\HPE\LoadRunner\bin\Wlrun.exe" -Run -TestPath "C:\Users\OneDrive - USER\Scenario\Test_Scenarios.lrs" -ResultName "C:\Users\OneDrive - USER\Result\Res"


Using Micro Focus Application Automation Tools plugin:

Firstly you need to install the plugin and then create the project.

Go to configure and then build section.
Click on 'Add build step' dropdown and choose 'Execute Micro Focus test from file System'

You need to update Test Field with path of your Load Runner scenario and Result Directory with Result path where you want to store it.

Click on LoadRunner Setting and you may change if need.

Click Save and Apply and Test the build.

You can configure Email for failed builds as well.

Email configuration in Jenkins

Please read the following blog to install Jenkins in Windows - Jenkins Installation for Windows

We need to install below plugin for Email from install page of Jenkins - 'Email Extension Plugin'

After installation restart Jenkins and we need to first configure default Email settings.

Default Email Setting:

From Home page, go to Manage Jenkins.

Then click on Configure System.
Fill the details for Extended E-mail Notification:
  • SMTP Server: Check with your team or admin or use gmail (smtp.gmail.com)
  • Click on Advance and then fill
  • SMTP port: Check with your team or admin or use gmail (465)
  • Default Receipients - Your receipents Email ID
  • Reply To List - Your Email ID
  • Default Subject - $PROJECT_NAME - Build # $BUILD_NUMBER - $BUILD_STATUS!
  • Default Content -  $PROJECT_NAME - Build # $BUILD_NUMBER - $BUILD_STATUS:
Check console output at $BUILD_URL to view the results.

After this you can Test Email by using E-mail Notification

Provide same details as above and check 'Test configuration by sending test e-mail'

Build Email notification:

Go to your project for which you want to send Email.

Go to Configure and then Post-build Actions.

Click on button - Add post-build action

select E-mail Notification.

Fill in the details.

Customized Email for every build run:

Go to your project for which you want to send Email.

Go to Configure and then Post-build Actions.

Click on button - Add post-build action

select 'Editable E-mail Notification'

Fill the below details

Java Heap Dumps

As name suggest, Heap dumps are only for java processes.

Commands to take heap dumps:

  • jmap -dump:live,format=b,file=heap.process_name.prof <PID>
  • jmap -dump:live,format=b,file=/home/Dumps/heap.process_name.prof <PID> 

Thread Analysis:

For analysis, we can use Java VisualVM and Eclipse Memory Analyzer

Heap Dump Parameter:

-Xms          set initial Java heap size in m,g or M,G (and not MB or GB)
-Xmx          set maximum Java heap size in m,g or M,G (and not MB or GB)

Garbage Collection:
In Java, there is object life cycle as below:

  • Object creation
  • Object in use
  • Object destruction

We need to clean object to release memory else we will have heap memory reaching 100%. Garbage collection is a way in Java which happens automatically and below are the available algorithm:


  • Mark and sweep:


  • Concurrent mark sweep (CMS) garbage collection:

To use CMS GC, use below JVM argument:
-XX:+UseConcMarkSweepGC


  • Serial garbage collection:

To use Serial GC, use below JVM argument:
-XX:+UseSerialGC


  • Parallel garbage collection:

To use parallel GC, use below JVM argument:
-XX:+UseParallelGC


  • G1 garbage collection:

If you want to use in Java 7 or Java 8 machines, use JVM argument as below:
-XX:+UseG1GC

Thread Dump

Thread dumps are only for java processes.

Commands to take thread dump:

  • jstack -l  <pid> > threaddump.txt
  • kill -3 <pid>
  • jcmd <pid> Thread.print > <file-path>

Thread Analysis:

Thread dumps should be taken multiple times to get exact issue and one dump is not sufficient and may mislead the investigation. We should atleast take 3-5 thread dumps at an interval of 10 secs.30 sec or 1 minutes as per the performance issue.

To analyse, take the thread dumps and upload the files in site - fastThread Java Thread Dump Analyzer

Thread Status:

  • NEW: The thread is created but has not been processed yet.
  • RUNNABLE: The thread is occupying the CPU and processing a task. (It may be in WAITING status due to the OS's resource distribution.)
  • BLOCKED: The thread is waiting for a different thread to release its lock in order to get the monitor lock.
  • WAITING: The thread is waiting by using a wait, join or park method.
  • TIMED_WAITING: The thread is waiting by using a sleep, wait, join or park method. (The difference from WAITING is that the maximum waiting time is specified by the method parameter, and WAITING can be relieved by time as well as external changes.) 


Scripting Web Services in Load Runner


Below are the steps to follow for scripting web services to load testing.
  • Get WSDL - Also called endpoint
  • Get Request XML - Also called request payload
  • Test in SOAP UI/POSTMAN - Test manually if proper response payload in fetched
  • Open Load Runner. Open new script with protocol as Web Services.
  • Go to Action page.
  • Go to View in Menu bar, click Step ToolBox.
  • Search web_customer_request.
Fill the below details:
METHOD: POST
POST requests supply additional data from the client (browser) to the server in the message body. In contrast, GET requests include all required data in the URL.
URL : your wsdl
Body: Copy and paste entire request. select all and right. Convert to C.

Click OK.

  • Now add below line above your web_custom_request:

web_reg_save_param("c_response","LB=<responseCode>","RB=</responseCode>","ORD=1");
lr_start_transaction("client_project_application_transaction_name");

After this will be your web_custom_request code:
web_custom_request("web_custom_request",
.
.
.
"</soapenv:Envelope>",
LAST);


  • Finally below code to check if you received pass response code or failed. You can add more validation in request response.

if (strcmp (lr_eval_string("{c_response}"),"3001") == 0)
        {
           lr_end_transaction("ngcc_bcm_retrieve_voucher_info", LR_PASS);
           
        }

else
{
lr_end_transaction("ngcc_bcm_retrieve_voucher_info",LR_FAIL);
  //lr_output_message ( "Response Ticket#%s", lr_eval_string ( "{c_ticket}" ) );

            lr_continue_on_error( 0 );
            lr_exit( LR_EXIT_ITERATION_AND_CONTINUE, LR_FAIL );
}

Web functions in loadrunner

web_reg_save_param
web_reg_save_param is THE most important function when you are working with LoadRunner. It is used for correlation.
web_req_save_param(“c_sessionid”,“NOTFOUND=ERROR”,”LB=Session”,”RB=}”,“ORD=1”,LAST);

web_set_max_html_param_len

To retrieve a string longer than 256 characters, use web_set_max_html_param_len to increase the maximum valid length.
web_set_max_html_param_len("1024");

web_custom_request

Allows you to create a custom HTTP request with any method supported by HTTP. We usually use it for web service scripting and method could be used from Step Toolbox in View Menu in Menu bar of Load Runner. It includes End point, Method (GET/POST), Body (Request payload) etc.

web_global_verification

web_global_verification("Text=Exception","Fail=Found","ID=MyAPP",LAST); 
In this example if the string Exception is found, the script execution stops.

web_add_auto_header:
web_add_auto_header function is used to add header to all the consecutive HTTP requests. It happens that you need to pass the log on session id in all the subsequent HTTP request and this can be done with this function,

Syntax : web_add_auto_header( const char *Header, const char *Content );
Example : web_add_auto_header("Authorization",lr_eval_string("{c_token}"));
                    web_add_auto_header("pwd", "northanger1803");