Today I experienced a bad limitation in Selenium Grid. The need to run chrome headless in nodes are deprived with the current versio" first make sure chrome headless and firefox headless supports fully across the Selenium solutions, especially in Grid. Although following code is written to send the headless option through desired capabilities, debugging the code showed that it does not support the headless argument. Running headless is most important thing to run scripts via Grid.
Selenium Web Driver versions used 3.12.0
Selenium Standalone - 3.12.0
chromeOptions.AddArgument("--headless");
capabilities = chromeOptions.ToCapabilities() as DesiredCapabilities;
capabilities.SetCapability(CapabilityType.BrowserName, "chrome");
capabilities.SetCapability(CapabilityType.Platform, new Platform(PlatformType.WinNT));
Driver = new RemoteWebDriver(new Uri("<ip of hub>"), capabilities);
Hi @lkkushan101,
The information provided does not help at all. When creating an issue there is a template that should be filled, which contains valuable information for the maintainers to help troubleshoot the issue.
Without that information is virtually impossible to reproduce the issue you are reporting, or at least to point where the error could be.
Please provide the full logs and a code snippet to reproduce the error. It is possible to run Chrome and Firefox in headless mode within Selenium Grid, so it could be a configuration issue.
@lkkushan101
I have just now tried reproducing the problem. Here's what I have in Java.
My test class looks like below
import java.net.MalformedURLException;
import java.net.URL;
import org.openqa.selenium.chrome.ChromeOptions;
import org.openqa.selenium.remote.RemoteWebDriver;
import org.testng.annotations.AfterClass;
import org.testng.annotations.BeforeClass;
import org.testng.annotations.Test;
public class HeadlessMode {
private RemoteWebDriver driver;
@BeforeClass
public void setup() throws MalformedURLException {
ChromeOptions options = new ChromeOptions();
options.addArguments("--headless");
driver = new RemoteWebDriver(new URL("http://localhost:4444/wd/hub"), options);
}
@Test
public void test() {
driver.get("http://www.google.com");
System.err.println("Title " + driver.getTitle());
System.err.println("User agent " + driver.executeScript("return navigator.userAgent;"));
}
@AfterClass
public void cleanup() {
if (driver != null) {
driver.quit();
}
}
}
Here's how my Selenium node (Which is running on 3.12) console logs look like
20:21 $ java -jar selenium-server-standalone-3.12.0.jar -role node
20:28:03.746 INFO [GridLauncherV3.launch] - Selenium build info: version: '3.12.0', revision: '7c6e0b3'
20:28:03.772 INFO [GridLauncherV3$3.launch] - Launching a Selenium Grid node on port 37211
2018-06-13 20:28:03.911:INFO::main: Logging initialized @605ms to org.seleniumhq.jetty9.util.log.StdErrLog
20:28:04.109 INFO [SeleniumServer.boot] - Selenium Server is up and running on port 37211
20:28:04.109 INFO [GridLauncherV3$3.launch] - Selenium Grid node is up and ready to register to the hub
20:28:04.120 INFO [SelfRegisteringRemote$1.run] - Starting auto registration thread. Will try to register every 5000 ms.
20:28:04.120 INFO [SelfRegisteringRemote.registerToHub] - Registering the node to the hub: http://localhost:4444/grid/register
20:28:04.619 INFO [SelfRegisteringRemote.registerToHub] - Updating the node configuration from the hub
20:28:04.701 INFO [SelfRegisteringRemote.registerToHub] - The node is registered to the hub and ready to use
20:30:01.962 INFO [ActiveSessionFactory.apply] - Capabilities are: Capabilities {browserName: chrome, goog:chromeOptions: {args: [--headless], extensions: []}}
20:30:01.964 INFO [ActiveSessionFactory.lambda$apply$11] - Matched factory org.openqa.selenium.remote.server.ServicedSession$Factory (provider: org.openqa.selenium.chrome.ChromeDriverService)
Starting ChromeDriver 2.37.544337 (8c0344a12e552148c185f7d5117db1f28d6c9e85) on port 46242
Only local connections are allowed.
20:30:02.590 INFO [ProtocolHandshake.createSession] - Detected dialect: OSS
20:30:03.074 INFO [RemoteSession$Factory.lambda$performHandshake$0] - Started new session 97651ef74b1ae9f10c29e0f96394b908 (org.openqa.selenium.chrome.ChromeDriverService)
20:30:04.840 INFO [ActiveSessions$1.onStop] - Removing session 97651ef74b1ae9f10c29e0f96394b908 (org.openqa.selenium.chrome.ChromeDriverService)
20:32:51.988 INFO [ActiveSessionFactory.apply] - Capabilities are: Capabilities {browserName: chrome, goog:chromeOptions: {args: [--headless], extensions: []}}
20:32:51.988 INFO [ActiveSessionFactory.lambda$apply$11] - Matched factory org.openqa.selenium.remote.server.ServicedSession$Factory (provider: org.openqa.selenium.chrome.ChromeDriverService)
Starting ChromeDriver 2.37.544337 (8c0344a12e552148c185f7d5117db1f28d6c9e85) on port 28169
Only local connections are allowed.
20:32:52.369 INFO [ProtocolHandshake.createSession] - Detected dialect: OSS
20:32:52.414 INFO [RemoteSession$Factory.lambda$performHandshake$0] - Started new session 99be74ecdbf3a87c790caa53abd17f1f (org.openqa.selenium.chrome.ChromeDriverService)
20:32:54.115 INFO [ActiveSessions$1.onStop] - Removing session 99be74ecdbf3a87c790caa53abd17f1f (org.openqa.selenium.chrome.ChromeDriverService)
On running the above sample, I get a user agent as below
User agent Mozilla/5.0 (Macintosh; Intel Mac OS X 10_13_5) AppleWebKit/537.36 (KHTML, like Gecko) HeadlessChrome/66.0.3359.181 Safari/537.36
This confirms that Chrome is indeed running in headless mode (For more details around the user agent please refer to this stackoverflow post.
So as @diemol mentioned this looks like either a configuration issue or perhaps the client bindings issue (The sample that has been shared, doesn't look like its java)
Its not in java. Its .net code. C# and also referring to console info I also get the chrome starts execution. But when I pass the headless argument it runs on non headless mode
@lkkushan101 Can you provide the console output of the hub in your failing case? If the .NET bindings are not serializing the JSON across the wire, that鈥檚 a problem.
Sure @jimevans let me provide you the console output tomorrow as I have no remote access to nodes now. I should access the remote nodes from my office. Thanks for the help... I really need to get this fixed...
:(
@lkkushan101 Ping!
Closing the issue as there is no reproduction scenario nor the logs provided.
Most helpful comment
@lkkushan101
I have just now tried reproducing the problem. Here's what I have in Java.
My test class looks like below
Here's how my Selenium node (Which is running on 3.12) console logs look like
On running the above sample, I get a user agent as below
This confirms that Chrome is indeed running in headless mode (For more details around the user agent please refer to this stackoverflow post.
So as @diemol mentioned this looks like either a configuration issue or perhaps the client bindings issue (The sample that has been shared, doesn't look like its java)