I’m working on automated testing for a web application using Selenium with Java and Chrome in headless mode. The application I’m testing requires OTP authentication when logging in from a new device or browser for the first time. After the OTP is verified once, regular browsers remember this and don’t ask for OTP again on subsequent logins from the same machine.
However, when I run my automation script with Chrome headless, it keeps asking for OTP verification every single time, even though I’m running it from the same computer. I expected that after verifying the OTP once, it would remember this like a normal browser does.
Here’s my current setup:
System.setProperty("webdriver.chrome.driver", driverPath);
ChromeOptions options = new ChromeOptions();
options.setHeadless(true);
options.addArguments("--enable-javascript");
options.addArguments("--disable-gpu");
WebDriver browser = new ChromeDriver(options);
browser.manage().window().maximize();
browser.manage().timeouts().implicitlyWait(30, TimeUnit.SECONDS);
browser.get(applicationURL);
I tried entering the OTP manually through console input for the first run, thinking it would save the verification status, but Chrome headless still requests OTP on every execution. This makes automation difficult since I can’t manually enter OTP each time.
Interestingly, PhantomJS handled this correctly - after the first OTP verification, it wouldn’t ask again. But I need to stick with Chrome headless due to project requirements.
What Chrome capabilities or arguments should I add to make it behave like a regular browser and remember the OTP verification status?