I am rather new to CI and I am trying to integrate selenium in gitlab ci for a dotnet blazor project with c#.
The e2e tests with selenium are working on my machine. I have to write them for firefox and chrome.
I used Program.CreateHostBuilder(new string[0]).Build().RunAsync();
to start the app on [SetUp]
in nunit for e2e tests.
I am reading out different connectionString due to different enviroments with
if (String.CompareOrdinal(Environment.MachineName, "runner") == 0)
{
return configuration.GetConnectionString("Pipeline");
}
return configuration.GetConnectionString("Local");
This is what my .gitlab-ci.yml
currently looks like:
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"
When I run the pipeline all the e2e are failing with the following error message:
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)
...
When I scroll down a little bit more I find the following:
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)
When I look at the first error message I found here and here though not connected to CI sadly. It seems it might be an error with installing the correct webdriver or some other configuration not set up properly. I am also wondering why the address should be already in use since I can't see anything which is using it.
For setting up the configuration I mainly found this post useful, looked at this and this as reference.
- with the gitlab docs I can't understand how to use the
wdio.conf.js
and where to put it and how the confidence check would be connected to be used in my test stage. - the documentation from one post above seems quite confusing since there is a lot configured and I cant make any sense what each line is required for.
- the same goes for using cucumber since it is quite ruby connected and I also can't find any clue on how to use it for other browsers
- here I see that a lot of details went in there I don't understand and I am having a hard time how to use it for other drivers, though it seems to be the most straigt forward in my opinion.
I feel a little stuck since I see only half baken answers on really specific cases and I am not sure what would be best practice for blazor and c#, since most answers are referring to other programing languages.
Please let me know if you need any further details. Thanks in advance! Any hints or solutions are appreciated.
update 1
- I tried using
npm
though I realized I can't use to images at the same time - defined the localhost to port 4444 on ap startup.
I still get the same errors though, I changed to
- name: selenium/standalone-chrome:latest
- name: selenium/standalone-firefox:latest
in my yml. I would like to know how I can pass different parameters regarding the port.
update 2
I tried to add the following to 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
which I got from this documentation, also moved the image for dotnet to the other stages.