簡體   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