Wednesday, February 28, 2018

Selenium Webdriver Scripts Using Jmeter

1.     Introduction

Modern day websites and the web applications are using and a lot of advanced features to make the client experience better and AJAX and JavaScript based logic plays a vital role in developing such features. Companies are also trying to make the websites prettier by using some cool graphics. However, this demands an increased level of processing at the browser end and using some rich graphic content that could make the application performing slowly if the enhanced features are not handled properly.

Most of the leading performance testing tools capture the response time on the protocol level which doesn’t include the client side rendering time. In addition, it requires advanced level of scripting skills in simulating AJAX calls using conventional load testing tool. Selenium webdriver scripts are a good choice to test the E2E performance of the web applications and to capture the response time inclusive of client-side rendering time.

To use Selenium Webdriver with Jmeter simply install the Webdriver set of plugins using the Plugins Manager which is available at https://jmeter-plugins.org/wiki/PluginsManager/

Simply follow the given steps:
-       Download the Plugins Manager JAR file
-       Put the file in the lib/ext directory
-       Restart JMeter
-       Click “Options” and then “Plugins Manager”



2.     Download Webdriver Plugins

Once you have “Plugins Manager” installed, you can simply go to available Plugins section and down download “Selenium/Webdriver Support” plugin. This will require a restart of Jmeter.

In the following diagram “Selenium/Webdriver Support” plugin is already downloaded and available under Available Plugins section.


After the Jmeter restart, you can find the “Webdriver Sampler” under the sampler section

 
 Webdriver set of plugins support Firefox browser out of the box. However, if you like to use Chrome or Internet Explorer then it will require some additional setup.

To use Chrome or Internet Explorer browser, simply download Chrome or IE driver using the below link and provide the path if the driver under the driver Config Element



Chrome driver config can be download from https://jmeter-plugins.org/wiki/ChromeDriverConfig/ and place the .exe file under the Bin folder of Jmeter or set the path of the EXE file under driver config.



We are ready to begin with the scripting now. All you need to add in your test plan is the Chrome Driver Config Element, Web Driver Sampler (Number of samplers depends on the testing needs), Cookie Manager, Cache Manager and View Results Tree.


3.     Webdriver Sampler Scripting

In this example, we are going to script a simple flow of opening the duckduckgo.com website, Searching Load testing Keyword and clicking on one the results link.
Here is the code you will require to do this:

//Common Code in all the Samplers

var pkg = JavaImporter(org.openqa.selenium); //Import Java Selenium Pacage
var support_ui = JavaImporter(org.openqa.selenium.support.ui.WebDriverWait); //WebDriver wait package classes
var wait = new support_ui.WebDriverWait(WDS.browser, 5000); //Wait 5 seconds until page loads

WDS.sampleResult.sampleStart(); //Sampler starting point
WDS.log.info("Sample started"); // This will log the information for us

// Transaction related code

WDS.sampleResult.sampleEnd();

//Transaction-1 Launch Website

WDS.browser.get('http://duckduckgo.com'); //opens website specified in 'http://duckduckgo.com'
WDS.log.info("navigated to duckduckgo.com");

//Transaction-2 Search Keyword

var searchField = WDS.browser.findElement(pkg.By.id('search_form_input_homepage')); //saves search field into searchField
searchField.click(); //clicks search field
searchField.sendKeys(['Load testing']); //types word "blazemeter" in field
WDS.log.info("Searched for Load testing");

var button = WDS.browser.findElement(pkg.By.id('search_button_homepage')); //Find Search button
button.click(); //Click Search Button
WDS.log.info("Clicked on the search button");

//Transaction-3 Open Link

var link = WDS.browser.findElement(pkg.By.id('r1-0')); // Clicks on the first link.
link.click(); //Click the search result's Link

var link = WDS.browser.findElement(pkg.By.id('firstHeading')); // wait for the page to be loaded

The script would look like this:



