Docker问题:Chrome无法启动:异常退出(未知错误:DevToolsActivePort文件不存在):Chrome浏览器和驱动程序78

时间:2019-12-06 20:52:24

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

我最近将Chrome浏览器更新为78版本,这引起了问题。

我正在Headless Chrome模式下在Linux Docker容器内运行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"]

1 个答案:

答案 0 :(得分:0)

解决此问题,

根本原因是:在项目中使用的default.srprofile在Docker中不起作用,因此无法读取。 在Git中心Specflow上提出了一个问题

有关详细信息: https://github.com/techtalk/SpecFlow/issues/1841