Follow

Selenium Webdriver Based Testing

How to use Selenium webdriver with JMeter

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

Steps to install Webdriver Plugin

  1. Download the plugins manager from https://jmeter-plugins.org/install/Install/
  2. Place plugins-manager.jar at the lib/ext/ folder.
  3. Open Jmeter, go to 'Options', then 'plugins manager'.
  4. Select 'Selenium/webdriver' support. 

To verify correct installation, open JMeter and test if there is "jp@gc - Firefox Driver Config" under 'Config Elements'.

How to use Webdriver plugin ?

The webdriver isn't meant to create large scale load, but to get real browser timings while using the standard HTTP samplers to create the majority of the load simultaneously.

The webdriver sampler runs a physical browser on the load engine which consumes a significant amount of resources.

1. Add "Thread Group" to your "Test Plan".

Add the default thread group and keep the user count to 1. 

2. Add Webdriver config element.

  • Add "Config Element" -> "HTTP Cookie Manager"
  • Add "Config Element" -> "jp@gc - Firefox Driver Config"
  • Add "Sampler" -> "jp@gc - Web Driver Sampler"
  • Add "Listener" -> "View Results Tree".

3. Open the "Web Driver Sampler" and add this code.

var pkg = JavaImporter(org.openqa.selenium); //WebDriver classes
var support_ui = JavaImporter(org.openqa.selenium.support.ui.WebDriverWait);//WebDriver classes
var wait = new support_ui.WebDriverWait(WDS.browser, 5000);

WDS.sampleResult.sampleStart();//captures sampler’s start time
WDS.sampleResult.getLatency();
WDS.log.info("Sample started");

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

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

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");

var link = WDS.browser.findElement(pkg.By.cssSelector('#r1-0 > div > h2 > a.result__a > b'))//also saves selector as variable but uses CSS.
link.click()//Click the search result's Link

WDS.sampleResult.sampleEnd();

4.Run test  and observe the results.

You should see the new Firefox window which will open the website. Search for “BlazeMeter”. After the test is has started running, open “View Results Tree” to confirm that there are no errors during the test run. If the “Response Code” is ‘200’ and the “Response Message” is ‘OK’ then the test was run successfully. If not, check the WebDriver script for errors. 

Start the Test Run on BlazeMeter

To launch the WebDriver sampler test in the cloud with more concurrent users on BlazeMeter, create a new test and upload your JMX file to run it. In BlazeMeter you can use two available browsers - Firefox or Chrome.

  • Firefox - Doesn't require any additional configuration. if it ran locally in JMeter, it will work in BlazeMeter.
  • Chrome - You will require to add a path to the Chrome Driver in your in the scripts chrome driver configuration. the path is: /usr/sbin/chromedriverFurthermore, in BlazeMeter's test configuration page, please use JMeter version '2.11 BlazeMeter' and run in any cloud location which is not the 'sandbox' location.

Note: Before uploading your JMeter script remove/disable "View Results Tree" as it slows test performance.

BlazeMeter Recommends

When using the WebDriver plugin, in order to perform better load testing, assemble the Selenium tests with JMeter tests. The number of WebDriver samplers should be less than the number of JMeter samplers. If you need to get any values from websites through Ajax you can use WebDriver with the Once Only Controller in order to avoid continual/duplicate browser launches.

Use a Multi Test configuration where one test is a JMeter only test creating 99% of the traffic and the other test is dedicated for running WebDriver with a minimal amount of threads.

 

Want to learn more? Read our blog post, 6 Easy Steps to Testing Your Chrome Extension With Selenium

Have more questions? Submit a request

0 Comments

Article is closed for comments.