4

Setup Robot Environment With Docker

 2 years ago
source link: https://ray-g.github.io/docker/setup-robot-with-docker/
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.

Setup Robot Environment With Docker

Jun 25, 2018
2 min read

Robot framework plus selenium is quite suitable for UI automation testing.

But it requires a GUI to open the browser and execute such test suites. Unfortunatly, most of the automation environments are headless servers, even if we can use virtual machines with virtual graphical environemnt, it is quite a performance overhead.

With docker, we can save quite a lot of energy and make the automation quite easy. With the xvfb it is able to execute robot and selenium inside the docker.

Here is the solution:

Dockerfile

FROM ubuntu:16.04

RUN apt-get update && \
DEBIAN_FRONTEND=noninteractive \
apt-get -y install \
sudo \
python2.7 \
python-pip \
libffi-dev \
libssl-dev \
dbus-x11 \
fonts-dejavu fonts-liberation hicolor-icon-theme \
xvfb \
firefox=45.0.2+build1-0ubuntu1

RUN pip install \
robotframework \
robotframework-selenium2library \
robotframework-sshlibrary \
pyvmomi \
pysphere

RUN export uid=1000 gid=1000 && \
mkdir -p /home/robot && \
echo “robot:x:${uid}:${gid}:robot,,,:/home/robot:/bin/bash” >> /etc/passwd && \
echo “robot:x:${uid}:” >> /etc/group && \
usermod –aG sudo robot && \
chown ${uid}:${gid} -R /home/robot

USER robot
ENV HOME /home/robot
RUN mkdir /home/robot/working_dir
ENV ENV_ROBOT_PATH /home/robot/working_dir

Usage

  1. In the folder where the Dockerfile is, build docker image: docker build --rm -t robot-env:ff45gui .
  2. One time run: docker run --rm -e DISPLAY=$DISPLAY -e ENV_TARGET_IP=<your-target-ip> -v /tmp/.X11-unix:/tmp/.X11-unix -v <path-to-your-robot-file>:/home/robot/working_dir -w /home/robot /working_dir robot-env:ff45gui pybot <path-to-your-robot-file>
  3. Multiple times run: docker run -it --rm -e DISPLAY=$DISPLAY -v /tmp/.X11-unix:/tmp/.X11-unix -v <path-to-your-robot-file>:/home/robot/working_dir -w /home/robot/working_dir robot-env:f f45gui, and then in the promote execute robot with ENV_TARGET_IP=<your-target-ip> pybot <path-to-your-robot-file>

About Joyk


Aggregate valuable and interesting links.
Joyk means Joy of geeK