简体   繁体   English

在 GitLab CI/CD 管道中使用 Chrome 驱动程序运行 UI 测试

[英]Running UI tests with Chrome Driver in GitLab CI/CD pipeline

I run into issue when trying to run unit tests for a website using ChromeDriver.尝试使用 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 .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}"

Basically, I have no idea what to do with it.基本上,我不知道该怎么做。 I am relatively new to both CI/CD pipelines and Selenium.我对 CI/CD 管道和 Selenium 都比较陌生。

You need to run an instance of selenium chrome with your unit-test stage.您需要在单元测试阶段运行 selenium chrome 实例。 Downloading chromedriver may be unnecessary.可能不需要下载 chromedriver。

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.在 CI 测试环境中运行时,您需要配置您的测试套件以连接到位于http://selenium__standalone-chrome:4444/wd/hub的远程 Web 驱动程序。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM