I run into issue when trying to run unit tests for a website using ChromeDriver. Here is the stack trace from job log:
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 file contents
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}"
Basically, I have no idea what to do with it. I am relatively new to both CI/CD pipelines and Selenium.
CodePudding user response:
You need to run an instance of selenium chrome with your unit-test stage. Downloading chromedriver may be unnecessary.
unit-test:
stage: test
services:
- name: selenium/standalone-chrome:latest
script:
- dotnet test ${projName}
You will need to configure your test suite to connect to the remote web driver at http://selenium__standalone-chrome:4444/wd/hub
, when running in the CI test environment.