How to Do Load Testing Using Selenium & JMeter?

How to Do Load Testing Using Selenium & JMeter?

tudip-logo

Tudip

12 January 2019

About Load Testing using JMeter tool:

In terms of software testing process, performance testing is a non-functional testing process which works on the particular work loaded application, web application or system to determine how the application performs in terms of particular workload and how much the application is stable in workload situation. JMeter is an open source load testing tool to test the performance of static resources such as JavaScript and HTML, and also to test dynamic resources, such as JSP, Servlets, and AJAX. JMeter is provided with various graphical analyses reports of the performance test.

Requirements:

JMeter Installations:

  1. To install, simply unzip the zip/tar file into the directory where you want JMeter to be installed.
  2. Provided that you have a JRE/JDK correctly installed and the JAVA_HOME environment variable set, there is nothing more for you to do.
  3. You need to add all the selenium web driver support – JMeter plugins jars inside the JMeter lib folder.

Create a Selenium Script:

  1. You need to create a web driver script to run the application.
  2. Export the jar file of the web driver project.
  3. Insert the exported project jar file inside the JMeter => Lib => JUnit folder.

How to run JMeter:

  1. To run JMeter, run the jmeter.bat (for Windows) or JMeter (for Unix) file. These files are found in the bin directory.
  2. We can run using JMeter interface or directly on JMeter server using command line arguments.

Steps to set up the JMeter interface you have the ability to create a new Test Plan from an existing template:

  1. To create a new test plan: Click on menu File => New button.

JMeter-Creating-New-Test-Plan-1024x545

To do so you use the menu File Templates or Templates icon: You will see the new test plan as shown below:

JMeter-NewTestPlan-1024x545

  1. To add Thread Group, right click on your ‘Test Plan‘ => ‘Add‘ => ‘Threads (Users)‘ => ‘Thread Group‘ button as shown below.

JMeter-Adding-Thread-Group-1024x544

You will see the ‘Thread Group‘ as shown below:

JMeter-Thread-Group-1024x540

  1. Now, we need to add sampler i.e. JUnit Request
  2. To add JUnit Request: Right Click on ‘Thread Group‘ => ‘Add‘ => ‘Sampler‘ => ‘JUnit Request‘ button as shown below.

JMeter-Adding-JUnit-Request-Sampler-1024x540

You will see the ‘JUnit Request‘ as shown below:

JMeter-JUnit-Request-1024x541

  1. Now, we need to add listeners i.e. ‘View Result Tree‘ to see the sampler results.
  2. To add View Result Tree: Right Click on ‘Thread Group‘ => ‘Add‘ => ‘Listeners‘ => ‘View Result Tree‘ button as shown below.

JMeter-Adding-View-Result-Tree-Listener-1024x543

You will see the ‘View Result Tree‘ as shown below:

JMeter-View-Result-Tree-1024x544

  1. Now, we need to add listeners i.e. ‘Summary Report‘ to see the whole summary of sampler results.
  2. To add Summary Report: Right Click on ‘Thread Group‘ => ‘Add‘ => ‘Listeners‘ => ‘Summary Report‘ button as shown below.

JMeter-Adding-Summary-Report-Listeners-1024x576

You will see the ‘Summary Report‘ as shown below:

JMeter-Summary-Report-1024x543

  1. Now, we need to add listeners i.e. ‘Graph Results‘ to see the whole summary of sampler results.
  2. To add Graph Results: Right Click on ‘Thread Group‘ => ‘Add‘ => ‘Listeners‘ => ‘Graph Results‘ button as shown below.

JMeter-Adding-Graph-Results-1024x576

You will see the ‘Graph Results‘ as shown below:

JMeter-Graph-Result-1024x543

  1. Now, we need to add data writer listener i.e. ‘Simple Data Writer‘ to create the CSV file of the sampler results.
  2. To add Simple Data Writer: Right Click on ‘Thread Group‘ => ‘Add‘ => ‘Listeners‘ => ‘Simple Data Writer‘ button as shown below.

JMeter-Adding-Simple-Data-Writer-1024x545

You will see the ‘Simple Data Writer‘ as shown below:

JMeter-Simple-Data-Writer-1024x576

Steps to run the web driver script:

To import web driver script in the JUnit Request Sampler Note: Script jar file must be there in the JUnit folder of Apache JMeter.

  1. Open the JUnit Request sampler of the respective test plan.
  2. Search for JUnit 4 Annotations (instead of JUnit 3)
  3. Select class name from Classname drop-down, you will see your all classes inside the class name drop-down.
  4. Select the test method inside the Test Method drop-down, you will see all the test method present in the selected class name.
  5. We can update the Success message, Success code, Failure message, Failure code, Error message, Error code manually.
  6. We can append assertion errors, runtime exceptions in the JMeter console logs and log file.

To customize the Thread Group Property:

  1. We can customize the Thread Properties:
    1. We can increase or set the Number of users (Threads).
    2. The Ramp-up period can also be increased or set to a certain specific period.
    3. We can fix the Loop Count or set the thread group to Forever state.
    4. We can add the Scheduler Configuration to set duration and thread startup delay.

To create CSV file of all sampler results:

  1. Open the Simple Data Writer listeners.
  2. Select the folder to paste the CSV file from “Write results to file/Read from file” section.

To run the JUnit request:

  1. After selecting a test method and setting thread properties.
  2. To run the script, click on the “Run” button.
  3. Script will execute as per the thread properties and configuration.
  4. After successful test script execution, CSV or jtl file will automatically export into the selected folder in the above step.

To generate the HTML format or overall graph from CSV file the following can be done:

  1. Run the test in non-GUI mode and save the report as CSV or jtl format, using a command in JMETER_HOME/bin directory.

search
Blog Categories
Request a quote