How to execute Selenium script in JMeter

Reading Time: 2 minutes

In this blog, we are going to discuss How to execute Selenium script in JMeter. Basically JMeter was developed to provide open source performance and load testing solution. Initially, JMeter was designed for testing web applications. Later it expands to other test functions. We can also perform functional testing using JMeter.

Why it is needed:-

In the current scenario, we are using much-advanced technology such that HTML5, JS, improved CSS. With these technologies, we are pushing more and more logic to the client itself. These advance improvements impact overall browser experience and execution time. Below are some of the examples:-

1. Client side JavaScript execution,

2. CSS Transormations(Various animations, 3D Matrix transformation),

3. Third party plugins(site analytics, various click based adds).

These mentioned logic ads the overall performance of the website/web app. But when we are talking about the JMeter matrix for these elements then it is not available in JMeter.

JMeter is not the real browser. So, we can’t measure the real-time user experience at the client-side. These advanced elements/logic need various rendering tie and effect in a real browser and give load time accordingly.

Pre Requistes:-

  1. First requirement for this setup is to have JMeter installed in the sysytem.
  2. Then install the “Selenium/webdriver” plugin using the JMeter plugin manager.
  3. gecko driver/chrome driver binaries downloaded in the system.
  4. Set system property for gecko/chrome driver in JMeter Installation folder.

How to set System property for chrome/gecko driver:-

  1. First go to JMeter installation folder.
  2. Then go to “bin/system.propertis” file
  3. Now set the system path for gecko/chrome driver as follows: (webdriver.chrome.driver=/home/knoldus/Downloads/apache-jmeter-4.0/bin/chromedriver), (webdriver.gecko.driver=/home/knoldus/Downloads/apache-jmeter-4.0/bin/geckodriver)

Steps to create sample JMeter project to run selenium script:-

  1. Launch JMeter GUI
  2. Now add simple Thread Group.
  3. Insert Firefox/chrome driver config.
  4. Then add web driver sampler to the thread group.
  5. Finally add ‘view results in table’ listner.

First selenium script in JMeter:-

WDS.sampleResult.sampleStart()
WDS.browser.get('http://google.com')
WDS.sampleResult.sampleEnd()
WDS.log.info("Sample ended - navigated to http://google.com/");

Conclusion:-

Performance testing is not only about plain text response in some given specified time frame. When we are talking about performance testing then real-time page rendering should be one of the prime concerns. Because at the end of the day it the end-user who is going to use that website on a real browser. So, we must know How to execute Selenium script in JMeter to achieve this.

Refrences:-

https://www.blazemeter.com/blog/jmeter-webdriver-sampler, https://stackoverflow.com

Written by 

QA Consultant

Discover more from Knoldus Blogs

Subscribe now to keep reading and get access to the full archive.

Continue reading