【问题标题】:Docker issue : Chrome failed to start: exited abnormally (unknown error: DevToolsActivePort file doesn't exist) : Chrome Browser and Driver 78Docker 问题:Chrome 无法启动:异常退出(未知错误:DevToolsActivePort 文件不存在):Chrome 浏览器和驱动程序 78
【发布时间】:2019-12-06 20:52:24
【问题描述】:

我最近将 Chrome 浏览器更新到了 78 版本,这导致了一个问题。

我正在 Linux Docker 容器中以 Headless Chrome 模式运行 Selenium 测试,使用最新的 chrome-78.0.3904.108、driver-78.0.3904.105 和 selenium-3.141.0、specflow 包 -3.1.67。

我已经尝试了这个论坛上建议的几乎所有功能,以便在 Docker 中无头运行 Chrome。

 case "Headless_Chrome":


                        string driverPath = "/opt/selenium/";
                        string driverExecutableFileName = "chromedriver";

                        ChromeDriverService service_headless = ChromeDriverService.CreateDefaultService(driverPath, driverExecutableFileName);

                       chrome_options.BinaryLocation = "/opt/google/chrome/chrome";

                        chrome_options.AddArgument("--no-sandbox");
                        chrome_options.AddArgument("--headless");
                        chrome_options.AddArgument("--window-size=1420,1080");
                        chrome_options.AddArgument("--disable-extensions");
                        chrome_options.AddArgument("--proxy-server='direct://'");
                        chrome_options.AddArgument("--proxy-bypass-list=*");
                        chrome_options.AddArgument("--disable-gpu"); //even will come redundant in case of linux 
                        chrome_options.AddArgument("--disable-dev-shm-usage"); // to fix -  error: unknown error: session deleted because of page crash
                        chrome_options.AddArgument("--remote-debugging-port=9222");
                        chrome_options.AddArgument("--remote-debugging-address=0.0.0.0");
                        chrome_options.AddArgument("--disable-infobars");
                        chrome_options.AddArgument("--user-data-dir=/data");
                        chrome_options.AddArgument("--disable-features=VizDisplayCompositor"); //to save from zombie chrome process running
                        //chrome_options.AddArgument("--disable-setuid-sandbox");
                        //chrome_options.AddArgument("--privileged"); // can be a security risk
                        //chrome_options.AddArgument("--lang=en_US");
                        //chrome_options.AddArgument("--start-maximized");
                        //chrome_options.AddAdditionalCapability("useAutomationExtension", false);

                        driver = new ChromeDriver(service_headless, chrome_options, TimeSpan.FromSeconds(120));

                     break;

我的 Docker 文件(许可证密钥已替换为 xxxxx ):

FROM microsoft/dotnet:2.2-sdk

ENV PATH="${PATH}:/root/.dotnet/tools"
RUN dotnet tool install --global SpecFlow.Plus.License

RUN specflow-plus-license register --licenseKey KBD0xxxxxxxxxxxxxxxxxxxxiqQGIUTnUBAU/wn/EAAA== --issuedTo "xxxxxxxxxxxxxx"

ENV LANG en_US.UTF-8  
ENV LANGUAGE en_US:en  
ENV LC_ALL en_US.UTF-8
ENV LC_ALL      en_US.UTF-8
ENV C           en_US.UTF-8
ENV TERM        xterm
ENV TZ          Europe/Copenhagen

USER root

# Install Chrome
RUN apt-get update && apt-get install -y \
    apt-transport-https ca-certificates curl gnupg hicolor-icon-theme \
    libcanberra-gtk* libgl1-mesa-dri libgl1-mesa-glx libpango1.0-0 libpulse0 \
    libv4l-0 fonts-symbola \
    --no-install-recommends \
  && curl -sSL https://dl.google.com/linux/linux_signing_key.pub | apt-key add - \
  && echo "deb [arch=amd64] https://dl.google.com/linux/chrome/deb/ stable main" > /etc/apt/sources.list.d/google.list \
  && apt-get update && apt-get install -y google-chrome-stable --no-install-recommends \
  && apt-get purge --auto-remove -y curl \
  && rm -rf /var/lib/apt/lists/*


#RUN dpkg -s google-chrome-stable
#RUN apt-get update && apt-get search google-chrome-stable  && apt-get show google-chrome-stable

# Download the google-talkplugin And ChromeDrive
ARG CHROME_DRIVER_VERSION="latest"
RUN set -x \
  && apt-get update \
  && apt-get install -y --no-install-recommends ca-certificates curl unzip \
  && rm -rf /var/lib/apt/lists/* \
  && curl -sSL "https://dl.google.com/linux/direct/google-talkplugin_current_amd64.deb" -o /tmp/google-talkplugin-amd64.deb \
  && dpkg -i /tmp/google-talkplugin-amd64.deb \
  && rm -rf /tmp/*.deb \
  && CD_VERSION=$(if [ ${CHROME_DRIVER_VERSION:-latest} = "latest" ]; then echo $(wget -qO- https://chromedriver.storage.googleapis.com/LATEST_RELEASE); else echo $CHROME_DRIVER_VERSION; fi) \
  && echo "Using chromedriver version: "$CD_VERSION \
  && mkdir /opt/selenium \
  && curl -sSL "https://chromedriver.storage.googleapis.com/$CD_VERSION/chromedriver_linux64.zip" -o /tmp/chromedriver.zip \
  && unzip -o /tmp/chromedriver -d /opt/selenium/ \
  && rm -rf /tmp/*.zip \
  && apt-get purge -y --auto-remove curl unzip

# Add chrome user
RUN groupadd -r chrome && useradd -r -g chrome -G audio,video chrome \
  && mkdir -p /home/chrome/Downloads && chown -R chrome:chrome /home/chrome

#ENV DISPLAY=:99

WORKDIR /data/WebShopTestAutomation

# copy code
RUN mkdir -p /data && mkdir /reports 
COPY ./source /data
RUN ls -ls /data

RUN cd /data/WebShopTestAutomation && dotnet build

CMD ["dotnet", "vstest", "--logger:trx;LogFileName=/reports/TestResults/report.trx", "/data/WebShopTestAutomation/bin/Debug/netcoreapp2.2/WebShopTestAutomation.dll"]

【问题讨论】:

    标签: docker google-chrome selenium-chromedriver dockerfile google-chrome-headless


    【解决方案1】:

    关闭这个问题,

    因为根本原因是:项目中使用的 default.srprofile 在 Docker 中不起作用,只是没有被读取。 在 Git 中心 Specflow 提出了一个问题

    详情: https://github.com/techtalk/SpecFlow/issues/1841

    【讨论】:

      猜你喜欢
      • 2020-05-03
      • 2023-02-14
      • 2023-02-07
      • 2021-04-03
      相关资源
      最近更新 更多