{{announcement.body}}
{{announcement.title}}

Combining Selenium with JMeter

DZone 's Guide to

Combining Selenium with JMeter

An article that explores whether Selenium and JMeter should be combined.

· Performance Zone ·
Free Resource

Research Sidekick

Recently I have been doing some research about distributed load and stress testing. If you have ever done it, it is quite apparent that Blazemeter and other similar services are pretty popular to help you with load generators and remote execution; however, I am not going to write about non-functional testing and services.

I am going to write about a couple of articles, videos, and tutorials I have come across during this research. Materials that were presenting how you can combine Selenium WebDriver with JMeter; and how JMeter test plans can start drivers and execute commands, which open a browser and interact with the system under test using the browser.

To begin with, I was not sure if those materials I went through were done to simply prove some concepts or to show good practices to follow. Why would someone combine functional testing with non-functional? That was the question that hit me right away and led me to write this article.

Findings

Articles I read presented that with Selenium tests in JMeter, you can measure how fast HTML pages take to load, you can also check javascript and CSS performances. All that using a combination of graphical JMeter interface and some scripting to invoke Selenium code plus once you have a script it is easy to leverage for example Blazemeter and execute tests from load generators.
At a glance, it sounds reasonable, perfectly fine.

Coupling

The thing is— why would you entangle JMeter with Selenium scripts? Scripts which in such a case don’t follow any design pattern. Scenarios which, based on the videos (video tutorial from 2018) were captured with a recording tool like Katalon Recorder and put into JMeter. Those pieces of code look for objects using driver.findElement(By....) calls. I don’t remember last time I called this function in any WebDriver based framework I participated in building.

How is that?— You may ask.

Well, the page object design pattern with page factory comes in hand here. Very briefly— you identify those elements which you want to interact with on a page, then put them in a class which is your Page Object for a particular view. Next, carefully tailor selectors— id, class name, css (yes skip xpath), and annotate those elements with @FindBy and corresponding string. When you create an instance of the class, call  PageFactory.initElements(driver, this)  and voilà! There is no need to by hand, looking for an element.
The only case where I manually needed to interact with some WebElement is a fluent wait case. But again, I am usually invoke  fluentWait.until(ExpectedContidions.elementToBeClickable(element))  or some similar predefined condition or provide completely custom wait implementing  ExpectedCondition interface with anonymous class.

Local stress test

Another engineer said that having the Selenium test script put into the Thread group allows quickly to spawn many browser instances, as many as threads defined in the Thread group. Then you can check how your page performs under load. Hmm, do you?
Mainly such a test is hitting webserver asking for a web page content, which is plain HTML. Then, once the browser receives the content, it renders it. When you run, let’s say 50 browsers, and each of them is doing this they all stress the machine, host which they run on. You end up slowing down the rendering or at least polluting any numbers you end up getting.

Wouldn’t it be better if one wants to check the webserver, do the stress test with JMeter executing GET request for the URL? Like you were trying to perform DDOS on your product (of course in pre-production environment). Also, additionally, check how well (from the non-functional point of view) your page loads and renders on a machine which serves as a baseline?

Guilty as charged

Myself in the past, I presented the test and I used JMeter for it. Test fired requests with an email in the body then the same email address was checked that specific message arrived; however, that was a case to demo that one can use JMeter even for functional cases. We didn’t use this though. It was just for fun of doing it.

Just because you can doesn’t mean you have to.

What do you think? Does it make sense to combine Selenium with JMeter? Does it make sense to combine functional and non-functional tests?

Topics:
test automation ,jmeter ,selenium ,web driver ,functional testing ,non functional testing ,performance

Opinions expressed by DZone contributors are their own.

{{ parent.title || parent.header.title}}

{{ parent.tldr }}

{{ parent.urlSource.name }}