Using Selenium with JMeter

To use Selenium Webdriver with JMeter, install “Webdriver” plugins. The WebDriver sampler is useful if you want to test for performance AJAX or GWT based web applications.

Download WebDriver plugins from http://jmeter-plugins.org/downloads/all/

Unzip the files and copy in the lib folder under JMeter home directory.

To test if WebDriver plugins installed open Jmeter and test if there is jp@gc – Firefox Driver Config.

*If not, check your JMeter’s lib folder.
 Selenium Webdriver SamplerAdd the Webdriver sampler and Firefox or chrome driver config element. Insert the following code to launch Bing search and search for a text. Also add tree listener to view the result.
var pkg = JavaImporter(org.openqa.selenium)
var support_ui = JavaImporter(org.openqa.selenium.support.ui.WebDriverWait)
var wait = new support_ui.WebDriverWait(WDS.browser, 20000)
WDS.sampleResult.sampleStart()
WDS.browser.get('http://www.bing.com/')
var searchField = WDS.browser.findElement(pkg.By.id('sb_form_q'))
searchField.click()
searchField.sendKeys(['testing'])
var button = WDS.browser.findElement(pkg.By.id('sb_form_go'))
button.click()
WDS.sampleResult.sampleEnd()
selenium_jmeter_2
Explanation of the code
  • The code starts with the import Java packages “org.openqa.selenium” and “org.openqa.selenium.support.ui.WebDriverWait” which will allow you to use the WebDriver classes.
  • WDS.sampleResult.sampleStart() and WDS.sampleResult.sampleEnd() captures sampler’s time and will track it. You can remove them, the script will still work but you will not get load time
  • WDS.browser.get(‘http://www.bing.com/’) – opens the browser with Bing search website
  • var searchField = WDS.browser.findElement(pkg.By.id(‘sb_form_q’)) – saves the search text box in searchField varialble
  • searchField.click() – Clicks the search field to make it active
  • searchField.sendKeys([‘testing’]) – Enters text to search
  • var button = WDS.browser.findElement(pkg.By.id(‘sb_form_go’)) – Saves search button in a variable
  • button.click() – clicks on the search button.

You are now ready to go. Do let us know your experience in using Selenium with JMeter

One Reply to “Using Selenium with JMeter”

Leave a Reply