Selenium and Jmeter integration

Let us make a simple selenium project in eclipse

We add a class in it and add some junit test cases to it . Once the test is created we run it to make sure its working.

Then we write click our project and click export and choose to save it as a jar file and save it some where in our pc.

Once done we open that folder where this project jar file is saved we copy it ,go to our jmeter folder ,go to library folder and paste it in junit folder. C:\apache-jmeter-5.0\lib\junit

Then we restart jmeter.

Then we make a new Thread and add 5 threads to it. We add a sampler to it .We add junit request sampler.

We check the box to search for junit annotations in this junit request sampler. For class name we will be able to select the name of the class we gave in our project. In the same way we will select the testcase name as well i.e the name of test method we gave in our class. Then we can change other flieds like Success message etc or leave them default.

Then we save the project and run it. We can even add a view result tree listener to our thread and see the results like how much load time it is taking for each of our test case etc. That is how much load time it is taking for each browser to pen and go to that website etc.

But it Is not a good practice to run selenium scripts from jmeter.As if in our script if we were automating the tests using firefox browser

WebDriver driveer = new FirefoxDriver();

and if in our jmeter thread we gave number of threads 20 it will open 20 browsers in our system and will hang our system and results will not be accurate.

So better to use headless driver mode if we want to integrate our selenium project with jmeter.

We can instantiate a headless driver mode in Selenium as below

WebDriver driver = new HtmlUnitDriver();