我有机器人框架,它将尝试在无头模式下运行UI测试。但当我们在Docker容器中运行机器人框架时,我们得到了以下错误
WebDriverException:消息:未知错误:Chrome无法启动:异常退出。(未知错误:DevToolsActivePort文件没有exist((进程从chrome位置开始/usr/bin/google chrome不再运行,因此ChromeDriver假设Chrome已经崩溃。(
Dockerfile:
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]*).*/1/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