3
votes

I'm trying to setup a container to test with RobotFramework on chrome.

But when I run my container I keep getting a WebDriverException. I've searched but couldn't find any fix that actually works for me.

This is my Dockerfile

FROM python:3

RUN apt-get update -y

# Dependencies
RUN apt-get install -y  \
       apt-utils \
       build-essential \
       fonts-liberation \
       gconf-service \
       libappindicator1 \
       libasound2 \
       libcurl3 \
       libffi-dev \
       libgconf-2-4 \
       libindicator7 \
       libnspr4 \
       libnss3 \
       libpango1.0-0 \
       libssl-dev \
       libxss1 \
       python-dev \
       python-pip \
       python-pyasn1 \
       python-pyasn1-modules \
       unzip \
       wget \
       xdg-utils \
       xvfb \
       libappindicator3-1 \
       libatk-bridge2.0-0 \
       libgtk-3-0 \
       lsb-release

# Install Chrome for Selenium
RUN curl https://dl.google.com/linux/direct/google-chrome-stable_current_amd64.deb -o /chrome.deb
RUN dpkg -i /chrome.deb || apt-get install -yf
RUN rm /chrome.deb

# Install chromedriver for Selenium
RUN curl https://chromedriver.storage.googleapis.com/2.42/chromedriver_linux64.zip -o /usr/local/bin/chromedriver
RUN unzip -o /usr/local/bin/chromedriver -d /usr/local/bin
RUN chmod +x /usr/local/bin/chromedriver


WORKDIR /home

COPY . .

RUN pip install -e .

CMD [ "pybot","./tests/test.robot" ]

This is the error I keep getting

WebDriverException screenshot

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.) (Driver info: chromedriver=2.42.591071 (0b695ff80972cc1a65a5cd643186d2ae582cd4ac),platform=Linux 4.15.0-34-generic x86_64)

My test.robot:

*** Settings ***
Library  Selenium2Library

*** Variables ***


*** Test Cases ***
Connect
  Open Browser   https://google.es  Chrome

I think I am missing something but, I just dont know what to do.

On my setup.py:

install_requires=[
        'robotframework',
        'robotframework-selenium2library',
        'selenium'
    ]
3
It's hard to read that image, could you edit your question and paste the output please?U-ways
There you have itpsanlo
What version of selenium and Selenium2Library do you use?JaPyR
I have this on my setup.py, im guessing its installig the latest version. Am I guessing wrong? install_requires=[ 'robotframework', 'robotframework-selenium2library', 'selenium' ]psanlo
Looks like you are installing, but not starting xvfb. Some answers from this question could be helpful stackoverflow.com/questions/22558077/…JaPyR

3 Answers

2
votes

I ran into this issue recently using a docker container and Amazon Linux running robot tests. I found that even though I added the required arguments within the robot framework test as in the example below chrome was crashing without even starting with the same message you received. I resolved the issue by updating the python settings in the options.py within the container.

I updated my docker container with the command below to set the options in the python selenium chrome WebDriver options.py file. In my case I'm using python version 3.7 - so you want to make sure that the path you use is correct.

RUN sed -i "s/self._arguments\ =\ \[\]/self._arguments\ =\ \['--no-sandbox',\ '--disable-dev-shm-usage'\]/" /usr/local/lib/python3.7/site-packages/selenium/webdriver/chrome/options.py

Example Robot - this is what I tried within robot framework that didn't fix the problem.

${chrome_options} =     Evaluate sys.modules['selenium.webdriver'].ChromeOptions()    sys, selenium.webdriver
Call Method    ${chrome_options}   add_argument    headless
Call Method    ${chrome_options}   add_argument    disable-gpu
Call Method    ${chrome_options}   add_argument    no-sandbox
Call Method    ${chrome_options}   add_argument    disable-dev-sim-usage    ${options}=     Call Method     ${chrome_options}    to_capabilities
${options}=  Evaluate  sys.modules['selenium.webdriver'].ChromeOptions()  sys, selenium.webdriver
open browser  about:blank  ${BROWSER}  desired_capabilities=${options}

I'm not sure if this will address your issue. You could try updating your file manually before updating your container to see if it helps. I spent a lot of time troubleshooting this. It would be great if the error was a bit more descriptive. Good luck.

1
votes

Please change modify permission , it's will work

from

RUN chmod +x /usr/local/bin/chromedriver  

to

RUN chmod 777 /usr/local/bin/chromedriver
0
votes

I had the same issue and the below code fixed it

*** Settings ***
Library           Selenium2Library

*** Variables ***
${URL}            https://www.google.com
${CHROMEDRIVER_PATH}        /usr/local/bin/chromedriver

*** Keywords ***
Open Website
    ${chrome_options}=  Evaluate  sys.modules['selenium.webdriver'].ChromeOptions()  sys, selenium.webdriver
    Call Method    ${chrome_options}    add_argument    --no-sandbox
    Call Method    ${chrome_options}    add_argument    --headless
    Open Browser    ${URl}    chrome    options=${chrome_options}      executable_path=${CHROMEDRIVER_PATH}

*** Settings ***
Suite Setup       Open Website