gpt4 book ai didi

java - 在 docker 容器内使用 headless chrome 运行 gauge java 规范

转载 作者:行者123 更新时间:2023-12-02 04:31:07 25 4
gpt4 key购买 nike

我正在尝试在 docker 容器内使用 headless Chrome 运行一组仪表规范。

我尝试像这样设置 Dockerfile:

FROM maven:latest

RUN apt-get update && apt-get install -q -y unzip curl

ENV DEBIAN_FRONTEND=noninteractive

# requirements for chrome headless
# https://github.com/Googlechrome/puppeteer/issues/290#issuecomment-322838700
RUN apt-get update && apt-get install -y gnupg &&\
curl -sL https://deb.nodesource.com/setup_11.x | bash - &&\
apt-get update && apt-get install -y nodejs make g++ &&\
apt-get update &&\
apt-get install -y git-all gconf-service libasound2 libatk1.0-0 libc6 libcairo2 libcups2 libdbus-1-3 \
libexpat1 libfontconfig1 libgcc1 libgconf-2-4 libgdk-pixbuf2.0-0 libglib2.0-0 libgtk-3-0 \
libnspr4 libpango-1.0-0 libpangocairo-1.0-0 libstdc++6 libx11-6 libx11-xcb1 libxcb1 libxcomposite1 \
libxcursor1 libxdamage1 libxext6 libxfixes3 libxi6 libxrandr2 libxrender1 libxss1 libxtst6 ca-certificates \
fonts-liberation libappindicator1 libnss3 lsb-release xdg-utils wget &&\
apt autoremove -y &&\
rm -rf /var/lib/apt/lists/*


# Install Google Chrome
RUN curl -sS -o - https://dl-ssl.google.com/linux/linux_signing_key.pub | apt-key add - && \
echo "deb http://dl.google.com/linux/chrome/deb/ stable main" >> /etc/apt/sources.list.d/google-chrome.list && \
apt-get -yqq update && \
apt-get -yqq install google-chrome-stable && \
rm -rf /var/lib/apt/lists/*

# Install gauge
RUN apt-get install unzip
RUN curl -L https://github.com/getgauge/gauge/releases/download/v1.0.5/gauge-1.0.5-linux.x86_64.zip -o /gauge-1.0.5-linux.x86_64.zip
RUN unzip -o gauge-1.0.5-linux.x86_64.zip -d /usr/local/bin

# Install gauge plugins
RUN gauge install java && \
gauge install screenshot

ENTRYPOINT ["mvn"]

注意:这里有少量专有内容我必须删除,但这应该不会产生影响。

另请注意,我工作的 CI 系统负责处理很多事情,例如将卷安装到容器中,从 git 获取存储库,分配端口等。

当 CI 系统使用此容器运行仪表规范时,它们都会失败并出现如下错误:

 INFO: Created user preferences directory.
17:55:37 Starting ChromeDriver 75.0.3770.8 (681f24ea911fe754973dda2fdc6d2a2e159dd300-refs/branch-heads/3770@{#40}) on port 26120
17:55:37 Only local connections are allowed.
17:55:37 Please protect ports used by ChromeDriver and related test frameworks to prevent access by malicious code.
17:55:37 [1560441336.946][SEVERE]: bind() failed: Cannot assign requested address (99)
17:55:37 Failed to take regular screenshot:
17:55:37 No X11 DISPLAY variable was set, but this program performed an operation which requires it.
17:55:37 Failed to take regular screenshot:
17:55:37 No X11 DISPLAY variable was set, but this program performed an operation which requires it.
17:55:37 Error Message: org.openqa.selenium.WebDriverException: unknown error: Chrome failed to start: exited abnormally
17:55:37 (unknown error: DevToolsActivePort file doesn't exist)
17:55:37 (The process started from chrome location /usr/bin/google-chrome is no longer running, so ChromeDriver is assuming that Chrome has crashed.)
17:55:37 Build info: version: '3.4.0', revision: 'unknown', time: 'unknown'
17:55:37 System info: host: 'dae4cd1c9fcd', ip: '10.99.0.2', os.name: 'Linux', os.arch: 'amd64', os.version: '4.15.0-1029-gcp', java.version: '11.0.1'
17:55:37 Driver info: driver.version: GaugeDriver
17:55:37 remote stacktrace: #0 0x562fab6bd299 <unknown>

看来 headless chrome 实例甚至没有启动。但是,我无法弄清楚为什么。

最佳答案

尝试将 --no-sandbox 选项传递给 chromedriver 实例。

示例:

   ChromeOptions options = new ChromeOptions();
options.addArguments(“--no-sandbox”);
new ChromeDriver(options);

请引用this问题以获取更多详细信息。

关于java - 在 docker 容器内使用 headless chrome 运行 gauge java 规范,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/56584567/

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