4.     Selenium IDE Chrome Extension Plugin

To use the selectors we can use the “Selenium IDE” Add-on, which is available at https://docs.seleniumhq.org/download/ . Selenium IDE is a Firefox add-on with a recording option for actions in the browser. To get similar selectors for other browsers, download and install the add-on.

In this example, I have downloaded the Selenium IDE extension for Chrome. Once it is successfully installed, you can see the icon in the browser



Open Duck Duck Go and Selenium IDE. Set the Selenium IDE’s base URL https://duckduckgo.com/ and start recording. Type “Load testing” and click Search open the link after that. If you open Selenium IDE, you see the captured actions and selectors.



All the captured actions can be manually converted to the webdriver format


Action and Command
Webdriver Code
Launch Website
Open
WDS.browser.get('http://duckduckgo.com');
Click at Search Box
Click at id= id=search_form_input_homepage
var searchField = WDS.browser.findElement(pkg.By.id('search_form_input_homepage'));
searchField.click();
Type Keyword
Type id=search_form_input_homepage
searchField.sendKeys(['Load testing']);
Click Search Button
Click at id= search_button_homepage
var button = WDS.browser.findElement(pkg.By.id('search_button_homepage'));
button.click();

Friday, February 23, 2018

Jmeter Results Visualisation Using InfluxDB Grafana


1.     Introduction

This article provides the details of setting up InflxDB and Grafana for performance test monitoring using Jmeter. Running Jmeter tests in command line mode provides a benefit of running the performance tests without consuming much system resources, also, provide the ability to scale the user load on any machine. However, one has to wait until the end of the test to view the results. InfluxDB and Grafana provide a feature to store and analyse time-series data respectively and could be used to real-time monitoring of the.

Installing InfluxDB and Grafana is a bit tedious task, but Blazemeter recently provided a white paper to install the InfluxDB and Grafana using Docker.

Blazemeter provides all the necessary setup files, which could be downloaded straight to your computer and can be used with Docker.

Setting up InfluxDB and Grafana involves the following steps
·        Installation of Docker
·        Installation of InfluxDB and Grafana
·        Setting up Grafana and Datasource
·        Setting up Jmeter Dashboard

2.     Installation of Docker

Download the Docker community edition from https://www.docker.com/community-edition and follow the installation instructions.

Open the PowerShell or command prompt and type “docker --version” to verify the successful installation of Docker. Given command returns the installed version details of Docker.

3.     Installation of InfluxDB and Grafana using Docker

Once you have Docker and Docker Compose successfully installed and up and running. Next step would be to download the Docker file created by Blazemeter using following link

Place the downloaded unzipped files to a folder and then follow the following steps
1.      Open the console
2.      Navigate to “DockerGrafanaInfluxKit-master” folder
3.      Run the command: > docker-compose up
If you see the following screen then the installation is successful

if you open http://localhost:3000 after the installation you should see your Grafana:


You can login using the default user ‘admin’ and ‘admin’ password. Also, if you go to the Grafana data sources configuration (Left top menu button -> Data Sources) you will see that the installed Grafana already has an inbuilt configuration with an InfluxDB instance that we are running in a separate docker container:


To be 100% sure that the integration works correctly, you can click on the ‘InfluxDB’ data source, scroll down to the end of the page and click on ‘Save and Test’. If you got ‘Data source is working’ which means your lightweight monitoring environment is ready and verified!


Following details will be required to set up the performance test monitoring using Jmeter
·        Host address: localhost or 127.0.0.1
·        Database port: 8086
·        Database name: influx
·        Database username: admin
·        Database password: admin

4.     Setting up Jmeter

To setup the Jmeter to push the data to Influx DB you will require the Backend Listener in you test plan, however to use the Jmeter dashboard provided by Grafana you will require to include the “JMeter-InfluxDB-Writer 1.2” jar file into the /lib/ext directory of your JMeter installation. Jar file can be downloaded using following link. https://github.com/NovaTecConsulting/JMeter-InfluxDB-Writer/releases/tag/v-1.2  
Restart your Jmeter and include the backend listener with the following values.

