我有一个运行 Selenium 的 Docker 容器:
docker run -d -p 4444:4444 -p 7900:7900 --shm-size="2g" selenium/standalone-chrome
我正在使用 Codeception 运行测试(不在 Docker 容器中)。我没有使用 Laravel。我的 Codeception
Acceptance.suit.yml
文件是:
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
我得到的错误是:
[Facebook\WebDriver\Exception\UnknownErrorException] unknown error: net::ERR_CONNECTION_REFUSED
(Session info: chrome=111.0.5563.146)
我在本地机器和 GitHub 操作上都遇到了这个错误。
在 Docker 容器日志中是这个 500 错误。我认为它是相关的,但我不知道是什么原因造成的:
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"}}
Codeception 文档 说要运行一个稍微不同的 Docker 命令:
docker run --net=host --shm-size 2g selenium/standalone-chrome
因为“通过使用 --net=host 允许 Selenium 访问本地网站。”,但是如果我这样做,那么我会得到一个不同的错误:
[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
Docker 容器的替代方法是运行
npx selenium-standalone start
,它在本地运行良好,但当我尝试将其用作 GitHub 操作的 CI 的一部分时,却导致我遇到更多问题。
我已经阅读了几乎所有的谷歌搜索结果,并尝试了所有可能的参数组合,但我已经束手无策了。非常感谢收到任何帮助。