Chrome failed to start
estivalet opened this issue · comments
When trying to run the image the following error is displayed:
docker run -it --rm -v ${PWD}:/robot moleszek/robotframework:latest -m robot test.robot
I think the image is using root to launch chrome. Is there a way to change this behaviour?
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.)
Stacktrace:
#0 0x563df9ccfa23
#1 0x563df979ae18
#2 0x563df97be1f1
#3 0x563df97b991a
#4 0x563df97f474a
#5 0x563df97ee883
#6 0x563df97c43fa
#7 0x563df97c54c5
#8 0x563df9cff16d
#9 0x563df9d155bb
#10 0x563df9d00e75
#11 0x563df9d15e85
#12 0x563df9cf486f
#13 0x563df9d30ae8
#14 0x563df9d30c68
#15 0x563df9d4baad
#16 0x7f0fc85d8ea7
Hi @estivalet
Thank you for creating this issue.
In this case, the root is not a problem to run chrome.
Inside the Keywords section you need to create a step that will run chrome in headless mode.
Chrome Headless
${chrome_options}= Evaluate sys.modules['selenium.webdriver'].ChromeOptions() sys, selenium.webdriver
Call Method ${chrome_options} add_argument --disable-extensions
Call Method ${chrome_options} add_argument --headless
Call Method ${chrome_options} add_argument --disable-gpu
Call Method ${chrome_options} add_argument --no-sandbox
Create Webdriver Chrome chrome_options=${chrome_options}
Then in Settings add Test Setup and run Chrome Headless.
See this example how it's should look like.
Please, let me know if this solution is good for you 😄
Hi @solairen thanks for the reply. Yes it works. But in this case I am not able to see the browser running the test. I am doing my personal docker image with VNC just for testing purporses and I don't know how I can run chrome with non-root user.
If you want to add a user to your docker image just add it to Dockerfile:
(...)
ARG user={USERNAME}
ARG home=/home/${user}
RUN addgroup docker
RUN adduser --disabled-password --gecos "" --home ${home} --ingroup docker ${user}
RUN chown ${user}:docker /usr/bin/google-chrome
RUN chown $[user}:docker /usr/bin/chromedriver
Then you will need to do this (depends on your os system): dockerGUI
Lastly, you will need to modify this:
*** Keywords ***
Chrome Headless
${chrome_options}= Evaluate sys.modules['selenium.webdriver'].ChromeOptions() sys, selenium.webdriver
Call Method ${chrome_options} add_argument --disable-extensions
Call Method ${chrome_options} add_argument --headless
Call Method ${chrome_options} add_argument --disable-gpu
Call Method ${chrome_options} add_argument --no-sandbox
Create Webdriver Chrome chrome_options=${chrome_options}
to that:
*** Keywords ***
Chrome Headless
${chrome_options}= Evaluate sys.modules['selenium.webdriver'].ChromeOptions() sys, selenium.webdriver
Call Method ${chrome_options} add_argument --disable-extensions
Call Method ${chrome_options} add_argument --no-sandbox
Create Webdriver Chrome chrome_options=${chrome_options}
You will see the browser running as a non-root user inside your docker container.
@solairen Thanks for the help! I'll give a try.