Chrome headless executes test over 40 seconds - selenium-chromedriver

I have issue with running tests in headless mode with chrome options.
ChromeOptions options = new ChromeOptions(); options.addArguments("--headless"); driver = new ChromeDriver(options);
In UI mode test is executed fast(4seconds), but when I enable headless mode (40 seconds)
Headless mode:
UI mode:
Is there any other way to use chrome headless, whether something is changed in the mean time in driver itself? I have tried with different java, browser version and chrome driver and issue is the same..
Selenium 4.3.0, TestNG 7.4.0

Related

Headless mode in chrome 97 is not working with windows auth

I use windows auth on build agent on teamcity
chromeOptions.AddArgument("--auth-server-whitelist=*");
chromeOptions.AddArgument("--auth-negotiate-delegate-whitelist=*");
And run autotests in headless mode.
chromeOptions.AddArgument("headless");
chromeOptions.AddArgument("window-size=1920x1200");
chromeOptions.AddArgument("--no-sandbox");
Everything has been working fine until Chrome was auto-updated to 97 version. After that my windows auth just stopped working(but it still works for runs without headless mode). I installed old Chrome version on my agents and it works again. But I want to continue both - get updates to Chrome and run my autotests in headless mode.
I tried to add some extra arguments but they didn't work.
options.addArguments("--window-size=1920,1080");
options.addArguments("--disable-gpu");
options.addArguments("--disable-extensions");
options.setExperimentalOption("useAutomationExtension", false);
options.addArguments("--proxy-server='direct://'");
options.addArguments("--proxy-bypass-list=*");
options.addArguments("--start-maximized");
options.addArguments("--headless");
Any idea how to fix this issue?
The Chrome command line arguments changed from whitelist to allowlist:
https://www.ibm.com/support/pages/change-kerberos-windows-authentication-registry-settings-chrome-and-edge-sso
Making that change seems to work for me.

Many chrome icons when running tests with chrome/headless chrome

Recently I switched my cucumber tests from capybara-webkit to chrome. Every time I am running tests locally a new chrome icon appears in the Deck bar. But 5th icon disappears when I start a new test (eg I see maximum four chrome icons)
I use
ChromeDriver 2.43.600229 (3fae4d0cda5334b4f533bede5a4787f7b832d052)
chrome Version 70.0.3538.110 (Official Build) (64-bit)
Gem versions:
selenium-webdriver (3.141.0)
capybara (3.11.1)
My capybara driver set up:
# features/support/env.rb
require 'selenium-webdriver'
Capybara.register_driver :chrome do |app|
options = Selenium::WebDriver::Chrome::Options.new(args: %w[no-sandbox])
options.headless! if tddium?
Capybara::Selenium::Driver.new(app, browser: :chrome, options: options)
end
Capybara.javascript_driver = :chrome
When I am running tests in the headless mode I see that new chrome icons appear, but I don't see browser window
How can I fix that?

Chrome headless not completing, ever (Windows)

I'm struggling to get Chrome headless to do absolutely anything.
I've tried the simple 'getting started' here: https://developers.google.com/web/updates/2017/04/headless-chrome
This example: chrome --headless --disable-gpu --screenshot https://www.chromestatus.com/
does nothing for me. No screenshot generated in the folder. (Was running CMD as Admin).
I've created a webapp (running in IIS on my PC) and set a breakpoint on its Index page. When I call the app using Chrome headless the breakpoint is triggered, but my 2nd (Console) app which created the Chrome headless instance never proceeds beyond the 'Navigate()' line.
The code from the console app:
IWebDriver webClient;
ChromeOptions option = new ChromeOptions();
option.AddArguments("--headless", "--disable-gpu", "--window-size=1920,1200", "--ignore-certificate-errors", "--no-sandbox");
webClient = new ChromeDriver(option);
webClient.Navigate().GoToUrl("http://localhost:49709/");
((ITakesScreenshot)webClient).GetScreenshot().SaveAsFile("ChromeScreenshot.png", ScreenshotImageFormat.Png);
Running:
Windows 7 64-bit
Chrome 64-bit 66.0.3359.139
ChromeDriver 2.38
What am I missing?
I've figured out what is causing the issue, but not why or a proper fix for it. Writing this here in case it helps someone in future.
I found by chance that a timeout error would eventually be thrown after 60 seconds:
The HTTP request to the remote WebDriver server for URL http://localhost:51660/session timed out after 60 seconds.
This error was being thrown on the creation of the ChromeDriver object. Note this is an error thrown by Selenium trying to communicate with the Chrome WebDriver, NOT the Navigate() command failing.
I discovered by complete chance that by removing the "--headless" parameter from the options makes everything works fine. I also found that another parameter "--remote-debugging-port=9222" causes it to fail completely, too.
I'm currently assuming these issues are specific to my environment rather than a bug in the ChromeDriver. But, still looking.

Is it possible to use Google Chrome instead of chromedriver with selenium?

Is there a way to use standard chrome instance instead of chromedrive.exe with selenium?
The chrome driver that is designed for selenium does not save cookies or browser state when being initialized.
For example, the installed instance of chrome is able to bypass 2-factor auth because it can remember that it is a known device in the remote system. On the other hand, the selenium chrome driver is unable to bypass 2-factor auth because it cannot remember its a known device.
I want to use the installed Google Chrome instead of the chromedriver.exe with selenium web driver. Can this be done?
You have to add, in the ChromeOptions the interested profile path.
Open your Chrome Browser and go to the chrome://version/ page.
And get the profile path.
For example, for me:
So, in Java:
String chromeDriver = "/pathTo/chromedriver";
System.setProperty("webdriver.chrome.driver", chromeDriver);
ChromeOptions options = new ChromeOptions();
String dir= "/Volumes/Macintosh HD/Users/DurdenP/Library/Application Support/Google/Chrome/";
options.addArguments("user-data-dir="+dir);
ChromeDriver driver = new ChromeDriver(options);

How to run automated Selenium test with Headless Chrome browser?

All automated test which currently runs on Selenium webdriver, is there any way to run all of them with new Headless chrome?
Yes, that's possible with Chrome V60+. Add these 2 chromeOptions and you're all set:
chromeOptions.addArguments("--headless");
chromeOptions.addArguments("--disable-gpu");
Yes you can run all of them with new Headless chrome. You need to use chrome version 59 and add two chromeOptions to use headless chrome in selenium
Here is the code
https://www.automation99.com/2017/07/how-to-use-chrome-headless-using.html