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?