Robot Framework test case fails with “Element not found” when running selenium library based test case with headless chrome inside a DOCKER container Robot Framework test case fails with “Element not found” when running selenium library based test case with headless chrome inside a DOCKER container docker docker

Robot Framework test case fails with “Element not found” when running selenium library based test case with headless chrome inside a DOCKER container


I found a solution for the above problem statement.

First I tried using chrome and firefox instead of chromium. But apline doesn't had chrome and so switched my base image to ubuntu. Also, in general, ubuntu is suggested [Reference: https://pythonspeed.com/articles/base-image-python-docker-images/] as a best docker base image for running Python Applications.

But even after changing to ubuntu as new docker base image with chrome and firefox, it is the same error (blank page white screen).

Below error as well,

oot@a4ac8fd9a950:/opt/google/chrome# google-chrome --headless --no-sandbox https://<URL>[0306/152227.264852:WARNING:headless_content_main_delegate.cc(530)] Cannot create Pref Service with no user data dir.[0306/152227.265234:WARNING:discardable_shared_memory_manager.cc(194)] Less than 64MB of free space in temporary directory for shared memory files: 63[0306/152227.269687:ERROR:bus.cc(393)] Failed to connect to the bus: Failed to connect to socket /var/run/dbus/system_bus_socket: No such file or directory[0306/152228.160231:ERROR:cert_issuer_source_aia.cc(32)] Error parsing cert retrieved from AIA (as DER):ERROR: Failed parsing Certificate SEQUENCEERROR: Failed parsing Certificate[0306/152228.363766:ERROR:cert_issuer_source_aia.cc(32)] Error parsing cert retrieved from AIA (as DER):ERROR: Failed parsing Certificate SEQUENCEERROR: Failed parsing Certificate[0306/152228.363958:ERROR:cert_issuer_source_aia.cc(104)] AiaRequest::OnFetchCompleted got error -301[0306/152228.364625:ERROR:ssl_client_socket_impl.cc(924)] handshake failed; returned -1, SSL error code 1, net_error -202

Then I tried the same with Xvfb [Xvfb (short for X virtual framebuffer) is an in-memory display server for UNIX-like operating system (e.g., Linux). It enables you to run graphical applications without a display (e.g., browser tests on a CI server) while also having the ability to take screenshots.] This worked. Giving all the contents below for reference.

Modified the docker file as below:

FROM ubuntu:20.04# Set the reports directory environment variableENV ROBOT_REPORTS_DIR /opt/robotframework/reports# Set the tests directory environment variableENV ROBOT_TESTS_DIR /opt/robotframework/tests# Set the working directory environment variableENV ROBOT_WORK_DIR /opt/robotframework/temp# Set number of threads for parallel execution# By default, no parallelisationENV ROBOT_THREADS 1ENV DEBIAN_FRONTEND=noninteractive# Install system dependenciesRUN apt-get update \  && apt-get install --quiet --assume-yes \    python3-pip \    unzip \    firefox \    wget \    curl \    vim \    ca-certificates \    git \    jq \    xvfb# Install chrome packageRUN wget --no-verbose https://dl.google.com/linux/direct/google-chrome-stable_current_amd64.debRUN dpkg --install google-chrome-stable_current_amd64.deb; apt-get --fix-broken --assume-yes install#Install robotframework and required libraries from the requirements fileADD requirements.txt /RUN pip3 install \    --no-cache-dir \    -r requirements.txt# Install webdrivers for chrome and firefoxRUN CHROMEDRIVER_VERSION=`wget --no-verbose --output-document - https://chromedriver.storage.googleapis.com/LATEST_RELEASE` && \    wget --no-verbose --output-document /tmp/chromedriver_linux64.zip http://chromedriver.storage.googleapis.com/$CHROMEDRIVER_VERSION/chromedriver_linux64.zip && \    unzip -qq /tmp/chromedriver_linux64.zip -d /opt/chromedriver && \    chmod +x /opt/chromedriver/chromedriver && \    ln -fs /opt/chromedriver/chromedriver /usr/local/bin/chromedriverRUN GECKODRIVER_VERSION=`wget --no-verbose --output-document - https://api.github.com/repos/mozilla/geckodriver/releases/latest | grep tag_name | cut -d '"' -f 4` && \    wget --no-verbose --output-document /tmp/geckodriver.tar.gz https://github.com/mozilla/geckodriver/releases/download/$GECKODRIVER_VERSION/geckodriver-$GECKODRIVER_VERSION-linux64.tar.gz && \    tar --directory /opt -zxf /tmp/geckodriver.tar.gz && \    chmod +x /opt/geckodriver && \    ln -fs /opt/geckodriver /usr/local/bin/geckodriver# Create the default report and work folders with the default user to avoid runtime issues# These folders are writeable by anyone, to ensure the user can be changed on the command line.RUN mkdir -p ${ROBOT_REPORTS_DIR} \  && mkdir -p ${ROBOT_WORK_DIR} \  && chmod ugo+w ${ROBOT_REPORTS_DIR} ${ROBOT_WORK_DIR}# Installing product related utilities inside the containerXXXXXXXX# Allow any user to write logsRUN chmod ugo+w /var/log# Update system pathENV PATH=/opt/robotframework/bin:$PATH# A dedicated work folder to allow for the creation of temporary filesWORKDIR ${ROBOT_WORK_DIR}

Requirement text file:

#Required robot framework packagesrobotframework==3.2.2robotframework-requests==0.7.2robotframework-seleniumlibrary==4.5.0robotframework-jsonlibrary==0.3.1robotframework-kubelibrary==0.2.0robotframework-xvfb==1.2.2

New Robot FW test case with Xvfb:

*** Settings ***Library    SeleniumLibraryLibrary    XvfbRobot*** Test Cases ***Login To GUI    [Documentation]  To open GUI and login with valid credentials    Start Virtual Display    1920    1080    Open Browser    ${URL}    Set Window Size    1920    1080    Set Browser Implicit Wait    5    Input Text    id=username    ${username}    Input Text    id=password    ${password}    Click Button    //input[@value='Sign in']