0

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.

OuttaSpaceTime
  • 710
  • 10
  • 24
  • 1
    Why is port number different (43471 & 5000)? the client and server can't both use the same IP address (or Localhost). On some machines the local host is set to 127.0.0.1) loopback) and others the machine IP address. So copying sample code doesn't always work. The listener/server should use 127.0.0.1 and the client should connect TO machine IP address. – jdweng May 31 '21 at 20:07
  • okay but how can this be achieved within CI? I havent set anything regarding the ip in my `.gitlab-ci.yml`. – OuttaSpaceTime Jun 01 '21 at 05:40
  • Did you solve issue? What errors are you currently getting? Is server and client now using same port number? – jdweng Jun 01 '21 at 09:34
  • sadly not solved still the same errors with both updates. I set server ip back to 5001 since it was causing some other errors. also setting it to 5001 in ci yml didnt help – OuttaSpaceTime Jun 01 '21 at 10:48
  • You may have more than one issue. The client and server must use same port number. Changing to port 5001 may of solved the first issue and now we need to find out how to fix second issue. – jdweng Jun 01 '21 at 11:25
  • ok i might have to use apt instead since docker is not supported by our runners or do you think I can go with `selenium/standalone-chrome:latest` and add to variables? – OuttaSpaceTime Jun 01 '21 at 11:34
  • You are making a HTTP Request and get a HTTP response. You have a client and server and any client class should be able to connect to any server class using HTTP with the right HTTP Headers. HTTP has different modes 1.0,1.1,2.0 so client and server has to use same mode. You may be using HTTP or HTTPS (secure) and HTTPS uses TLS for authentication so the TLS versions and encryption modes have to be compatible between client and server. – jdweng Jun 01 '21 at 11:45
  • @jdweng do you have any idea how to achieve this? – OuttaSpaceTime Jun 01 '21 at 12:23
  • I don't have all the facts. Your error indicates that the por tnumber are different . Until that is fixed and you give me the new error message I can't help. – jdweng Jun 01 '21 at 12:34
  • I have excluded ssl certificate but is still not working – OuttaSpaceTime Jun 01 '21 at 16:04
  • One step at a time. You must fix the port number before anything else. Do not worry about TLS until the port number is fixed. – jdweng Jun 01 '21 at 16:54
  • I havent set aynthing regarding the port number how can I fix it in the yml? – OuttaSpaceTime Jun 01 '21 at 16:57
  • See following:https://github.com/SeleniumHQ/docker-selenium?force_isolation=true Either you have to set both Kestrel (currently at 5000) or selenium (currently at 4444) to same port. – jdweng Jun 01 '21 at 17:56
  • I tried sadly I cant use the `docker run...` command. I tried with variables as well for selenium/standalone. I was not able to figure out how to set this with variables. I tried `p: 5000:5000` – OuttaSpaceTime Jun 01 '21 at 18:03

0 Answers0