能否在Visual Studio Team Services构建/发布的托管代理中使用Chrome驱动程序的无头模式来运行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中托管的代理。
我还成功地使用PhantomJS驱动程序在VSTS中运行了测试,但是我们仍然希望尽可能地专门针对Chrome浏览器进行测试。 更新 根据下面接受的答案(由Bernard Vander Beken),我成功通过插入一个额外的发布任务来使用PowerShell脚本静默和无人值守地安装Chrome来解决了这个问题。显然,该任务需要在测试运行之前执行,以便在Selenium测试中以无头模式使用浏览器。