c# - 在 Gitlab CI 中将 Blazor 的 E2E 测试与 Selenium 集成时修复“无法在 http://localhost 上启动驱动程序服务:...已在使用中”
问题描述
我对 CI 比较陌生,我正在尝试将 selenium 集成到 gitlab ci 中,以使用 c# 进行 dotnet blazor 项目。使用 selenium 进行的 e2e 测试正在我的机器上运行。我必须为 Firefox 和 chrome 编写它们。我曾经在 nunit 中Program.CreateHostBuilder(new string[0]).Build().RunAsync();
启动应用程序进行 e2e 测试。[SetUp]
由于不同的环境,我正在读取不同的连接字符串
if (String.CompareOrdinal(Environment.MachineName, "runner") == 0)
{
return configuration.GetConnectionString("Pipeline");
}
return configuration.GetConnectionString("Local");
这是我.gitlab-ci.yml
目前的样子:
image: mcr.microsoft.com/dotnet/sdk:5.0
stages:
- build
- test
before_script:
- "cd Project/Team01"
- "dotnet restore"
build:
tags:
- pro
stage: build
script:
- "dotnet build"
test:
tags:
- pro
stage: test
services:
- name: mcmoe/mssqldocker:v2017.CU24.0
alias: mssql
- selenium/standalone-chrome
- selenium/standalone-firefox
variables:
ACCEPT_EULA: Y
SA_PASSWORD: SomeStrongPW
MSSQL_DB: db
MSSQL_USER: Dev
MSSQL_PASSWORD: DatabasPW
script:
- "dotnet test"
当我运行管道时,所有 e2e 都失败并显示以下错误消息:
OpenQA.Selenium.WebDriverException : Cannot start the driver service on http://localhost:43471/
TearDown : System.NullReferenceException : Object reference not set to an instance of an object.
Stack Trace:
at OpenQA.Selenium.DriverService.Start()
at OpenQA.Selenium.Remote.DriverServiceCommandExecutor.Execute(Command commandToExecute)
at OpenQA.Selenium.Remote.RemoteWebDriver.Execute(String driverCommandToExecute, Dictionary`2 parameters)
...
当我向下滚动一点时,我发现以下内容:
Unable to start Kestrel.
System.IO.IOException: Failed to bind to address http://127.0.0.1:5000: address already in use.
---> Microsoft.AspNetCore.Connections.AddressInUseException: Address already in use
---> System.Net.Sockets.SocketException (98): Address already in use
at System.Net.Sockets.Socket.UpdateStatusAfterSocketErrorAndThrowException(SocketError error, String callerName)
当我查看我在这里和这里找到的第一条错误消息时,虽然遗憾的是没有连接到 CI。安装正确的 webdriver 或其他一些未正确设置的配置似乎可能是错误的。我也想知道为什么地址应该已经在使用,因为我看不到任何正在使用它的东西。
对于设置配置,我主要发现这篇文章很有用,将这个和这个作为参考。
- 使用 gitlab 文档,我无法理解如何使用
wdio.conf.js
和放置它以及如何连接置信度检查以在我的测试阶段使用。 - 上面一篇文章中的文档似乎很混乱,因为配置了很多,我无法理解每行需要什么。
- 使用cucumber也是如此,因为它与红宝石连接非常紧密,我也找不到任何关于如何将它用于其他浏览器的线索
- 在这里,我看到有很多我不明白的细节,我很难将它用于其他驱动程序,尽管在我看来它似乎是最直接的。
我觉得有点卡住了,因为我在非常具体的情况下只看到了一半的答案,而且我不确定 blazor 和 c# 的最佳实践是什么,因为大多数答案都是指其他编程语言。
如果您需要更多详细信息,请告诉我。提前致谢!任何提示或解决方案表示赞赏。
更新 1
- 我尝试使用
npm
虽然我意识到我不能同时使用图像 - 在 ap 启动时将 localhost 定义为端口 4444。
我仍然遇到同样的错误,我改为
- name: selenium/standalone-chrome:latest
- name: selenium/standalone-firefox:latest
在我的 yml 中。我想知道如何传递有关端口的不同参数。
更新 2
我尝试将以下内容添加到gitlab-ci.yml
:
install:
image: docker:stable
script:
- docker run -d -p 4444:4444 -v /dev/shm:/dev/shm selenium/standalone-firefox:4.0.0-beta-4-prerelease-20210527
- docker run -d -p 4444:4444 -v /dev/shm:/dev/shm selenium/standalone-chrome:4.0.0-beta-4-prerelease-20210527
artifacts:
paths:
- test
我从这个文档中得到的,也将 dotnet 的图像移到了其他阶段。
解决方案
推荐阅读
- c++ - 在多继承类中使用非类型模板参数消除重载成员函数的歧义
- c# - 通过实体框架中的重复操作减少复杂的 .Where
- configuration - log4j2 + 复合配置 + web.xml
- r - 如何在 R 中修改数据框中的现有值
- android - Google Play 商店内部测试链接不起作用
- r - 如何将分类变量从数据集转换为数值?
- matlab - for loop-Matlab 中的错误
- apache-spark - Spark SQL 限制与 Hive SQL 限制之间的区别
- google-cloud-run - 在 Cloud Code 中调试时访问 computeMetadata
- .net - 为什么在 .NET4.6 中很少有分析器规则将其有效严重性设置为抑制