unknown error: DevToolsActivePort file doesn't exist launching ChromeDriver using robot framework with headless in Docker
unknown error: DevToolsActivePort file doesn't exist launching ChromeDriver using robot framework with headless in Docker
我有机器人框架,它将尝试 运行 UI 无头模式测试。但是当我们 运行 机器人框架在 Docker 容器中时,我们得到以下错误
WebDriverException: Message: unknown error: Chrome failed to start:
exited abnormally. (unknown error: DevToolsActivePort file doesn't
exist) (The process started from chrome location
/usr/bin/google-chrome is no longer running, so ChromeDriver is
assuming that Chrome has crashed.)
Docker文件:
FROM python:3.8
ENV JAVA_OPTS "-Dlog4j.formatMsgNoLookups=true"
ENV LOG4J_FORMAT_MSG_NO_LOOKUPS=true
ENV WAIT_VERSION 2.7.2
#Install Google Chrome
RUN echo 'deb http://dl.google.com/linux/chrome/deb/ stable main' > /etc/apt/sources.list.d/chrome.list
RUN wget -q -O - https://dl-ssl.google.com/linux/linux_signing_key.pub | apt-key add -
RUN set -x && apt-get update && apt-get install -y xvfb google-chrome-stable
#Install Chrome Driver
RUN BROWSER_MAJOR=$(google-chrome --version | sed 's/Google Chrome \([0-9]*\).*//g') && \
wget https://chromedriver.storage.googleapis.com/LATEST_RELEASE_${BROWSER_MAJOR} -O chrome_version && \
wget https://chromedriver.storage.googleapis.com/`cat chrome_version`/chromedriver_linux64.zip && \
unzip chromedriver_linux64.zip && \
mv chromedriver /usr/local/bin/
ADD https://github.com/ufoscout/docker-compose-wait/releases/download/$WAIT_VERSION/wait /wait
RUN chmod +x /wait
CMD ["/bin/bash"]
RobotFramework 资源详情
##### Headless Browser ##########
###### For Headless #######
${chrome options} = Evaluate selenium.webdriver.ChromeOptions()
... modules=selenium, selenium.webdriver
Call Method ${chromeOptions} add_experimental_option prefs ${prefs}
Call Method ${chrome_options} add_argument headless
Call Method ${chrome_options} add_argument disable-gpu
Call Method ${chrome_options} add_argument --ignore-certificate-errors
${var}= Call Method ${chrome_options} to_capabilities
Create Webdriver driver_name=Chrome alias=google chrome_options=${chrome_options}
Go To ${environment.url}
Maximize Browser Window
如何解决这个问题?
克服错误:
WebDriverException: Message: unknown error: Chrome failed to start: exited abnormally.
(unknown error: DevToolsActivePort file doesn't exist) (The process started from chrome location /usr/bin/google-chrome is no longer running, so ChromeDriver is assuming that Chrome has crashed.)
您可以添加参数--no-sandbox
,如下所示:
##### Headless Browser ##########
###### For Headless #######
${chrome options} = Evaluate selenium.webdriver.ChromeOptions()
... modules=selenium, selenium.webdriver
Call Method ${chromeOptions} add_experimental_option prefs ${prefs}
Call Method ${chrome_options} add_argument headless
Call Method ${chrome_options} add_argument --no-sandbox # newly added argument
Call Method ${chrome_options} add_argument disable-gpu
Call Method ${chrome_options} add_argument --ignore-certificate-errors
${var}= Call Method ${chrome_options} to_capabilities
Create Webdriver driver_name=Chrome alias=google chrome_options=${chrome_options}
Go To ${environment.url}
Maximize Browser Window
我有机器人框架,它将尝试 运行 UI 无头模式测试。但是当我们 运行 机器人框架在 Docker 容器中时,我们得到以下错误
WebDriverException: Message: unknown error: Chrome failed to start: exited abnormally. (unknown error: DevToolsActivePort file doesn't exist) (The process started from chrome location /usr/bin/google-chrome is no longer running, so ChromeDriver is assuming that Chrome has crashed.)
Docker文件:
FROM python:3.8
ENV JAVA_OPTS "-Dlog4j.formatMsgNoLookups=true"
ENV LOG4J_FORMAT_MSG_NO_LOOKUPS=true
ENV WAIT_VERSION 2.7.2
#Install Google Chrome
RUN echo 'deb http://dl.google.com/linux/chrome/deb/ stable main' > /etc/apt/sources.list.d/chrome.list
RUN wget -q -O - https://dl-ssl.google.com/linux/linux_signing_key.pub | apt-key add -
RUN set -x && apt-get update && apt-get install -y xvfb google-chrome-stable
#Install Chrome Driver
RUN BROWSER_MAJOR=$(google-chrome --version | sed 's/Google Chrome \([0-9]*\).*//g') && \
wget https://chromedriver.storage.googleapis.com/LATEST_RELEASE_${BROWSER_MAJOR} -O chrome_version && \
wget https://chromedriver.storage.googleapis.com/`cat chrome_version`/chromedriver_linux64.zip && \
unzip chromedriver_linux64.zip && \
mv chromedriver /usr/local/bin/
ADD https://github.com/ufoscout/docker-compose-wait/releases/download/$WAIT_VERSION/wait /wait
RUN chmod +x /wait
CMD ["/bin/bash"]
RobotFramework 资源详情
##### Headless Browser ##########
###### For Headless #######
${chrome options} = Evaluate selenium.webdriver.ChromeOptions()
... modules=selenium, selenium.webdriver
Call Method ${chromeOptions} add_experimental_option prefs ${prefs}
Call Method ${chrome_options} add_argument headless
Call Method ${chrome_options} add_argument disable-gpu
Call Method ${chrome_options} add_argument --ignore-certificate-errors
${var}= Call Method ${chrome_options} to_capabilities
Create Webdriver driver_name=Chrome alias=google chrome_options=${chrome_options}
Go To ${environment.url}
Maximize Browser Window
如何解决这个问题?
克服错误:
WebDriverException: Message: unknown error: Chrome failed to start: exited abnormally.
(unknown error: DevToolsActivePort file doesn't exist) (The process started from chrome location /usr/bin/google-chrome is no longer running, so ChromeDriver is assuming that Chrome has crashed.)
您可以添加参数--no-sandbox
,如下所示:
##### Headless Browser ##########
###### For Headless #######
${chrome options} = Evaluate selenium.webdriver.ChromeOptions()
... modules=selenium, selenium.webdriver
Call Method ${chromeOptions} add_experimental_option prefs ${prefs}
Call Method ${chrome_options} add_argument headless
Call Method ${chrome_options} add_argument --no-sandbox # newly added argument
Call Method ${chrome_options} add_argument disable-gpu
Call Method ${chrome_options} add_argument --ignore-certificate-errors
${var}= Call Method ${chrome_options} to_capabilities
Create Webdriver driver_name=Chrome alias=google chrome_options=${chrome_options}
Go To ${environment.url}
Maximize Browser Window