Having used this page as a reference: http://executeautomation.com/blog/running-chrome-in-headless-mode-with-selenium-c/
I have tried to get Chrome working in headless mode (with a view to running under SpecFlow/xUnit). This has failed spectacularly and I would like to know if anyone has a solution/fix.
I'm running VS 2015 on Windows 7 with a .NET 4.7 console application and Google Chrome Version 65.0.3325.162 (Official Build) (64-bit)...
Here's my packages.config:
<?xml version="1.0" encoding="utf-8"?>
<packages>
<package id="Selenium.Support" version="3.11.0" targetFramework="net461" />
<package id="Selenium.WebDriver" version="3.11.0" targetFramework="net461" />
<package id="Selenium.WebDriver.ChromeDriver" version="2.36.0" targetFramework="net461" />
<package id="xunit" version="2.3.1" targetFramework="net461" />
<package id="xunit.abstractions" version="2.0.1" targetFramework="net461" />
<package id="xunit.analyzers" version="0.8.0" targetFramework="net461" />
<package id="xunit.assert" version="2.3.1" targetFramework="net461" />
<package id="xunit.core" version="2.3.1" targetFramework="net461" />
<package id="xunit.extensibility.core" version="2.3.1" targetFramework="net461" />
<package id="xunit.extensibility.execution" version="2.3.1" targetFramework="net461" />
<package id="xunit.runner.visualstudio" version="2.3.1" targetFramework="net461" developmentDependency="true" />
</packages>
And here's my Class1.cs:
using OpenQA.Selenium.Chrome;
using Xunit;
namespace xUnitSpecFlowChrome
{
public class Class1
{
[Fact]
public void GoTest()
{
var options = new ChromeOptions();
options.AddArgument("--headless");
options.AddArgument("start-maximized");
options.AddArgument("--disable-gpu");
options.AddArgument("--disable-extensions");
var driver = new ChromeDriver(options);
driver.Navigate().GoToUrl("http://www.daringfireball.net");
var title = driver.Title;
}
}
}
And here's what I see, when running that test, in the output:
------ Run test started ------
[xUnit.net 00:00:00.5727852] Starting: xUnitSpecFlowChrome
[xUnit.net 00:00:03.3212989] xUnitSpecFlowChrome.Class1.GoTest [FAIL]
[xUnit.net 00:00:03.3239354] System.InvalidOperationException : session not created exception
from tab crashed
(Session info: headless chrome=65.0.3325.162)
(Driver info: chromedriver=2.36.540470 (e522d04694c7ebea4ba8821272dbef4f9b818c91),platform=Windows NT 6.1.7601 SP1 x86_64) (SessionNotCreated)
[xUnit.net 00:00:03.3264983] Stack Trace:
[xUnit.net 00:00:03.3276332] at OpenQA.Selenium.Remote.RemoteWebDriver.UnpackAndThrowOnError(Response errorResponse)
[xUnit.net 00:00:03.3280606] at OpenQA.Selenium.Remote.RemoteWebDriver.Execute(String driverCommandToExecute, Dictionary`2 parameters)
[xUnit.net 00:00:03.3284914] at OpenQA.Selenium.Remote.RemoteWebDriver.StartSession(ICapabilities desiredCapabilities)
[xUnit.net 00:00:03.3289079] at OpenQA.Selenium.Remote.RemoteWebDriver..ctor(ICommandExecutor commandExecutor, ICapabilities desiredCapabilities)
[xUnit.net 00:00:03.3292786] at OpenQA.Selenium.Chrome.ChromeDriver..ctor(ChromeDriverService service, ChromeOptions options, TimeSpan commandTimeout)
[xUnit.net 00:00:03.3296566] at OpenQA.Selenium.Chrome.ChromeDriver..ctor(ChromeOptions options)
[xUnit.net 00:00:03.3300055] C:\git\xUnitSpecFlowChrome\xUnitSpecFlowChrome\Class1.cs(14,0): at xUnitSpecFlowChrome.Class1.GoTest()
[xUnit.net 00:00:03.3573096] Finished: xUnitSpecFlowChrome
========== Run test finished: 1 run (0:00:04.757) ==========
UPDATE
Having changed nothing of apparent consequence, I am now seeing this in the output pane:
------ Run test started ------
[xUnit.net 00:00:00.3376673] Starting: xUnitSpecFlowChrome
[xUnit.net 00:01:00.8905380] xUnitSpecFlowChrome.Class1.GoTest [FAIL]
[xUnit.net 00:01:00.9024429] OpenQA.Selenium.WebDriverException : The HTTP request to the remote WebDriver server for URL http://localhost:23698/session timed out after 60 seconds.
[xUnit.net 00:01:00.9038433] ---- System.Net.WebException : The operation has timed out
[xUnit.net 00:01:00.9185440] Stack Trace:
[xUnit.net 00:01:00.9199720] at OpenQA.Selenium.Remote.HttpCommandExecutor.MakeHttpRequest(HttpRequestInfo requestInfo)
[xUnit.net 00:01:00.9212636] at OpenQA.Selenium.Remote.HttpCommandExecutor.Execute(Command commandToExecute)
[xUnit.net 00:01:00.9224907] at OpenQA.Selenium.Remote.DriverServiceCommandExecutor.Execute(Command commandToExecute)
[xUnit.net 00:01:00.9237665] at OpenQA.Selenium.Remote.RemoteWebDriver.Execute(String driverCommandToExecute, Dictionary`2 parameters)
[xUnit.net 00:01:00.9250241] at OpenQA.Selenium.Remote.RemoteWebDriver.StartSession(ICapabilities desiredCapabilities)
[xUnit.net 00:01:00.9262697] at OpenQA.Selenium.Remote.RemoteWebDriver..ctor(ICommandExecutor commandExecutor, ICapabilities desiredCapabilities)
[xUnit.net 00:01:00.9275900] at OpenQA.Selenium.Chrome.ChromeDriver..ctor(ChromeDriverService service, ChromeOptions options, TimeSpan commandTimeout)
[xUnit.net 00:01:00.9289251] at OpenQA.Selenium.Chrome.ChromeDriver..ctor(ChromeOptions options)
[xUnit.net 00:01:00.9302787] C:\git\xUnitSpecFlowChrome\xUnitSpecFlowChrome\Class1.cs(16,0): at xUnitSpecFlowChrome.Class1.GoTest()
[xUnit.net 00:01:00.9315103] ----- Inner Stack Trace -----
[xUnit.net 00:01:00.9327543] at System.Net.HttpWebRequest.GetResponse()
[xUnit.net 00:01:00.9339867] at OpenQA.Selenium.Remote.HttpCommandExecutor.MakeHttpRequest(HttpRequestInfo requestInfo)
[xUnit.net 00:01:00.9698773] Finished: xUnitSpecFlowChrome
========== Run test finished: 1 run (0:01:01.085) ==========