Selenium integrate with Jmeter step by step integration
Posted by Mufi on 7:37 AM with 2 comments
JMeter is an open source load testing tool, with many capabilities. One of the interesting thing is Jmeter can be used to do Performance testing when the functional test scripts are created in Selenium with JUnit framework.
This post will focus on how the Selenium scripts are integrated into the Jmeter test suite.
Step 1: Download and install Eclipse.
Create a new Java project with a class and run it.
- In the Java Perspective, right-click in Eclipse's Package Explorer window and select New >> Java Project
- Name the project whatever you like (e.g. 'SelJmtInt'). For now the other options do not matter; just click on Finish.
- In the Package Explorer window, right-click on the test package and select New >> Class.
- Name the class 'TestClass'. For now the other options do not matter; just click on Finish.
- Add Junit Library to the project by right click on project >> configure build path >> Add Library
Step 2: Steps to configure selenium with eclipse
Download Selenium Web driver from the below link.
http://docs.seleniumhq.org/download/
Add the Selenium jar by right click on project >> Configure Build Path>> Add External Jar
Latest Version is selenium-server-standalone-2.42.21. In the Eclipse menu bar, select File >> Save. If everything is working properly this program should compile automatically without errors.
2.Run the program by right-clicking on the TestClass class in the package manager, then select Run As >> JUnit Test
Step 3: Once the scripts are ready, export them into jar files. Export the Java ‘ TestClass ' & create JAR file of the project.
(Right click on ‘Test Class’ –> Export –> Java –> JAR File –> Finish )
(Right click on ‘Test Class’ –> Export –> Java –> JAR File –> Finish )
Copy the jar file and paste it in the Junit folder under lib folder of Jmeter. Here is the path where I have placed the jar files in my system: “D:\apache-jmeter-2.9\apache-jmeter-2.9\lib\junit”
step 4:
Copy & paste the ‘Test.jar’ file in the lib folder of JUnit location Ex: ‘D:\apache-jmeter-2.9\lib\junit’ and ‘selenium-server-standalone-2.42.2’ server file in the location lib folder Ex: ‘D:\apache-jmeter-2.9\lib’
step 5:
Open the JMeter tool by executing ‘jmeter.bat’ file. Create a Thread Group & add ‘JUnit Request’ Sampler to Thread Group.
Select the JMeter class & testJMeter method under the Classname & Test Method in the JUnit Request component.
Step 6: Add all the required JUnit components for Result analysis & define the thread properties in ‘Thread Group’ to run for number of instances.
Step 7: Save the Thread Group Test Script files to .jmx format & start the execution in JMeter.
Step 8: Now change the No of users to 10 in Thread Group and Start the Execution
As we increased the users, for each user the browser will open (i.e. for 10 times and for each instance of browser it will use some amount of memory of the Machine based on the test script). So to come up with better performance results we have to use HtmlUnit Driver in selenium code. This will execute the tests in the background and you will not see multiple browser windows opening.
The benefit of integrating Selenium and Jmeter is that the same functional scripts created in Selenium for functional testing can be used for performance testing and moreover Jmeter and Selenium are open source tools and we can save money and time.
where are the pictures???
ReplyDeleteHow integrate it with TestNG?
ReplyDeleteI have this escenario:
I have a flow that i need run API and this API response data necesary to run a with UI (Selenium)
I use TestNG but i read that it's not compatible.
I need help :D