Chrome headless execution using ChromeOptions

Hi everyone,

A little introduction to my problem. I am trying to test a web application using katalon studio and to access the website I have to use an SSL certificate. In Firefox, I launch a specific profile with the certificate preloaded and for chrome I have the certificate in my keychain. If I select a headless browser (FF or chrome) from the run button in Katalon, the website I am trying to access will not be loaded as I need my certificate. Now I want to be able to perform headless execution of my browser so to do this in Firefox, I use the following code:

> WebUIDriverType executedBrowser = DriverFactory.getExecutedBrowser()
> switch(executedBrowser) {
> 	case WebUIDriverType.FIREFOX_DRIVER:          // "Firefox"
> 		ProfilesIni profile = new ProfilesIni();
> 		FirefoxProfile FF = profile.getProfile("AutomationTesting");      
> 		FirefoxBinary firefoxBinary = new FirefoxBinary();
> 		firefoxBinary.addCommandLineOptions("--headless");
> 		FirefoxOptions firefoxOptions = new FirefoxOptions().setProfile(FF);
> 		firefoxOptions.setBinary(firefoxBinary);
> 		System.setProperty('webdriver.gecko.driver', DriverFactory.getGeckoDriverPath())
> 		WebDriver driver = new FirefoxDriver(firefoxOptions);
> 		DriverFactory.changeWebDriver(driver)
> 		break

This code allows me to open a specific profile of Firefox in headless mode. I was trying to do something similar in Chrome: I wanted to open my website using the certificate I have in my keychain but simply running my tests with Chrome Headless does not work. So, I tried the following code:

> case WebUIDriverType.CHROME_DRIVER:
> 		path = "#the-path-to-my-driver-goes-here#"
> 		//System.setProperty('', DriverFactory.getChromeDriverPath())
> 		System.setProperty('', path)
> 		ChromeOptions opt = new ChromeOptions()
> 		//opt.setHeadless(true)
> 		opt.addArguments("--headless")
> 		WebDriver driver = new ChromeDriver(opt)
> 		DriverFactory.changeWebDriver(driver)
> 		break
> }

Now the code above executes, but not as intended. It will open a Chrome browser but just in regular GUI mode, no headless execution occurs. I have tried both the opt.setHeadless(true) and the opt.addArguments(“–headless”), but both give me the same result.

If anyone knows of a way to get past this issue or have any suggestions please let me know. Thanks for your time!

FYI, I have the following WebDriver imports:

import org.openqa.selenium.WebDriver
import org.openqa.selenium.firefox.FirefoxDriver
import org.openqa.selenium.firefox.FirefoxBinary;
import org.openqa.selenium.firefox.FirefoxOptions
import org.openqa.selenium.firefox.FirefoxProfile
import org.openqa.selenium.firefox.internal.ProfilesIni
import com.kms.katalon.core.webui.driver.DriverFactory
import com.kms.katalon.core.webui.driver.WebUIDriverType