5.     Setting up Jmeter Dashboard

Next step is to setup the Jmeter dashboard. Simplest way to do this is to use the Jmeter Dashboard and you can download this Grafana template in json format using link https://grafana.com/dashboards/1152


After that, open Grafana and instead of the new dashboard creation go to:

Menu -> Dashboards -> Import and choose “Download JSON”, specifying the data source that we have just created for that example:


After that, by clicking on “Import” we will automatically create outstanding JMeter monitoring dashboard


Sunday, January 24, 2016

JavaScript: String And Math Functions

Introduction of JAVAScript as an alternate scripting languages in Loadrunner version 12.50  gives the flexibility to the Performance Test Engineers to leverage the capabilities of existing JAVAScript functions to code various custom logics. 

I am going to describe couple of pre built JAVAScript String and Math functions which will make your life bit easier. 
Date.js
Working with dates are always tricky. So many dots, slashes and formats. Datejs is a stunning library for simple to complex date functions. It can parse dates like: “Next thursday”, “+2 years” and all formats like 2009.01.08, 12/6/2001 etc.
Sylvester
This is a JavaScript library for doing vector and matrix math easily, without using a lot of loops and getting lost between arrays. It includes classes for modelling vectors and matrices in any number of dimensions and for modelling infinite lines and planes in 3D space.
Pretty Date 
A smart JavaScript solution for displaying dates within the past month in a prettier and more user-friendly way. It displays dates relative to the current time; for example, “Yesterday,” “3 hours ago,” etc.
Pretty Date
XRegExp
Regular expressions can be already used in JavaScript with the RegExp object.XRegExp adds more power to RegExp with features that will be part of the browsers of tomorrow (according to proposals for ECMAScript 4 – ES4). Using the library, RegExp objects can be cached and reused, modifiers can be added to existing RegExp objects and more.
JavaScript URL Library
A library for handling and manipulating URLs more easily. It is possible to reach every part of a URL as a string and modify it when needed. This URL library is very new but already works as mentioned.

ASP .NET Application Monitoring

This article describes the basic monitoring required to drill down any ASP .NET related performance issues. It's always good to have more performance data than not enough, especially when you experience a problem that is not easily reproduced. This article will describe some necessary Performance Counters and logs required to be looked into while analysing ASP .NET application's performance issues.

