Reputation: 2538
I'm trying to run some chromedriver tests on VSTS using a Java + Maven project. Because I will be using Chrome extensions I am not able to run headless Chrome as it is not supported. I know that Chrome is, by default, not installed on the "Hosted VS2017" VM so I tried to install it via the following powershell script:
$Path = $env:TEMP; $Installer = "chrome_installer.exe";
Invoke-WebRequest "http://dl.google.com/chrome/install/375.126/chrome_installer.exe" -OutFile $Path\$Installer;
Start-Process -FilePath $Path\$Installer -Args "/silent /install" -Verb RunAs -Wait;
Remove-Item $Path\$Installer
However, this results in the following error:
2017-11-06T01:23:18.4054541Z ##[command]. 'd:\a\1\s\install_chrome_win.ps1' 2017-11-06T01:23:23.6299793Z Start-Process : This command cannot be run due to the error: This operation requires an interactive window station. 2017-11-06T01:23:23.6299793Z At D:\a\1\s\install_chrome_win.ps1:1 char:169 2017-11-06T01:23:23.6299793Z + ... $Installer; Start-Process -FilePath $Path\$Installer -Args "/silent / ... 2017-11-06T01:23:23.6299793Z +
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 2017-11-06T01:23:23.6299793Z + CategoryInfo : InvalidOperation: (:) [Start-Process], InvalidOperationException 2017-11-06T01:23:23.6299793Z + FullyQualifiedErrorId : InvalidOperationException,Microsoft.PowerShell.Commands.StartProcessCommand 2017-11-06T01:23:23.6309786Z 2017-11-06T01:23:23.6559779Z[section]Finishing: PowerShell Script
Although I have specified the "silent" and "install" options it appears that there is still some kind of interactive input necessary. I know that there is a .NET tutorial online which allows running of chrome tests but I cannot use it as I have a Java + Maven project.
My questions are: 1. Is it possible to get the "Hosted VS2017" VM to run Java selenium chromedriver "non-headless" tests? 2. What extra configurations do I have to make to get the above powershell script working? Is there a better script I should use instead?
Upvotes: 1
Views: 1774
Reputation: 4164
The hosted build agents have Selenium capabilities pre-installed. Instead of executing the installer, you can use the existing browsers by accessing the environment variables to get the path to the executables.
From Microsoft:
When using the Hosted agent, you should use the Selenium web drivers that are pre-installed on the hosted agents because they are compatible with the browser versions installed on the hosted agent images. The file paths to these drivers can be obtained from the environment variables named
IEWebDriver
(Internet Explorer),ChromeWebDriver
(Google Chrome), andGeckoWebDriver
(Firefox). For example,driver = new ChromeDriver(Environment.GetEnvironmentVariable("ChromeWebDriver"));
Upvotes: 2
Reputation: 33698
You can run Java headless chrome selenium test on an agent with service mode, but the chrome isn’t installed on Hosted agent and you can’t install it on the Hosted agent.
So, I recommend that you can setup a private build agent with Chrome installed and run Java Selenium on that agent.
Simple code of headless selenium test:
System.setProperty("webdriver.chrome.driver", "[chromedriver.exe path]");
ChromeOptions options = new ChromeOptions();
options.addArguments("headless");
//options.setBinary("C:/Program Files/Google/Chrome/Application/chrome.exe");
ChromeDriver driver=new ChromeDriver(options);
driver.get("http://www.google.com");
WebElement searchBox = driver.findElement(By.name("q"));
searchBox.sendKeys("ChromeDriver");
searchBox.submit();
driver.quit();
On the other a uservoice about Install headless chrome on hosted build servers.
Upvotes: 1