Thursday, 13 August 2015 00:00

Use Selenium WebDriver with JMeter

Written by
Rate this item
(0 votes)

The Apache JMeter™ desktop 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.

In this example, you learn how to use Selenium WebDriver with JMeter to test performance of a web application. This example uses Mahara ePortfolio system as an example. We test the application's login and logout performance.

To use Selenium Webdriver with JMeter, simply install "WebDriver Set" plugins. The WebDriver sampler is very useful if you want to test for performance AJAX, GWT based web applications and simulated user actions.

tep 1: download Apache JMeter

To download Apache JMeter, visit the site . click on the file " file" and download it. Unzip the file. 




Step 2: download WebDriver plugins for JMeter. visit download page ""

Step 3: unzip Unzipped files must be copied into the lib folder of Jmeter. To test if WebDriver plugins installed open Jmeter and test if there is jp@gc - Firefox Driver Config.

Step 4: write your WebDriver script as usual, then add "Thread Group" to your "Test Plan".

Add "Config Element" -> "HTTP Cookie Manager", "Config Element" -> "jp@gc - Firefox Driver Config", "Sampler" -> "jp@gc - Web Driver Sampler", "Listener" -> "View Results in Table". Just add two Samplers: one for Login and the other one is for Logout.

Step 5: open the Login (Web Driver Sampler) and add this code. 

var pkg=JavaImporter(org.openqa.selenium) //import java selenium package
var support_ui=JavaImporter( //import WebDriverWait Package
var ui=JavaImporter( //import Selenium Support UI package
var wait=new support_ui.WebDriverWait(WDS.browser,5000) // wait 5 seconds until page loads
WDS.sampleResult.sampleStart() //sample starting point
WDS.browser.get('') // opens website """
var usernameField = WDS.browser.findElement('login_login_username')) //define username field
usernameField.sendKeys(['student1']) // types word “student1” in field
var passwordField = WDS.browser.findElement('login_login_password')) //define username field
passwordField.sendKeys(['Testing1']) // types word “Testing1” in field
var loginButton=WDS.browser.findElement('login_submit')) //define login submit button //click on the login button + ' has logged an entry') //log message

Step 6: open the Logout (Web Driver Sampler) and add this code

var pkg=JavaImporter(org.openqa.selenium) //import java selenium package
var support_ui=JavaImporter( //import WebDriverWait Package
var ui=JavaImporter( //import Selenium Support UI package
WDS.sampleResult.sampleStart() //sample starting point
var wait=new support_ui.WebDriverWait(WDS.browser,60000) // wait 60s econds until page loads
wait.until(ui.ExpectedConditions.presenceOfElementLocated(pkg.By.linkText('Logout'))) //wait until logout link displays
var logoutButton=WDS.browser.findElement(pkg.By.linkText('Logout')) //defind logout link //click on logout link

Step 7: set the Thread Group as shown on the picture below. we are using 5 users and 2 repeat, so the test will run 10 times. 

Step 8: open the "View Results in Table" and you will see the result table below. 

Step 9: in the result window, see the average response time. 

Read 1549 times

1 comment

  • Comment Link Dmitri T Friday, 15 January 2016 04:27 posted by Dmitri T

    Thanks for the great tutorial. I would recommend checking out follow-up article which highlights specific of using WebDriver Sampler - The WebDriver Sampler: Your Top 10 Questions Answered

Leave a comment

Make sure you enter all the required information, indicated by an asterisk (*). HTML code is not allowed.

Tel:  +44 129 327 98 86

Email :

©2017 ItProBit All Rights Reserved.