Updated February 21, 2023
Introduction to JMeter with Selenium
JMeter and selenium can be integrated via plugin support of web drivers. Then download the copy in the ext folder and lib folder. The sampler of web drivers comes with configuration element plugins for internet explorer, Mozilla, and chrome. They can be called via selenium code compiled in the sampler. Then choose the driver path in the config element, which takes the browser driver and connects the browser and code. This article explains the integration of JMeter and selenium and the script execution.
JMeter with selenium overview
JMeter and Selenium can be integrated to perform load testing on a website. Selenium is used to execute load testing, and JMeter is used to compute the load testing. The user can measure the response and how fast the HTML pages can pick the load and check the performance of CSS and javascript. It is done by integrating a graphical JMeter interface and important scripting to invoke the selenium code. JMeter is implemented in applications like WebSocket to enhance the browser functionalities by including an enhanced application client. Selenium is used to test mouse functions and also the drag and drop feature.
Why need JMeter with selenium?
The user follows advanced technology like JS, HTML5, and improved CSS in the current situation. The user pushes more to add logic to his code with the technologies. But at times, the advanced features can impact the entire web browser performance and execution time. A few examples are JavaScript execution on the client-side, CSS transformation on a 3D matrix, animations, third-party plugins like site analytics, and various clicks over adds. The given logic matches all the performance on the web application. However, JMeter doesn’t act like a real browser and so cannot measure the real-time user experience on the client end. The advanced logic requires different rendering ties and effects in the browser and its load time accordingly.
JMeter with selenium Project
The initial requirement to establish this project is to configure JMeter in the system. Then install Webdriver or Selenium plugins with the plugin manager of JMeter. Then download the chrome driver binaries in the system. Finally, configure the chrome driver’s property in the JMeter installation folder.
- Navigate to the installation folder of JMeter. Choose a file from bin/system properties.
- Configure the system path for the chrome driver.
- Launch the GUI of JMeter and add the simple thread group.
- Insert the configuration from firefox or chrome
- Insert web driver sampler to the configured thread group
- Add view result in the table from the listener.
- The selenium script in JMeter is configured.
- All the statements should be changed to URL using JSON wire protocol in HTTP in the selenium script. Then, the URL should be passed to the browser driver.
- Then every browser uses an HTTP server to get HTTP requests. Once the browser receives an URL, it passes the request to the original browser via HTTP. Then, the commands from the selenium script are executed to the browser.
- If it is a post request, then there executes the action on the browser.
- If it is a get request, the suitable response is produced at the browser and sent over HTTP.
JMeter with selenium Running
creates a new test plan by choosing a new button from the file option
- The user can use the menu file from templates or select the template icon. The user will execute the new test plan.
- Add the thread group from the test plan by clicking add, then choose users that are threads. Then select thread group.
Add the sampler request from Junit request. Choose Junit request from the thread group, then sampler to add the request.
Add view result tree option from listeners to look at the sampler results. Then, select thread group, choose listeners, and view the result tree option.
- Then add a summary report from sampler results to view the full summary.
- Add graph results as a listener to see the full result of the sampler results. First, the graph result is selected from the thread group and added to listeners.
Add the writer listener from data to create a CSV file of sampler results. Next, choose a simple data writer from the thread group. Finally, the simple data writer is added in the listener’s tab.
To execute the selenium web driver scripts, follow the below steps.
- Import the web driver script in Junit request sampler note. The file of the script jar should be imported to the JUnit folder in Apache JMeter.
- Open the sampler of Junit requests and choose the concerned test plan.
- Choose the annotations from Junit 4 instead of Junit 3.
- Choose the class name from the drop-down, and the list displays all the classes present in the drop-down.
- Select the test method in the drop-down of the test method, where all the test methods are present in the chosen class name.
- The user can update the success code, success message, failure code, failure message, error code, and error message.
- The user can append the errors from assertions, runtime exceptions in the JMeter log file, and console logs.
- The properties of the thread group should be customized.
- Increase or configure the number of threads or users.
- The ramp-up period can be enhanced to configure the specific period.
- Set the loop count and move the thread group to state forever.
- Add the scheduler configuration to fix duration and configure the thread startup delay.
- Create a CSV file with all the sampler results by executing the write result to the file or can read from the file.
- To execute the Junit request, choose the test method and set thread properties.
- To execute the script, choose the run button. Then, the script is executed according to configuration and thread properties.
- Once the test script is executed, the jtl file or CSV gets automatically exported to the given folder.
- To produce the HTML format or graph, execute the test in non-GUI mode, and the report should be saved in jtl or CSV format.
Conclusion
Hence the JMeter can be integrated with Selenium to perform effective load testing, and it has a simple and easy configuration that can be implemented in all cases.
Recommended Articles
This is a guide to JMeter with Selenium. Here we discuss the integration of JMeter and selenium and the script execution. You may also look at the following articles to learn more –