【发布时间】:2018-07-30 22:12:41
【问题描述】:
是否可以在无头模式下使用 Chrome 驱动程序在 Visual Studio Team Services 构建/发布中的托管代理上运行 Selenium C# 测试?
我看到了相互矛盾的信息,表明目前这是不可能的。这个用户声音的想法似乎表明 Chrome 已预安装在托管代理上:
当前设置
作为我的测试设置的一部分(在代码中),我表示我希望 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 浏览器进行测试。
更新
根据下面接受的答案(Bernard Vander Beken),我设法通过插入一个额外的发布任务来解决这个问题,以通过 PowerShell 脚本静默和无人值守地安装 Chrome。此任务(显然)需要在测试运行之前执行,以便浏览器可以在 Selenium 测试中以无头模式使用。
【问题讨论】:
标签: c# google-chrome selenium azure-devops azure-pipelines-release-pipeline