Search code examples
seleniumjmeterheadlessselenium-firefoxdriver

Apache Jmeter - Selenium test with Firefox headless mode


I would like to run my test script in Apache Jmeter with Firefox Driver Config but I couldn't set up the headless mode and the setAcceptInsecureCerts(true).

I execute the Jmeter with the following command from CLI:

jmeter -Dwebdriver.gecko.driver="c:\DEVTOOLS\PERFORMANCE_TEST\FIREFOX_GECKO_DRIVER\geckodriver.exe"

Unfortunately, the test target site does not use valid or secure certification at the moment, so I need to set up to accept insecure cert somehow.

Here is my code snippet:

var pkg = JavaImporter(org.openqa.selenium, org.openqa.selenium.support.ui,org.openqa.selenium.firefox.FirefoxOptions)

var wait = new pkg.WebDriverWait(WDS.browser, 20)

pkg.FirefoxOptions.setAcceptInsecureCerts(true)

**I got the following error:**
2020-06-02 13:27:59,024 ERROR c.g.j.p.w.s.WebDriverSampler: TypeError: pkg.FirefoxOptions.setAcceptInsecureCerts is not a function in <eval> at line number 4

I don't know how is it possible to add the headless argument and AcceptInsecureCerts(true) to Jmeter code.

Thank you for your help!


Solution

  • Unfortunately this is not something you can control using WebDriver Sampler, the options are in:

    1. Patch FirefoxDriverConfig.java code where FirefoxDriver initialization happens and replace the WebDriver Sampler plugin under "lib/ext" folder of your JMeter installation with your own version
    2. Switch to the JSR223 Sampler where you can instantiate your own FirefoxDriver with whatever capabilities/preferences/command-line arguments you want

    3. If you're not able or not willing to go for the above options you can set acceptInsecureCerts preference using Firefox Driver Config element:

      enter image description here

      and if your system doesn't have GUI you can use i.e. Xvfb to act as a virtual display like it's described in Headless Execution of Selenium Tests in Jenkins article