嘗試使用 ChromeDriver 為網站運行單元測驗時遇到問題。這是來自作業日志的堆疊跟蹤:
OpenQA.Selenium.WebDriverException : Cannot start the driver service on http://localhost:37329/
TearDown : System.NullReferenceException : Object reference not set to an instance of an object.
StackTrace: at OpenQA.Selenium.DriverService.Start()
at OpenQA.Selenium.Remote.DriverServiceCommandExecutor.Execute(Command commandToExecute)
at OpenQA.Selenium.WebDriver.Execute(String driverCommandToExecute, Dictionary`2 parameters)
at OpenQA.Selenium.WebDriver.StartSession(ICapabilities desiredCapabilities)
at OpenQA.Selenium.WebDriver..ctor(ICommandExecutor executor, ICapabilities capabilities)
at OpenQA.Selenium.Chromium.ChromiumDriver..ctor(ChromiumDriverService service, ChromiumOptions options, TimeSpan commandTimeout)
at OpenQA.Selenium.Chrome.ChromeDriver..ctor(ChromeDriverService service, ChromeOptions options, TimeSpan commandTimeout)
at OpenQA.Selenium.Chrome.ChromeDriver..ctor(String chromeDriverDirectory, ChromeOptions options, TimeSpan commandTimeout)
at OpenQA.Selenium.Chrome.ChromeDriver..ctor(String chromeDriverDirectory, ChromeOptions options)
at OpenQA.Selenium.Chrome.ChromeDriver..ctor(String chromeDriverDirectory)
at ScamTeamWebsiteTests.Tests.Setup() in /builds/kostyabek/ScamTeamWebsiteTests/ScamTeamWebsiteTests/WebSiteTests.cs:line 19
.yml 檔案內容
image: mcr.microsoft.com/dotnet/sdk:6.0
stages:
- build
- test
variables:
projFolder: "ScamTeamWebsiteTests"
projName: "ScamTeamWebsiteTests.csproj"
before_script:
- "apt-get update -qy"
- "apt-get -y install zip unzip"
- "cd ${projFolder}"
- "wget https://chromedriver.storage.googleapis.com/102.0.5005.27/chromedriver_linux64.zip"
- "unzip chromedriver_linux64.zip -d '/home/kostyabek'"
build:
stage: build
script:
- "dotnet build"
unit-test:
stage: test
script:
"dotnet test ${projName}"
基本上,我不知道該怎么做。我對 CI/CD 管道和 Selenium 都比較陌生。
uj5u.com熱心網友回復:
您需要在單元測驗階段運行 selenium chrome 實體。可能不需要下載 chromedriver。
unit-test:
stage: test
services:
- name: selenium/standalone-chrome:latest
script:
- dotnet test ${projName}
http://selenium__standalone-chrome:4444/wd/hub在 CI 測驗環境中運行時,您需要配置測驗套件以連接到遠程 Web 驅動程式。
- https://docs.gitlab.com/ee/ci/services/#accessing-the-services
轉載請註明出處,本文鏈接:https://www.uj5u.com/yidong/478779.html
