Run Selenium on Jmeter

This tutorial is basically for testers who have their written Selenium test scripts. Also testers who wants to use their existing selenium test scripts to load and performance testing using Jmeter.

Jmeter is a powerful tool which you provide several functionalities to run your selenium scripts to get testing statistics.

Step 01

Export Selenium Script

You should have junit test cases to export from eclipse as a jar file.

  1. right click on the project
  2. select export
  3. export as jar file

Step 02

Run Script on Jmeter

  1. click on test plan and browse the jar file you need to add.
  2. right click on test plan and add a thread group.
  3. right click on thread group and add->sampler->Junit request
  4. Then you can select the classname and test methode to run on the jmeter.

Note: If you have existing test scripts written using other test frameworks like testng, so far jmeter doesn’t support testng but we could use beanshell sampler to execute testng test scripts.

but if you use testng as your test frameworks, you could do all the load and performance testing without using Jmeter 🙂

Jmeter Setup For Selenium

This tutorial will give you an idea about the jmeter and each step to install jmeter; instruction to setup for selenium automation testing to load and performance testing.

What is Jmeter ?

The Apache JMeter™ application is open source software, a 100% pure Java application designed to load test functional behavior and measure performance. It was originally designed for testing Web Applications but has since expanded to other test functions.

JMeter is not a browser, it works at protocol level. As far as web-services and remote services are concerned, JMeter looks like a browser (or rather, multiple browsers); however JMeter does not perform all the actions supported by browsers. In particular, JMeter does not execute the Javascript found in HTML pages. Nor does it render the HTML pages as a browser does (it’s possible to view the response as HTML etc., but the timings are not included in any samples, and only one sample in one thread is ever displayed at a time).

You can learn more about jmeter using this link.

Install Jmeter And Selenium Setup

Install Jmeter

Prerequisites

  1. Your computer needs to be installed Java 7 or above before proceeding to the Jmeter installation.  You can download the Java from this link.

Installation Steps

  1. Download Jmeter file from this link. (download binaries zip to install on windows and other tgz to install on linux. Also you download the source codes as well since it’s open source 🙂 )
  2. Once you download the zip or tgz file, extract it in you computer on preferred location.
  3. Go to the extracted root folder, then redirect to bin, open ApacheJmeter.jar (You may ask running platform when it’s open at the first time, select java)

That’s all Enjoy Jmeter.

Untitled

Install Plugin Manager in Jmeter

My opinion is installing plugin manager in jmeter is a must. We could easily install plugins though the plugin manger without confusing jar files copy pasting. Please go through below easy step to install plugin manager in Jmeter.

  1. Download the plugin manager Jar file using this link.
  2. After installing the jar files, paste in the following path, <jmeter root folder>/lib/ext
  3. restart the jmeter.
  4. verify plugin manager installation once jmeter restarted; go to the Options menu->plugin managerplugin_menuplugin_manager

Install Selenium Webdriver Plugin

  1. Open plugin manager.
  2. navigate to the available plugin tab.
  3. search selenium webdriver and tick on selenium webdriver support plugin.
  4. press install and restart jmeter button. sel_web_support_plugin

Configure Chrome/Firefox Driver

To run the selenium testscripts we need to configure chrome or firefox drivers in Jmeter. For that you need to create a testplan; file->new; then you could create a new test plan.

Now you have to create a thread group for that; right click on newly created test plan->add->Threads(Users)->Thread group

create_thred_group

Now you can create a configuration for Chrome or firefox. In here chrome configuration is illustrated, You could do the firefox and other browser configuration by following the same steps.

To create the configuration file; right click on previously created thread group->add->config element->Chrome driver config

chrome_driver_config_path

Once you created the chrome driver config, you will see a window as below. Navigate to the chrome tab and insert the chrome driver exe file path.

If you don’t have the chrome diver exe file; you can download from this link.

chrome_driver_config

Now you have successfully created the configuration for chrome.

Create a Listener

You could create a listener to listen the results of our test cases. It gives the end results of our test cases. Mostly used to get statistics for performance test results.

There are several listeners available in Jmeter, we use tree view listener for our exercise.

right click on previously created thread group->add->listener->View Results Tree

tree_listener_path

Create a Webdriver Sampler

We could create a webdriver sampler and directly write selenium test scripts through Jmeter, else if you have pre-written selenium scripts you could export it to a jar file and run it through the Jmeter. For more go to this link.

For this exercise, we will create a webdriver sampler and execute a simple selenium script.

to create a webdriver sampler right click on previously created thread group->add->sampler->WebDriver Sampler

web_driver_sampler_path

driver_sampler

Running the Script

Before running the script make sure, you have followed all the steps above. Your final setup should be like below,

driver_sampler

In the webdriver sampler, you could write your selenium script and run it by pressing green color arrow button (start button).

You can change the thread properties in Thread Group and run the scripts in different ways.

thread_properties

Also by opening the View Results Tree, you could see the end results of your test plan.

That’s all Friends. Happy Testing.

 

 

Install TestNG On Eclipse Oxygen

What is TestNG ?

TestNG is a testing framework inspired from JUnit and NUnit but introducing some new functionalities that make it more powerful and easier to use

such as:

  • Annotations.
  • Run your tests in arbitrarily big thread pools with various policies available (all methods in their own thread, one thread per test class, etc…).
  • Test that your code is multithread safe.
  • Flexible test configuration.
  • Support for data-driven testing (with @DataProvider).
  • Support for parameters.
  • Powerful execution model (no more TestSuite).
  • Supported by a variety of tools and plug-ins (Eclipse, IDEA, Maven, etc…).
  • Embeds BeanShell for further flexibility.
  • Default JDK functions for runtime and logging (no dependencies).
  • Dependent methods for application server testing.

For more information visit this link.

Why TestNG ?

TestNG has more functionalities when compared to other testing frameworks. Also it supports well on Selenium. It supports latest platforms and frameworks as well (Java 7 and above). Last but not least due to the rich annotations we could code our scripts very easily.

How to install TestNG on Eclipse

Step 1

  1. Open Eclipse – if you don’t have eclipse you download it from this link.
  2. go to the help menu and click on install new software

Step 2

  1. a pop up window will open, click on add button as below, 
  2. another pop up window will open as below, enter  “TestNG” and type “http://beust.com/eclipse/” as location. Click OKNote : You can find the location url in this link.
  3. You will come back to the previous window, but with testng option.
  4. check the testng and click on next button.

Step 03

  1. Read the agreement and accept.
  2. if you see any security warning press ok. This warning is populated from eclipse due to it’s policy on third party installations. 
  3. After installation, eclipse need to be restarted. Press yes on below window.

Step 04

  1. After restarting the eclipse, verify testng is installed correctly as below.

That’s all friends, Enjoy automation testing.