Monitoring Performance Counters:
There are many performance counters that are useful for monitoring performance of ASP .NET application. Below are the few important ones. 

  • Processor(_Total)\% Processor Time
  • Process(aspnet_wp)\% Processor Time
  • Process(aspnet_wp)\Private Bytes
  • Process(aspnet_wp)\Virtual Bytes
  • Process(aspnet_wp)\Handle Count
  • Microsoft® .NET CLR Exceptions\# Exceps thrown / sec
  • ASP.NET\Application Restarts
  • ASP.NET\Requests Rejected
  • ASP.NET\Worker Process Restarts (not applicable to IIS 6.0)
  • Memory\Available Mbytes
  • Web Service\Current Connections
  • Web Service\ISAPI Extension Requests/sec

  • Monitoring Logs:

    Event Log:

    It is critical to monitor the event log for messages from ASP.NET and Microsoft Internet Information Server (IIS). ASP.NET writes messages to the application log, for example, each time the aspnet_wp worker process terminates IIS 6.0 writes messages to both the application and/or system logs, for example, each time the w3wp worker process reports itself unhealthy or crashes. It is quite easy to write a .NET application that reads the application log and filters out messages from ASP.NET and IIS, and fires an alert (sends e-mail or dials a pager) if necessary.

    W3C and HTTPERR Logs:

    First, enable W3C logging for IIS through the Internet Information Services (IIS) Manager. This log can be configured to include various data about the requests, such as the URI, status code, and so on. Scan the log for error codes such as 404 Not Found, and take action to correct links, if necessary. It also contains substatus code in the log and is useful for debugging. IIS uses substatus codes to indentify specific problems. For example, 404.2 indicates that the ISAPI extension handling the request is locked down. 
    New for IIS 6.0, malformed or bad requests and requests that fail to be served by an Application Pool are logged to the HTTPERR log by HTTP.SYS, the kernel-mode driver for handling HTTP requests. Each entry includes the URL and a brief description of the error.
    Check the HTTPERR log for rejected requests. Requests are rejected by HTTP.SYS when the kernel request queue is exceeded, and when the application is taken offline by the Rapid Fail Protection feature. When the first issue occurs, the URL is logged with the message QueueFull, and when the second occurs, the message is AppOfflineCheck the HTTPERR log for requests lost due to a worker process crash or hang. When this occurs the URL will be logged with the message,Connection_Abandoned_By_AppPool, for each in-flight request. An in-flight request is one that was sent to a worker process for processing, but did not complete before the crash or hang.

    Thursday, December 17, 2015

    REST (REpresentational State Transfer)

    REST (REpresentational State Transfer) is a software architecture style of the World Wide Web. Systems and web services which follows the REST architecture are also known as RESTful systems/web services.

    In REST Architecture everything is a resource, REST interfaces with external systems using resources identified by Uniform Resource Identifier (URI), for example /Books/WingsOfFire, which can be operated upon using standard HTTP methods, such as PUT /Books/WingsOfFire .

    RESTful systems are light weight, highly scalable, stateless and maintainable and are very commonly used to create APIs for web based applications.

    RESTful systems usually communicates over HTTP and leverages the capabilities of HTTP methods- GET, POST, PUT, DELETE etc. which browsers typically use to retrieve web pages.






    Friday, October 31, 2014

    Pre-requisite for SAP GUI Protocol scripting in Loadrunner

    The fundamental requirement of Loadrunner to record and run SAP GUI scripts requires few settings at client and server side. Here are the main settings you need to incorporate:
    1. Enable scripting at client side:
    • Install SAP GUI client on Vugen
    • To ensure that scripting is available on the client-end, check that there is a Scripting directory located in the SAP GUI installation directory.  If this directory does not exist, then the SAP Scripting API is not installed and you must reinstall SAP GUI with the SAP Scripting API option.
    • Once you have script SAP GUI complete package installed, configure all the required systems in SAP GUI, You will require the details of servers like server name, system number etc.
    • Ensure you have connectivity between SAP GUI and SAP server, if not then request for necessary ports to be opened.
    • You need to enable Scripting as circled in the red colour in the screen shot below and disable all check boxes as shown in the screen shot shown below. In order to do this, log on to SAP server, select the “Rainbow” Icon and select “Options”. And you must disable the remaining two check boxes
      - Notify When a Script attaches to a Running GUI
      - Notify When a Script Opens a Connection

     
     
     
     
     
     
     
     
     
     
     
     
     
     
     
     
     
     
     
     
     
     
     
    2. Enable scripting at server side:
    • Logon to SAP with a user with required privileges, User ID need to have proper privilege to enable scripting at server side. Basis should be able to provide you administrative privilege to do the same.
    • Logon to SAP using SAP GUI, run the transaction rz11, and enter parameter name sapgui/user_script.
    • Enable the parameter with the Current value changed to TRUE.  Save it and enable the changes on all the servers and scripting will be enabled the next time you log on.  

    Thursday, October 30, 2014

    SAP Performance/Volume testing

    Its is always recommended to performance/volume test your SAP applications as SAP systems has specifically configured to the critical business processes. A successful performance testing confirms that underlying hardware and infrastructure is able to support the required transaction volume and able to generate desired response time for the critical processes.
    SAP provides a wide range of products:
    • Customer Relationship Management (CRM)
    • Enterprise Resource Planning (ERP)
    • Product Lifecycle Management (PLM)
    • Supply Chain Management (SCM)
    • Supplier Relationship Management (SRM)
    SAP's products focus on Enterprise Resource Planning (ERP). The company has no main product as different products serve to meet the different needs of businesses. Now a days businesses are looking for a software product that handle all the companies needs, from inventory management, invoicing customers, sales and distribution and controlling the whole business planning in one module. This need from businesses lead to the development of SAP Enterprise Central Component [ECC] system. SAP ECC offers the opportunity to integrate all software data programs by all departments by using one single database.

     
     
     
     
     
     
     
     
     
     
     
     
     
     
     
     
     
     
     
     
     
     
     
     
     
     
    Following diagram depicts the 3-tier architecture of a typical SAP system
     

     
     
     
     
     
     
     
     
     
     
     
     
     
     
     
     
     
     
     
    Effective performance test planning plays a vital role in the success of a SAP performance/volume test project. Outcome of the performance test planning phase should indicate the things and order of activities need to be performed. Typical outputs of a planning phase are performance test strategy/ test plan, critical business scenarios, Targeted transaction volume and response time, SLAs, Test data requirements, Risks and mitigation plan etc.
    Non functional requirement (NFR) documents is one of the key documents which may provide next level of details while planning, NFR should state all performance/volume testing related requirements very specifically like Expected transaction response time or Dialog response time or work process response time. Different architects may use different terminologies while referring to response time in the world of SAP projects, So it is recommended to understand the requirement very specifically.
     
    Effective and realistic performance/volume testing requires to test the SAP systems with two main processes which is Online users and Batches/reports. Batches plays an important role while we are doing performance test to identify the capabilities of underlying hardware and infrastructure. Its is recommended to understand the 24Hrs round the clock load profile of the system and to identify the points where there is overlap between peak online user load and batches running in parallel. Along with this standalone batch jobs performance testing is also critical for the daily/weekly/monthly and yearly batches which are business critical or resource intensive. NFR document should explicitly mention the expectation and SLAs for the batches.
    Based on the identifies business scenarios/batches, performance test could be conducted with three possible combinations
    1. Standalone peak online user load test.
    2. Peak Online+ Batches performance test
    3. Standalone batch performance test
     
    Batches and the interfaces with the legacy/External and third party systems also plays a key role in the performance of the SAP system, we should identify the times where we may received significant load coming from these systems and SAP system has to process the scheduled and ad-hoc requests arriving from these systems.
    Successful testing of batches will give us indication of the records or data processed within a given period of time, batches are more prone to have performance deficiency and highly vulnerable to the poor SQL queries, work process consumption, high number of enque and lock entries etc.
     
    Another important factor in planning the performance and volume test in test data, You should have a clear understanding of the load profile you are going to simulate as part of performance testing. Its is must recommended that test environment should have the data similar to production and volume test results will impact a lot if these are performance with lesser data in test environments compared to production. For newly built system you may have zero or very few records in the database which is expected to grow over the time, in such cases there will be a difference in the response time in production and the one you received during performance testing when testing was conducted on empty or with very few records on database.
    Expectation should be set clearly with the stakeholders and project management like who is going to create the data and how data will be populated into the test environment and the efforts required to create test data.
    There also should be a clear understanding of who is going to create the user IDs with appropriate role and number of user IDs required. User IDs with improper role may not be able to perform the required operation. Role based testing should also be discussed with stakeholders very specifically.
    Following diagrams depicts a typical performance test lab setup
     
     
    Please note that load generators running SAP GUI users should have SAP GUI installed on the machines. System resource requirement to run a single SAP GUI user is much higher than a typical web user, based on the specifications of your load generators machines you should calculate the footprint of the system resource utilization by a single SAP GUI user and accordingly you van calculate the Load generator machines required to accommodate your needs.