繁体   English   中英

在VSTS托管代理上以Chrome(无头模式)运行Selenium测试

[英]Running Selenium Tests in Chrome (Headless mode) on a VSTS Hosted Agent

是否可以在无头模式下使用Chrome驱动程序在Visual Studio Team Services构建/发布中的托管代理上运行Selenium C#测试?

我已经看到相互矛盾的信息表明这是当前不可能的。 此用户语音提示似乎表明Chrome已预先安装在托管代理上:

https://visualstudio.uservoice.com/forums/330519-visual-studio-team-services/suggestions/19387174-install-headless-chrome-on-hosted-build-servers

当前设置

作为我的测试设置的一部分(在代码中),我表示我希望Chrome驱动程序在无头模式下运行,并且在VS的本地实例中运行时它们会这样做。

例:

var options = new ChromeOptions();
options.AddArgument("headless");
options.AddArgument("disable-gpu");

var driver = new ChromeDriver(options);

当测试作为VSTS中的发布定义的一部分运行时,将引发以下错误:

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)

我确保chromedriver.exe已被复制到bin目录,并包含在发布过程正在使用的构建工件中。

备择方案

我知道您可以设置一个私有代理来运行这些测试,但我想尽可能避免这样做,并在VSTS中使用托管代理。

我还设法使用VSTS中的PhantomJS驱动程序成功运行测试,但我们希望能够在可能的情况下专门针对Chrome浏览器进行测试。

UPDATE

根据下面接受的答案(Bernard Vander Beken),我设法通过插入额外的发布任务来安装Chrome静默和通过PowerShell脚本无人值守来解决这个问题。 这项任务(显然)需要在测试运行之前执行,以便浏览器可以在Selenium测试中以无头模式使用。

发布定义示例

应该可以,请参阅https://github.com/Microsoft/vsts-agent/issues/1378

托管代理程序作为管理员运行,因此只要chrome具有无人参与安装模式,您就应该能够将chrome作为构建的一部分进行安装。

我遇到了同样的问题。 这个问题主要是因为版本兼容性,我尝试了一些组合并使其工作。 之前我使用过ChromeDriver最新版本,即76.*.*.*但是任何Hosted Agent都不支持此功能(截至编写此答案的日期)我使用的是Win 1803 我后来将我的ChromeDriver版本更改为72.*.*.*Hosted AgentVS2017-Win2016 ,现在工作正常。 它也适用于Windows2019

因此,DevOps需要一些时间来为最新版本提供支持。 根据您的项目环境尝试各种组合。

在最近的Hosted VS Agents中,例如Hosted VS2017 ,已经安装了Web浏览器甚至Selenium驱动程序。 您可以在Azure Piplelines Image Generation Github Repo上关注托管代理的文档。 例如,以下是对VS2017代理程序中存在的Chrome的引用

单击管道顶部的“ Agent Phase标题。 然后在Agent pool选择Hosted VS2017而不是vanilla Hosted池。 Windows 2019 with VS 2019最近也可用)。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM