title: Running Selenium Tests in Chrome (Headless mode) on a VSTS Hosted Agent
body: <p>Is it possible to run Selenium C# tests on a hosted agent within a Visual Studio Team Services build/release using the Chrome driver in headless mode?</p>
  
  <p>I've seen contradictory information indicating this is and isn't possible currently. This user voice idea seems to suggest Chrome is pre-installed on the hosted agents:</p>
  
  <p><a href="https://visualstudio.uservoice.com/forums/330519-visual-studio-team-services/suggestions/19387174-install-headless-chrome-on-hosted-build-servers" rel="noreferrer">https://visualstudio.uservoice.com/forums/330519-visual-studio-team-services/suggestions/19387174-install-headless-chrome-on-hosted-build-servers</a></p>
  
  <p><strong>Current Setup</strong></p>
  
  <p>As part of the setup of my tests (in code), I'm indicating that I want the Chrome driver to run in headless mode and they do so when run within a local instance of VS.</p>
  
  <p><em>Example:</em></p>
  
  <pre><code>var options = new ChromeOptions();
  options.AddArgument("headless");
  options.AddArgument("disable-gpu");
  
  var driver = new ChromeDriver(options);
  </code></pre>
  
  <p>When the tests are run as part of the release definition within VSTS, the following error is thrown:</p>
  
  <pre><code>2018-02-20T13:21:10.7954002Z Error Message:
  2018-02-20T13:21:10.7954156Z  unknown error: cannot find Chrome binary
  2018-02-20T13:21:10.7954340Z   (Driver info: chromedriver=2.35.528161 (5b82f2d2aae0ca24b877009200ced9065a772e73),platform=Windows NT 10.0.14393 x86_64)
  2018-02-20T13:21:10.7954487Z Stack Trace:
  2018-02-20T13:21:10.7954620Z System.InvalidOperationException: unknown error: cannot find Chrome binary
  2018-02-20T13:21:10.7955947Z   (Driver info: chromedriver=2.35.528161 (5b82f2d2aae0ca24b877009200ced9065a772e73),platform=Windows NT 10.0.14393 x86_64)
  2018-02-20T13:21:10.7956136Z    at OpenQA.Selenium.Remote.RemoteWebDriver.UnpackAndThrowOnError(Response errorResponse)
  2018-02-20T13:21:10.7956387Z    at OpenQA.Selenium.Remote.RemoteWebDriver.Execute(String driverCommandToExecute, Dictionary`2 parameters)
  2018-02-20T13:21:10.7956557Z    at OpenQA.Selenium.Remote.RemoteWebDriver.StartSession(ICapabilities desiredCapabilities)
  2018-02-20T13:21:10.7956729Z    at OpenQA.Selenium.Remote.RemoteWebDriver..ctor(ICommandExecutor commandExecutor, ICapabilities desiredCapabilities)
  2018-02-20T13:21:10.7956927Z    at OpenQA.Selenium.Chrome.ChromeDriver..ctor(ChromeDriverService service, ChromeOptions options, TimeSpan commandTimeout)
  2018-02-20T13:21:10.7957106Z    at OpenQA.Selenium.Chrome.ChromeDriver..ctor(String chromeDriverDirectory, ChromeOptions options)
  </code></pre>
  
  <p>I've ensured the <strong>chromedriver.exe</strong> has been copied over to the <strong>bin</strong> directory and is included in the build artifacts that are being used by the release process.</p>
  
  <p><strong>Alternatives</strong></p>
  
  <p>I know you can setup a private agent to run these tests on, but I wanted to avoid doing this if possible and make use of the hosted agents within VSTS.</p>
  
  <p>I've also managed to successfully run the tests using the PhantomJS driver within VSTS, but again we want to be able to test exclusively against the Chrome browser if possible.</p>
  
  <p><strong>UPDATE</strong></p>
  
  <p>As per the accepted answer below (by Bernard Vander Beken), I managed to resolve this by inserting an additional release task to install Chrome silenty and unattended via a PowerShell script. This task (obviously) needs to be excuted prior to the test run so that the browser can then be used in headless mode within the Selenium tests.</p>
  
  <p><a href="https://i.stack.imgur.com/ttA3Z.png" rel="noreferrer"><img src="https://i.stack.imgur.com/ttA3Z.png" alt="Release Definition Example"></a></p>