Problem with headless browser testing in JMeter

Hey folks, I’m struggling with headless browser testing in JMeter. I tried using the HtmlUnit Driver Config, but I’m getting this error:

Response message: com.gargoylesoftware.htmlunit.ScriptException: ReferenceError: "getComputedStyle" is not defined.

I’ve read that HtmlUnit might not support JavaScript. Is there a way to fix this in JMeter? Or are there other options for headless browser testing on a Linux server?

I also tried using a WebDriver sampler to open Google, like this:

WDS.sampleResult.sampleStart()
WDS.browser.get('http://google.com')
WDS.sampleResult.sampleEnd()

I downloaded PhantomJS too, but nothing shows up in the report when I run it. Do I need to add more settings?

Any help would be awesome. Thanks!

I’ve encountered similar challenges with headless browser testing in JMeter. One solution that’s worked well for me is using Selenium WebDriver with Chrome in headless mode. It’s more robust than HtmlUnit and supports JavaScript better.

To set it up, you’ll need to install ChromeDriver on your Linux server. Then, in JMeter, use the WebDriver Sampler with Chrome options set for headless mode. Here’s a basic script:

WDS.sampleResult.sampleStart()
var options = new org.openqa.selenium.chrome.ChromeOptions()
options.addArguments(‘–headless’, ‘–no-sandbox’, ‘–disable-dev-shm-usage’)
var driver = new org.openqa.selenium.chrome.ChromeDriver(options)
driver.get(‘http://google.com’)
WDS.sampleResult.sampleEnd()

This approach should resolve your JavaScript issues and provide more reliable results. Remember to add appropriate waits and assertions to ensure your tests are capturing the right data.

hey, i’ve been there too. phantomjs is pretty much dead now. try using chrome headless instead. it’s way more reliable. here’s a quick tip:

use chromedriver config in jmeter
set these chrome options:
chromeoptions.addarguments(‘–headless’, ‘–disable-gpu’)

works like a charm for me. good luck!

I’ve dealt with similar issues in JMeter, and it can be frustrating. For headless browser testing on Linux, I’ve had better luck using ChromeDriver with Chrome in headless mode. Here’s what worked for me:

  1. Install Chrome and ChromeDriver on your Linux server.
  2. In JMeter, use the Chrome Driver Config element instead of HtmlUnit.
  3. Set the Chrome options to run headless:
ChromeOptions options = new ChromeOptions();
options.addArguments('--headless');
WDS.browser = new ChromeDriver(options);

This approach supports JavaScript and gives more reliable results than HtmlUnit or PhantomJS (which is no longer maintained).

For your Google test, try adding assertions or saving the page source to verify it’s working. Sometimes the actions happen too fast to see in the report. Also, make sure you have the View Results Tree listener added to see detailed results.

Hope this helps! Let me know if you need more specifics on setting it up.