gpt4 book ai didi

selenium - 在 docker 容器中运行 firefox 时,Selenium webdriver 的连接被拒绝错误

转载 作者:行者123 更新时间:2023-12-02 18:27:50 32 4
gpt4 key购买 nike

我正在尝试在使用 centos 作为基本镜像的 docker 容器中使用 gecko 驱动程序 0.24.0 在 firefox 68.0.esr 上运行基本 Selenium 测试。 webdriver 拒绝连接。

1. I tried downgrading the firefox and gecko driver(tried with firefox 60 and gecko driver 0.21.0)
2. The test runs fine outside the container in a centos linux machine.
3. I tired exposing all the ports of the docker container
4. I tried but couldn't restrict the gecko driver to run on a dedicated port.

Docker 文件片段:
FROM centos:latest

# Install pre-requisites
RUN yum install -y \
bzip2 \
dbus-x11 \
build-essential \
libgl1-mesa-glx \
gtk3
COPY firefox-68.0esr.tar.bz2 /tmp
RUN tar -xvjf /tmp/firefox-68.0esr.tar.bz2 -C /usr/share \
&& ln -s /usr/share/firefox/firefox /usr/bin/firefox

EXPOSE 1025-65535

docker 运行命令:
docker run --privileged -it --shm-size=2g --rm -u $(id -u):$(id -g) -v "  firefox

错误日志:
    1564119317051   geckodriver     INFO    geckodriver 0.21.0
1564119317056 geckodriver INFO Listening on 127.0.0.1:27326
1564119317288 mozrunner::runner INFO Running command: "/usr/bin/firefox" "-marionette" "-headless" "-foreground" "-no-remote" "-profile" "/tmp/rust_mozprofile.BiPoRQ1CUTKA"
1564119317290 geckodriver::marionette DEBUG Waiting 60s to connect to browser on 127.0.0.1:40722
*** You are running in headless mode.
1564119377337 webdriver::server DEBUG <- 500 Internal Server Error {"value":{"error":"unknown error","message":"connection refused","stacktrace":""}}
2019-07-26 05:36:17,381 [main] DEBUG freemarker.cache - Couldn't find template in cache for "index.ftl"("en", UTF-8, parsed); will try to load it.
2019-07-26 05:36:17,382 [main] DEBUG freemarker.cache - TemplateLoader.findTemplateSource("index_en.ftl"): Not found
2019-07-26 05:36:17,383 [main] DEBUG freemarker.cache - TemplateLoader.findTemplateSource("index.ftl"): Found
2019-07-26 05:36:17,383 [main] DEBUG freemarker.cache - Loading template for "index.ftl"("en", UTF-8, parsed) from "jar:file:/var/maven/.m2/repository/com/aventstack/extentreports/3.1.5/extentreports-3.1.5.jar!/com/aventstack/extentreports/view/html-report/index.ftl"



Caused by: org.openqa.selenium.WebDriverException: connection refused
Build info: version: '3.14.0', revision: 'aacccce0', time: '2018-08-02T20:19:58.91Z'
System info: host: '6919b4dea6cf', ip: '172.17.0.2', os.name: 'Linux', os.arch: 'amd64', os.version: '3.10.0-957.21.3.el7.x86_64', java.version: '1.8.0_212'
Driver info: driver.version: FirefoxDriver

最佳答案

我通过以 root 身份运行容器解决了这个问题,因为事实证明我为运行容器而创建的用户没有所需的权限。

关于selenium - 在 docker 容器中运行 firefox 时,Selenium webdriver 的连接被拒绝错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/57213997/

32 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com