Integrating Jmeter with Selenium Code
Jmeter can be used to do performance testing of an application that has existing selenium scripts written over Junit.
– The samplers in Jmeter have a category known as “Junit Request”, which can be used to execute tests written in Junit3 or Junit4
– A test script written in Junit 3 extends the “TestCase” class of Junit, here is an example of the test script written using the “TestCase” class.
– A test script written in Junit 4 uses Junit annotations, here is an example of the test script written using Junit annotations
– Once the scripts are in place, export them into jar files. To export to jar files right click on the project folder -> Select Export-> Expand Java folder -> Click on Jar files -> Click Next -> -> Select the resource to export -> Check the option “Export Java source files and resources” -> Select the export destination -> 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”
– Download the selenium server standalone jar “http://code.google.com/p/selenium/downloads/detail?name=selenium-server-standalone-2.24.1.jar&can=2&q=”
– Copy the selenium server standalone jar to the lib folder of Jmeter
– Now open Jmeter, create a “Thread Group” [ Right click on the Test Plan -> Select Add – > Select Thread(Users) -> Select Thread Group
– Create a “Junit Request” [Right click on Thread Group -> Select Add -> Select Sampler -> Select Junit Request
– In the Junit Request sampler, there would be two drop downs named “Classname:” and “Test Method”
In the two drop downs one could see the tests that were created using Junit3 i.e by extending the TestCase class
– In order to see the tests that were created using Junit annotations, just check the checkbox saying “Search for Junit4 annotations” and the drop downs would populate accordingly
– Add a listener [Right click on Thread Group -> Select Add -> Select Listener (One can select the type of listener as desired , say “View Results in Table”/ “View Results in Tree”/”Summary Report”
– Select the test that you want to execute from the “Test Method” drop down and run the test
– It will launch the browser and perform the action as per one’s test.
– The time taken by each sampler could be noted from the results shown in “View Results in Table” and the Standard Deviation, Throughput, Mean, Average, Minimum Maximum time the samples took to execute could be noted from the “Summary”/”Aggregrate” reports
Written By: – Jaya Mohanty, QA Engineer, Mindfire Solutions
Posted on September 25, 2013, in Automation Testing, Performance Testing, Selenium Testing and tagged Apache JMeter, JAR, Java, java source files, Jaya Mohanty, Jmeter Junit request, Junit, junit download, Mindfire Solutions, Performance Testing, Selenium Testing, software, technology, Test case. Bookmark the permalink. 13 Comments.
How do you think, what the difference between running Selenium code via WebDriver Sampler and via JUnit Request?
Hi Bob,
That is a great piece of information you have shared in your blog.
However, in the above example I have used the jar of an existing script, I did not have to write a separate script specially for JMeter. But using your way I cannot reuse the existing script, I have to create a sampler again for each test.
Best Regards
– Jaya
Hello
Thanks for the steps mentioned in this post.
i followed the steps but in the end the browser open and do not execute the test and the test finally stops running on jmeter.
Any inputs you can give on this in resolving this issue.
Thanks in advance.
Hi Rahul,
Since the browser opened for you, it means that JMeter was able to read the code where you instantiated the WebDriver. Could you check your selenium code works as expected, after the browser was instantiated, without using JMeter.
Best Regards
– Jaya
Hello Jaya,
I am not getting the class name and method name in JMeter.Is there any version is required for JMeter.Please reply me..
Hi Santosh,
If you are using JUnit annotations, then you have to check the option ‘Search for Junit 4 annotations’ for the Class name and Method name to be available at their respective drop downs.
Best Regards
– Jaya
I followed steps which you mentioned in above. But browser was not opening at all.
Selenium test Scripts was executed and verified using webdriver.
jaya,
Thanks for the steps mentioned in this post.
i followed the steps but in the end the browser open and do not execute the test and the test finally stops running on jmeter.
Any inputs you can give on this in resolving this issue.
Junit4 annotations in jmeter & executed scripts usig junit4 only.
please reply me asap.
thanks in advance.
Log information:
2014/10/09 13:57:57 ERROR – jmeter.threads.JMeterThread: Test failed! org.openqa.selenium.WebDriverException: Failed to connect to binary FirefoxBinary(C:\Program Files (x86)\Mozilla Firefox\firefox.exe) on port 7055; process output follows:
pp-system-share
1412843230424 addons.xpi INFO Mapping {972ce4c6-7e08-4474-a285-3208198ce6fd} to C:\Program Files (x86)\Mozilla Firefox\browser\extensions\{972ce4c6-7e08-4474-a285-3208198ce6fd}
1412843230425 addons.xpi INFO Mapping fxdriver@googlecode.com to C:\Users\user\AppData\Local\Temp\anonymous4079681820015274809webdriver-profile\extensions\fxdriver@googlecode.com
1412843230425 addons.xpi DEBUG Ignoring file entry whose name is not a valid add-on ID: C:\Users\user\AppData\Local\Temp\anonymous4079681820015274809webdriver-profile\extensions\webdriver-staging
1412843230425 addons.xpi DEBUG checkForChanges
1412843230431 addons.xpi DEBUG Directory state JSON differs: cache [] state [{“name”:”app-global”,”addons”:{“{972ce4c6-7e08-4474-a285-3208198ce6fd}”:{“descriptor”:”C:\\Program Files (x86)\\Mozilla Firefox\\browser\\extensions\\{972ce4c6-7e08-4474-a285-3208198ce6fd}”,”mtime”:1411652829009,”rdfTime”:1411652828994}}},{“name”:”app-profile”,”addons”:{“fxdriver@googlecode.com”:{“descriptor”:”C:\\Users\\user\\AppData\\Local\\Temp\\anonymous4079681820015274809webdriver-profile\\extensions\\fxdriver@googlecode.com”,”mtime”:1412843230258,”rdfTime”:1412843230246}}}]
1412843230435 addons.xpi-utils DEBUG Opening XPI database C:\Users\user\AppData\Local\Temp\anonymous4079681820015274809webdriver-profile\extensions.json
1412843230436 addons.xpi DEBUG New add-on fxdriver@googlecode.com installed in app-profile
*** Blocklist::_loadBlocklistFromFile: blocklist is disabled
1412843230568 addons.xpi-utils DEBUG Make addon app-profile:fxdriver@googlecode.com visible
1412843230570 DeferredSave.extensions.json DEBUG Save changes
1412843230571 DeferredSave.extensions.json DEBUG Save changes
1412843230571 addons.xpi DEBUG New add-on {972ce4c6-7e08-4474-a285-3208198ce6fd} installed in app-global
1412843230574 addons.xpi-utils DEBUG Make addon app-global:{972ce4c6-7e08-4474-a285-3208198ce6fd} visible
1412843230574 DeferredSave.extensions.json DEBUG Save changes
1412843230574 DeferredSave.extensions.json DEBUG Save changes
1412843230584 addons.xpi DEBUG Updating database with changes to installed add-ons
1412843230584 addons.xpi-utils DEBUG Updating add-on states
1412843230585 addons.xpi-utils DEBUG Writing add-ons list
1412843231814 DeferredSave.extensions.json DEBUG Starting timer
1412843231849 addons.manager DEBUG shutdown
1412843231851 DeferredSave.extensions.json DEBUG Starting write
1412843231851 addons.xpi DEBUG shutdown
1412843231851 addons.xpi-utils DEBUG shutdown
1412843231945 DeferredSave.extensions.json DEBUG Write succeeded
1412843231946 addons.xpi-utils DEBUG XPI Database saved, setting schema version preference to 16
1412843231946 addons.xpi DEBUG Notifying XPI shutdown observers
1412843231950 addons.manager DEBUG Async provider shutdown done
1412843232186 addons.manager DEBUG Loaded provider scope for resource://gre/modules/addons/XPIProvider.jsm: [“XPIProvider”]
1412843232188 addons.manager DEBUG Loaded provider scope for resource://gre/modules/LightweightThemeManager.jsm: [“LightweightThemeManager”]
1412843232189 addons.xpi DEBUG startup
1412843232190 addons.xpi DEBUG Skipping unavailable install location app-system-local
1412843232190 addons.xpi DEBUG Skipping unavailable install location app-system-share
1412843232190 addons.xpi INFO Mapping {972ce4c6-7e08-4474-a285-3208198ce6fd} to C:\Program Files (x86)\Mozilla Firefox\browser\extensions\{972ce4c6-7e08-4474-a285-3208198ce6fd}
1412843232191 addons.xpi INFO Mapping fxdriver@googlecode.com to C:\Users\user\AppData\Local\Temp\anonymous4079681820015274809webdriver-profile\extensions\fxdriver@googlecode.com
1412843232191 addons.xpi DEBUG Ignoring file entry whose name is not a valid add-on ID: C:\Users\user\AppData\Local\Temp\anonymous4079681820015274809webdriver-profile\extensions\webdriver-staging
1412843232191 addons.xpi DEBUG checkForChanges
1412843232196 addons.xpi DEBUG No changes found
*** Blocklist::_preloadBlocklistFile: blocklist is disabled
JavaScript error: chrome://browser/content/urlbarBindings.xml, line 677: aUrl is undefined
Build info: version: ‘2.33.0’, revision: ‘4ecaf82108b2a6cc6f006aae81961236eba93358’, time: ‘2013-05-22 12:00:17’
System info: os.name: ‘Windows 7’, os.arch: ‘amd64’, os.version: ‘6.1’, java.version: ‘1.7.0_60’
Driver info: driver.version: FirefoxDriver
at org.openqa.selenium.firefox.internal.NewProfileExtensionConnection.start(NewProfileExtensionConnection.java:118)
at org.openqa.selenium.firefox.FirefoxDriver.startClient(FirefoxDriver.java:244)
at org.openqa.selenium.remote.RemoteWebDriver.(RemoteWebDriver.java:110)
at org.openqa.selenium.firefox.FirefoxDriver.(FirefoxDriver.java:188)
at org.openqa.selenium.firefox.FirefoxDriver.(FirefoxDriver.java:183)
at org.openqa.selenium.firefox.FirefoxDriver.(FirefoxDriver.java:100)
at com.googlecode.jmeter.plugins.webdriver.config.FirefoxDriverConfig.createBrowser(FirefoxDriverConfig.java:41)
at com.googlecode.jmeter.plugins.webdriver.config.FirefoxDriverConfig.threadStarted(FirefoxDriverConfig.java:22)
at org.apache.jmeter.threads.JMeterThread$ThreadListenerTraverser.addNode(JMeterThread.java:597)
at org.apache.jorphan.collections.HashTree.traverseInto(HashTree.java:961)
at org.apache.jorphan.collections.HashTree.traverse(HashTree.java:946)
at org.apache.jmeter.threads.JMeterThread.threadStarted(JMeterThread.java:566)
at org.apache.jmeter.threads.JMeterThread.initRun(JMeterThread.java:554)
at org.apache.jmeter.threads.JMeterThread.run(JMeterThread.java:253)
at java.lang.Thread.run(Unknown Source)
Caused by: org.openqa.selenium.firefox.NotConnectedException: Unable to connect to host 127.0.0.1 on port 7055 after 45000 ms. Firefox console output:
pp-system-share
1412843230424 addons.xpi INFO Mapping {972ce4c6-7e08-4474-a285-3208198ce6fd} to C:\Program Files (x86)\Mozilla Firefox\browser\extensions\{972ce4c6-7e08-4474-a285-3208198ce6fd}
1412843230425 addons.xpi INFO Mapping fxdriver@googlecode.com to C:\Users\user\AppData\Local\Temp\anonymous4079681820015274809webdriver-profile\extensions\fxdriver@googlecode.com
1412843230425 addons.xpi DEBUG Ignoring file entry whose name is not a valid add-on ID: C:\Users\user\AppData\Local\Temp\anonymous4079681820015274809webdriver-profile\extensions\webdriver-staging
1412843230425 addons.xpi DEBUG checkForChanges
1412843230431 addons.xpi DEBUG Directory state JSON differs: cache [] state [{“name”:”app-global”,”addons”:{“{972ce4c6-7e08-4474-a285-3208198ce6fd}”:{“descriptor”:”C:\\Program Files (x86)\\Mozilla Firefox\\browser\\extensions\\{972ce4c6-7e08-4474-a285-3208198ce6fd}”,”mtime”:1411652829009,”rdfTime”:1411652828994}}},{“name”:”app-profile”,”addons”:{“fxdriver@googlecode.com”:{“descriptor”:”C:\\Users\\user\\AppData\\Local\\Temp\\anonymous4079681820015274809webdriver-profile\\extensions\\fxdriver@googlecode.com”,”mtime”:1412843230258,”rdfTime”:1412843230246}}}]
1412843230435 addons.xpi-utils DEBUG Opening XPI database C:\Users\user\AppData\Local\Temp\anonymous4079681820015274809webdriver-profile\extensions.json
1412843230436 addons.xpi DEBUG New add-on fxdriver@googlecode.com installed in app-profile
*** Blocklist::_loadBlocklistFromFile: blocklist is disabled
1412843230568 addons.xpi-utils DEBUG Make addon app-profile:fxdriver@googlecode.com visible
1412843230570 DeferredSave.extensions.json DEBUG Save changes
1412843230571 DeferredSave.extensions.json DEBUG Save changes
1412843230571 addons.xpi DEBUG New add-on {972ce4c6-7e08-4474-a285-3208198ce6fd} installed in app-global
1412843230574 addons.xpi-utils DEBUG Make addon app-global:{972ce4c6-7e08-4474-a285-3208198ce6fd} visible
1412843230574 DeferredSave.extensions.json DEBUG Save changes
1412843230574 DeferredSave.extensions.json DEBUG Save changes
1412843230584 addons.xpi DEBUG Updating database with changes to installed add-ons
1412843230584 addons.xpi-utils DEBUG Updating add-on states
1412843230585 addons.xpi-utils DEBUG Writing add-ons list
1412843231814 DeferredSave.extensions.json DEBUG Starting timer
1412843231849 addons.manager DEBUG shutdown
1412843231851 DeferredSave.extensions.json DEBUG Starting write
1412843231851 addons.xpi DEBUG shutdown
1412843231851 addons.xpi-utils DEBUG shutdown
1412843231945 DeferredSave.extensions.json DEBUG Write succeeded
1412843231946 addons.xpi-utils DEBUG XPI Database saved, setting schema version preference to 16
1412843231946 addons.xpi DEBUG Notifying XPI shutdown observers
1412843231950 addons.manager DEBUG Async provider shutdown done
1412843232186 addons.manager DEBUG Loaded provider scope for resource://gre/modules/addons/XPIProvider.jsm: [“XPIProvider”]
1412843232188 addons.manager DEBUG Loaded provider scope for resource://gre/modules/LightweightThemeManager.jsm: [“LightweightThemeManager”]
1412843232189 addons.xpi DEBUG startup
1412843232190 addons.xpi DEBUG Skipping unavailable install location app-system-local
1412843232190 addons.xpi DEBUG Skipping unavailable install location app-system-share
1412843232190 addons.xpi INFO Mapping {972ce4c6-7e08-4474-a285-3208198ce6fd} to C:\Program Files (x86)\Mozilla Firefox\browser\extensions\{972ce4c6-7e08-4474-a285-3208198ce6fd}
1412843232191 addons.xpi INFO Mapping fxdriver@googlecode.com to C:\Users\user\AppData\Local\Temp\anonymous4079681820015274809webdriver-profile\extensions\fxdriver@googlecode.com
1412843232191 addons.xpi DEBUG Ignoring file entry whose name is not a valid add-on ID: C:\Users\user\AppData\Local\Temp\anonymous4079681820015274809webdriver-profile\extensions\webdriver-staging
1412843232191 addons.xpi DEBUG checkForChanges
1412843232196 addons.xpi DEBUG No changes found
*** Blocklist::_preloadBlocklistFile: blocklist is disabled
JavaScript error: chrome://browser/content/urlbarBindings.xml, line 677: aUrl is undefined
at org.openqa.selenium.firefox.internal.NewProfileExtensionConnection.start(NewProfileExtensionConnection.java:106)
… 14 more
2014/10/09 13:57:57 INFO – jmeter.threads.JMeterThread: Thread finished: Thread Group 1-1
2014/10/09 13:57:57 INFO – jmeter.engine.StandardJMeterEngine: Notifying test listeners of end of test
2014/10/09 13:57:57 INFO – jmeter.gui.util.JMeterMenuBar: setRunning(false,*local*)
This error cos some version mismatch. I got solution for selenium but how to do with jmeter.
Solution which i got
1. FF version 32 & above supports selenium 2.43.0 or more version..
Just version updated is required,
I am not able to update Jmeter ( latest version itself 2.11). using that only.
hello can i run the Selenium script with TestNG annotations with Jmeter ?..
Can you please tell me how to run with testNG annotations.
I successfully ran Junit testcases with jmeter. but don’t about testNG
Hi Jaya,
This is great information. thank you for posting it.
I have tried to setup the JMeter using a JUnit Test Case. However, I am getting error “2015/02/12 15:27:45 ERROR – jmeter.threads.JMeterThread: Test failed! java.lang.NoSuchFieldError: INSTANCE” in the Jmeter logs and Mozilla browser is not launching.
The Test Case is successfully running in eclipse.
Kindly let me know if I am missing something.
Regards,
Ravi