3

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'
    ]
psanlo
  • 31
  • 1
  • 4
  • It's hard to read that image, could you edit your question and paste the output please? – u-ways Sep 17 '18 at 08:56
  • There you have it – psanlo Sep 17 '18 at 09:11
  • What version of selenium and Selenium2Library do you use? – JaPyR Sep 17 '18 at 10:07
  • 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 Sep 17 '18 at 10:16
  • Looks like you are installing, but not starting xvfb. Some answers from this question could be helpful https://stackoverflow.com/questions/22558077/unknown-error-chrome-failed-to-start-exited-abnormally-driver-info-chromedri – JaPyR Sep 17 '18 at 10:57
  • Try this Dockerfile https://github.com/sreenathd/robotwithselenium/blob/master/Dockerfile Here I use latest robot framework, selenium library 4.3, Latest chrome , and python 3.7 Check the readme file for how to use it – Sreenath D Apr 17 '20 at 01:25

4 Answers4

2

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.

C. Lipford
  • 41
  • 1
  • 4
1

Please change modify permission , it's will work

from

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

to

RUN chmod 777 /usr/local/bin/chromedriver
Sidara KEO
  • 1,693
  • 1
  • 14
  • 34
0

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
Dhivya Dandapani
  • 401
  • 1
  • 5
  • 8
0

This is my Dockerfile have test with gitlab CI:

FROM python:3.9.6-buster

ADD ./requirements.txt /tmp/requirements.txt
RUN pip install -r /tmp/requirements.txt
RUN apt-get update && apt-get install -y xvfb wget unzip libnss3-tools
RUN echo "deb [arch=amd64] http://dl.google.com/linux/chrome/deb/ stable main" >> /etc/apt/sources.list.d/google-chrome.list \
    && wget -q -O - https://dl-ssl.google.com/linux/linux_signing_key.pub | apt-key add -
RUN apt-get update && apt-get install -y google-chrome-stable
RUN wget -q https://chromedriver.storage.googleapis.com/91.0.4472.101/chromedriver_linux64.zip -O /tmp/chromedriver_linux64.zip \
    && unzip -qq /tmp/chromedriver_linux64.zip -d /usr/local/bin \
    && rm /tmp/chromedriver_linux64.zip \
    && chmod +x /usr/local/bin/chromedriver

You can get more information to run Robot Framework with docker:

https://github.com/dylanops/docker-robot-framework

General Grievance
  • 4,555
  • 31
  • 31
  • 45
Dylan Ngo
  • 21
  • 4