1. Overview

In this tutorial, we'll discuss the steps to run Selenium scripts with JMeter.

2. Selenium Scripts with JMeter

JMeter provides an open-source solution for performance and load testing. It can also be used for functional testing. But with the advancement of technologies like CSS, JS, and HTML5, we push more and more logic and behavior down the client. Thus many more things add to the browser execution time. These things include:

  • Client-side Javascript execution – AJAX, JS templates, etc.
  • CSS transforms – 3D matrix transforms, animations, etc.
  • 3rd party plugins – Facebook likes Double click ads, etc.

In turn, this might affect the overall performance of a website or web application. But JMeter does not have such a matrix to measure these perceived performances. JMeter also cannot measure the user experience at client renderings like load time or page rendition as JMeter is not a real browser.

Web drivers like Selenium can automate the execution and collection of performance metrics discussed above on the client-side (browser in this case). Thus while the JMeter Load Test will put enough load on the system, the JMeter WebDriver plan will get the response times and other behavior from the user experience point of view.

Thus apart from measuring performance, we can also measure other behaviors when we use a WebDriver set with JMeter. So let's discuss this further.

3. Prerequisites

Following prerequisites should be fulfilled before running a Selenium script with JMeter:

Now we can move ahead and create a sample JMeter project to run the Selenium script.

4. JMeter Project

At this point, we have the environment installed to run the Selenium script in JMeter. Now, let's create a JMeter Project to configure and test it out. We'll create a Thread Group that will have a Selenium Web Driver Sampler instance. We'll include a Selenium script in this sampler and then execute it.

A detailed description is given below:

First, we launch our JMeter GUI:

Then we can add a simple “Thread Group” by clicking “Edit-> Add” and select the Thread Group:

Then, we need to add the Chrome driver config. Now, we click on the Chrome driver config in the left pane and specify the “Path to chrome driver”:

Please note that the version of Chrome browser should match with the “Chromedrive.exe” version for the script to run successfully.

Next, we need to add the web driver sampler to the thread group:

We can add the script  given below to the thread group:

WDS.log.info("successfully navigated to http://baeldung.com/");

Finally, let's add a ‘View Results in Table’  and/or “View Results Tree” listener so that we can view the results of the script execution.

The thread group we created above looks as shown in the following image:

5. Running the Selenium Script

Now we have created the thread group with the Selenium script we want to execute. Next, we “Run the Thread Group”.

The instance of Selenium Web Driver is created, and a new Chrome driver window opens up that opens the homepage of Baeldung:

As we can see from the JMeter Results table above, we have successfully executed the Thread Group that contained a simple Selenium script that opened a new Chrome Browser window and then opened the specified webpage. This way we can execute any Selenium script by adding a WebDriver Sample in the Thread Group and then executing it.


6. Conclusion

In this tutorial, we have illustrated running a Selenium script using JMeter. We executed a Selenium script in JMeter by creating a Thread Group containing the Selenium Web Driver instance.

The full code for the implementation is available over on GitHub.

Generic bottom

Get started with Spring 5 and Spring Boot 2, through the Learn Spring course:

Inline Feedbacks
View all comments