2

Similar to this (unanswered) question: Facebook\WebDriver\Exception\UnknownErrorException: unknown error: net::ERR_CONNECTION_REFUSED (Session info: headless chrome=96.0.4664.110)


I have a Docker container running Selenium:

docker run  -d -p 4444:4444 -p 7900:7900 --shm-size="2g" selenium/standalone-chrome

I am running tests with Codeception (not in a Docker container). I am not using Laravel. My Codeception Acceptance.suit.yml file is:

actor: AcceptanceTester
modules:
    enabled:
        - WebDriver:
            url: 'http://localhost/'
            browser: chrome     
            window_size: false          
            capabilities:
              chromeOptions:
                args: ["--disable-gpu", "--headless", "--no-sandbox"]
        - Tests\Support\Helper\Acceptance
        - Asserts

The error I get is:

[Facebook\WebDriver\Exception\UnknownErrorException] unknown error: net::ERR_CONNECTION_REFUSED
(Session info: chrome=111.0.5563.146)

I am getting this error on both my local machine, and on GitHub actions.

In the Docker container logs is this 500 error. I think it's related, but I don't know what's causing it:

WARN [SeleniumSpanExporter$1.lambda$export$3] - {"traceId": "2c43f3ee7b62d2ad1d902ce80aac409f","eventTime": 1680403387701636876,"eventName": "HTTP request execution complete","attributes": {"http.flavor": 1,"http.handler_class": "org.openqa.selenium.remote.http.Route$PredicatedRoute","http.host": "127.0.0.1:4444","http.method": "POST","http.request_content_length": "52","http.scheme": "HTTP","http.status_code": 500,"http.target": "\u002fsession\u002f8c921d4ca9ca2abfc00f3b52da301178\u002furl"}}

The Codeception docs say to run a slightly different Docker command:

docker run --net=host --shm-size 2g selenium/standalone-chrome

because "By using --net=host allow Selenium to access local websites.", but if I do that then I get a different error:

[Facebook\WebDriver\Exception\Internal\WebDriverCurlException] Curl error thrown for http POST to /session with params: {"capabilities":{"firstMatch":[{"goog:chromeOptions":{"args":["--disable-gpu","--headless","--no-sandbox"]},"browserName":"chrome"}]},"desiredCapabilities":{"chromeOptions":{"args":["--disable-gpu","--headless","--no-sandbox"]},"browserName":"chrome"}}

Failed to connect to 127.0.0.1 port 4444 after 2028 ms: Connection refused

An alternative to a Docker container is to run npx selenium-standalone start, which works fine locally, but leads me down a path of yet more problems when I try to use it as part of CI on GitHub actions.

I have read pretty much every Google search result and tried what seems like every possible combination of parameters, and I am out of ideas. What can I try next?

halfer
  • 19,824
  • 17
  • 99
  • 186
user3356802
  • 141
  • 2
  • 8
  • I recommend to use docker-compose to spin up the docker containers. the containers have to know each other over the network to connect to each other. i described my setup here: https://stackoverflow.com/questions/70858717/is-it-possible-to-run-ui-tests-in-codeception-in-the-background/71207918#71207918 – rickroyce Apr 11 '23 at 08:16
  • Some CI environments are already in Docker, so if you are spinning up containers, that is Docker-in-Docker, which can exhibit some strange effects. Moreover, some CI systems (specifically CircleCI) do not guarantee that multiple containers will be on the same host, which can have knock-on networking effects. – halfer Apr 15 '23 at 10:17
  • I wonder if there is not enough information here. Is the problem that Codeception can't connect to Selenium, or Selenium can't connect to the web app under test? – halfer Apr 15 '23 at 10:19

0 Answers0