smd*_*smd 7 c# selenium google-chrome azure-devops azure-pipelines-release-pipeline
是否可以在无头模式下使用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);
Run Code Online (Sandbox Code Playgroud)
当测试作为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)
Run Code Online (Sandbox Code Playgroud)
我已经确保将chromedriver.exe复制到bin目录中,并包含在发布过程中正在使用的构建工件中。
备择方案
我知道您可以设置一个私有代理来运行这些测试,但是我想避免这样做,而要在VSTS中使用托管代理。
我还设法使用VSTS中的PhantomJS驱动程序成功运行了测试,但是我们再次希望能够在可能的情况下专门针对Chrome浏览器进行测试。
更新
根据下面接受的答案(由Bernard Vander Beken撰写),我设法通过插入一个附加的发布任务来解决此问题,以静默地安装Chrome,并通过PowerShell脚本无人值守。(显然)需要在测试运行之前执行此任务,以便随后可以在Selenium测试中以无头模式使用浏览器。
应该是可以的,请参阅https://github.com/Microsoft/vsts-agent/issues/1378
托管代理以管理员身份运行,因此只要 chrome 具有无人值守安装模式,您就应该能够将 chrome 安装为构建的一部分。
| 归档时间: |
|
| 查看次数: |
3388 次 |
| 最近记录: |