Coder Social home page Coder Social logo

ppodgorsek / docker-robot-framework Goto Github PK

View Code? Open in Web Editor NEW
324.0 20.0 232.0 6.42 MB

Robot Framework in Docker

Home Page: https://cloud.docker.com/repository/docker/ppodgorsek/robot-framework

License: MIT License

Shell 16.38% RobotFramework 33.98% Dockerfile 49.64%
robot-framework firefox docker chrome selenium browser microsoft-edge playwright

docker-robot-framework's Introduction

Robot Framework in Docker, with Firefox, Chrome and Microsoft Edge

Table of contents


What is it?

This project consists of a container image containing a Robot Framework installation.

This installation also contains Firefox, Chrome, Microsoft Edge, along with the Selenium and Playwright/RFBrowser library for Robot Framework.

Versioning

The versioning of this image follows the one of Robot Framework:

  • Major version matches the one of Robot Framework
  • Minor and patch versions are specific to this project (allows to update the versions of the other dependencies)

The versions used are:

As stated by the official GitHub project, starting from version 3.0, Selenium2Library is renamed to SeleniumLibrary and this project exists mainly to help with transitioning. The Selenium2Library 3.0.0 is also the last release and for new releases, please look at the SeleniumLibrary project.

Running the container

This container can be run using the following command:

docker run \
    -v <local path to the reports' folder>:/opt/robotframework/reports:Z \
    -v <local path to the test suites' folder>:/opt/robotframework/tests:Z \
    ppodgorsek/robot-framework:<version>

Switching browsers

Browsers can be easily switched. It is recommended to define ${BROWSER} %{BROWSER} in your Robot variables and to use ${BROWSER} in your test cases. This allows to set the browser in a single place if needed.

When running your tests, simply add -e BROWSER=chrome, -e BROWSER=firefox or -e BROWSER=edgeto the run command.

Please note: edge will work with Selenium but not the Browser Library, as the latter currently doesn't have an easy mechanism to install additional browsers. Playwright, on which the Browser library relies, cannot install additional browsers on Linux platforms other than Ubuntu/Debian and suggests using Chromium to test Microsoft Edge scenarios, unless you require Edge-specific capabilities.

Changing the container's screen resolution

It is possible to define the settings of the virtual screen in which the browser is run by changing several environment variables:

  • SCREEN_COLOUR_DEPTH (default: 24)
  • SCREEN_HEIGHT (default: 1080)
  • SCREEN_WIDTH (default: 1920)

Changing the container's tests and reports directories

It is possible to use different directories to read tests from and to generate reports to. This is useful when using a complex test file structure. To change the defaults, set the following environment variables:

  • ROBOT_REPORTS_DIR (default: /opt/robotframework/reports)
  • ROBOT_TESTS_DIR (default: /opt/robotframework/tests)

Parallelisation

It is possible to parallelise the execution of your test suites. Simply define the ROBOT_THREADS environment variable, for example:

docker run \
    -e ROBOT_THREADS=4 \
    ppodgorsek/robot-framework:latest

By default, there is no parallelisation.

Parallelisation options

When using parallelisation, it is possible to pass additional pabot options, such as --testlevelsplit, --argumentfile, --ordering, etc. These can be passed by using the PABOT_OPTIONS environment variable, for example:

docker run \
    -e ROBOT_THREADS=4 \
    -e PABOT_OPTIONS="--testlevelsplit" \
    ppodgorsek/robot-framework:latest

Passing additional options

RobotFramework supports many options such as --exclude, --variable, --loglevel, etc. These can be passed by using the ROBOT_OPTIONS environment variable, for example:

docker run \
    -e ROBOT_OPTIONS="--loglevel DEBUG" \
    ppodgorsek/robot-framework:latest

Testing emails

This project includes the IMAP library which allows Robot Framework to connect to email servers.

A suggestion to automate email testing is to run a Mailcatcher instance in Docker which allows IMAP connections. This will ensure emails are discarded once the tests have been run.

Dealing with Datetimes and Timezones

This project is meant to allow your tests to run anywhere. Sometimes that can be in a different timezone than your local one or of the location under test. To help solve such issues, this image includes the DateTimeTZ Library.

To set the timezone used inside the Docker image, you can set the TZ environment variable:

docker run \
    -e TZ=America/New_York \
    ppodgorsek/robot-framework:latest

Installing additional dependencies

It is possible to install additional dependencies dynamically at runtime rather than having to extend this image.

To do so, simply mount a text file containing the list of dependencies you would like to install using pip: (by default, this file is empty if not mounted)

docker run \
    -v <local path to the dependency file>:/opt/robotframework/pip-requirements.txt:Z \
    -v <local path to the test suites' folder>:/opt/robotframework/tests:Z \
    ppodgorsek/robot-framework:latest

The file must follow Pip's official requirements file format.

Here is a example of what such a file could contain:

robotframework-docker==1.4.2
rpa==1.50.0

For large dependencies, it is still recommended to extend the project's image and to add them there, to avoid delaying the CI/CD pipelines with repeated dependency installations.

Security consideration

By default, containers are implicitly run using --user=1000:1000, please remember to adjust that command-line setting accordingly, for example:

docker run \
    --user=1001:1001 \
    ppodgorsek/robot-framework:latest

Remember that that UID/GID should be allowed to access the mounted volumes in order to read the test suites and to write the output.

Additionally, it is possible to rely on user namespaces to further secure the execution. This is well described in the official container documentation:

This is a good security practice to make sure containers cannot perform unwanted changes on the host. In that sense, Podman is probably well ahead of Docker by not relying on a root daemon to run its containers.

Continuous integration

It is possible to run the project from within a Jenkins pipeline by relying on the shell command line directly:

pipeline {
    agent any
    stages {
        stage('Functional regression tests') {
            steps {
                sh "docker run --shm-size=1g -e BROWSER=firefox -v $WORKSPACE/robot-tests:/opt/robotframework/tests:Z -v $WORKSPACE/robot-reports:/opt/robotframework/reports:Z ppodgorsek/robot-framework:latest"
            }
        }
    }
}

The pipeline stage can also rely on a Docker agent, as shown in the example below:

pipeline {
    agent none
    stages {
        stage('Functional regression tests') {
            agent { docker {
                image 'ppodgorsek/robot-framework:latest'
                args '--shm-size=1g -u root' }
            }
            environment {
                BROWSER = 'firefox'
                ROBOT_TESTS_DIR = "$WORKSPACE/robot-tests"
                ROBOT_REPORTS_DIR = "$WORKSPACE/robot-reports"
            }
            steps {
                sh '''
                    /opt/robotframework/bin/run-tests-in-virtual-screen.sh
                '''
            }
        }
    }
}

Defining a test run ID

When relying on Continuous Integration tools, it can be useful to define a test run ID such as the build number or branch name to avoid overwriting consecutive execution reports.

For that purpose, the ROBOT_TEST_RUN_ID variable was introduced:

  • If the test run ID is empty, the reports folder will be: ${ROBOT_REPORTS_DIR}/
  • If the test run ID was provided, the reports folder will be: ${ROBOT_REPORTS_DIR}/${ROBOT_TEST_RUN_ID}/

It can simply be passed during the execution, such as:

docker run \
    -e ROBOT_TEST_RUN_ID="feature/branch-name" \
    ppodgorsek/robot-framework:latest

By default, the test run ID is empty.

Upload test reports to an AWS S3 bucket

To upload the report of a test run to an S3 bucket, you need to define the following environment variables:

docker run \
    -e AWS_ACCESS_KEY_ID=<your AWS key> \
    -e AWS_SECRET_ACCESS_KEY=<your AWS secret> \
    -e AWS_DEFAULT_REGION=<your AWS region e.g. eu-central-1> \
    -e AWS_BUCKET_NAME=<name of your S3 bucket> \
    ppodgorsek/robot-framework:latest

Testing this project

Not convinced yet? Simple tests have been prepared in the test/ folder, you can run them using the following commands:

# Using Chromium
docker run \
    -v `pwd`/reports:/opt/robotframework/reports:Z \
    -v `pwd`/test:/opt/robotframework/tests:Z \
    -e BROWSER=chrome \
    ppodgorsek/robot-framework:latest

# Using Firefox
docker run \
    -v `pwd`/reports:/opt/robotframework/reports:Z \
    -v `pwd`/test:/opt/robotframework/tests:Z \
    -e BROWSER=firefox \
    ppodgorsek/robot-framework:latest

For Windows users who use PowerShell, the commands are slightly different:

# Using Chromium
docker run \
    -v ${PWD}/reports:/opt/robotframework/reports:Z \
    -v ${PWD}/test:/opt/robotframework/tests:Z \
    -e BROWSER=chrome \
    ppodgorsek/robot-framework:latest

# Using Firefox
docker run \
    -v ${PWD}/reports:/opt/robotframework/reports:Z \
    -v ${PWD}/test:/opt/robotframework/tests:Z \
    -e BROWSER=firefox \
    ppodgorsek/robot-framework:latest

Screenshots of the results will be available in the reports/ folder.

Troubleshooting

Chromium is crashing

Chrome drivers might crash due to the small size of /dev/shm in the docker container:

UnknownError: session deleted because of page crash

This is a known bug of Chromium.

To avoid this error, please change the shm size when starting the container by adding the following parameter: --shm-size=1g (or any other size more suited to your tests)

Accessing the logs

In case further investigation is required, the logs can be accessed by mounting their folder. Simply add the following parameter to your run command:

  • Linux/Mac: -v `pwd`/logs:/var/log:Z
  • Windows: -v ${PWD}/logs:/var/log:Z

Chromium allows to set additional environment properties, which can be useful when debugging:

  • webdriver.chrome.verboseLogging=true: enables the verbose logging mode
  • webdriver.chrome.logfile=/path/to/chromedriver.log: sets the path to Chromium's log file

Error: Suite contains no tests

When running tests, an unexpected error sometimes occurs:

[Error] Suite contains no tests.

There are two main causes to this:

  • Either the test folder is not the right one,
  • Or the permissions on the test folder/test files are too restrictive.

As there can sometimes be issues as to where the tests are run from, make sure the correct folder is used by trying the following actions:

  • Use a full path to the folder instead of a relative one,
  • Replace any`pwd`or ${PWD} by the full path to the folder.

It is also important to check if Robot Framework is allowed to access the resources it needs, i.e.:

  • The folder where the tests are located,
  • The test files themselves.

Database tests are failing in spite of the DatabaseLibrary being present

As per their official project page, the Robot Framework DatabaseLibrary contains utilities meant for Robot Framework's usage. This can allow you to query your database after an action has been made to verify the results. This is compatible with any Database API Specification 2.0 module.

It is anyway mandatory to extend the container image to install the specific database module relevant to your tests, such as:

Supported devices and architectures

As mentioned on the Docker Hub, the project has been built and uploaded as a linux/amd64 image only. This means ARM devices such as MacBook M1/M2 and Amazon EC2 Graviton won't be able to run the image with the default configuration.

As mentioned in the official documentation, Podman and Docker provide a --platform option which selects a given application architecture, such as:

docker run \
    --platform linux/amd64 \
    -v <local path to the reports' folder>:/opt/robotframework/reports:Z \
    -v <local path to the test suites' folder>:/opt/robotframework/tests:Z \
    ppodgorsek/robot-framework:<version>

Please note: builds and automated tests of this project will remain performed on a linux/amd64 architecture so such emulation might not work, depending on your device and operating system.

If this does not solve your platform-related issues, you will have to rebuild the image for your device/platform, specifying that --platform option during the build and run.

Please contribute!

Have you found an issue? Do you have an idea for an improvement? Feel free to contribute by submitting it on the GitHub project.

docker-robot-framework's People

Contributors

christian-roggia avatar dencze avatar dprevost-lmi avatar jakob-em avatar jeabakker avatar juacompe avatar krizm avatar linh-ngophuochoai avatar nilsty avatar ppodgorsek avatar rkefi84 avatar rs-roy avatar ultimatedogg avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

docker-robot-framework's Issues

SimpleTest with chrome failed ?

Hi,

I'm testing your docker image with a simple ROBOT test like Simple.robot.txt

But i get error: WebDriverException: Message: unknown error: Chrome failed to start: exited abnormally

Robot debug do not help very much:
debug.txt

And inside image chrome log file, i get a lot of:
DevTools Request: 127.0.0.1:12585/json/version. DevTools request failed

Can you help me or send me a simple working robot test sample ?

thanks !

Automated update of dependencies in Dockerfile

Investigate if Travis could also be used to update the versions of all dependencies and to commit an updated Dockerfile whenever it is possible (merged to master via an automated pull request merge).

This would allow to regularly push updated Docker images without the need for a manual intervention.

Add parallel execution support

pabot should be added to the toolchain of this chart. This would allow users to launch tests in parallel whenever it is required.

This can be done by passing environment variables to the docker container and invoking a bash script whenever required.

Internally we are currently using the following bash script:

#!/bin/sh

set -e

# Install parallel executor "pabot"
pip install --upgrade --quiet robotframework-pabot

# Set number of threads for parallel execution
RF_THREADS=4

# Launch Robot Framework instances
xvfb-run \
    --server-args="-screen 0 ${SCREEN_WIDTH}x${SCREEN_HEIGHT}x${SCREEN_COLOUR_DEPTH} -ac" \
    pabot \
        --verbose \
        --processes $RF_THREADS \
        --outputdir /opt/robotframework/reports \
        ${ROBOT_OPTIONS} \
        /opt/robotframework/tests

exit 0

cannot build the project

I ran command docker build -t robot-framework . and got the error below.

Error: Unable to find a match
The command '/bin/sh -c dnf upgrade -y	&& dnf install -y		chromedriver-63.0.*		
chromium-63.0.*		firefox-58.0-*python2-pip-9.0.1-*		xorg-x11-server-Xvfb-1.19.*	&& dnf 
clean all' returned a non-zero code: 1

My docker version as below.

docker version
Client:
 Version:	17.12.0-ce
 API version:	1.35
 Go version:	go1.9.2
 Git commit:	c97c6d6
 Built:	Wed Dec 27 20:03:51 2017
 OS/Arch:	darwin/amd64

Server:
 Engine:
  Version:	17.12.0-ce
  API version:	1.35 (minimum version 1.12)
  Go version:	go1.9.2
  Git commit:	c97c6d6
  Built:	Wed Dec 27 20:12:29 2017
  OS/Arch:	linux/amd64
  Experimental:	true

Chromedriver has the wrong version?

Hey Paul, thanks for this docker, I'm trying to install it in a Bitbucket Pipeline but it always fails when it tries to "Open Browser" in my tests. I have a feeling it's the chromedriver version you're using..? I'm looking all over the internet and it says chromedriver is on version '2.35' and you're using '63.0' just like chromium, could it be a typo?

dnf install -y chromedriver-66.0.* Failed, No match for arguments.

Complete!
Non-fatal scriptlet failure in rpm package libgcc
Non-fatal scriptlet failure in rpm package libgcc
Last metadata expiration check: 0:01:38 ago on Wed Jun 27 21:59:23 2018.
No match for argument: chromedriver-66.0.*
No match for argument: chromium-66.0.*
Error: Unable to find a match

Outdated Chromium causes Docker build to fail

Complete!
Last metadata expiration check: 0:00:57 ago on Tue Apr 3 08:35:14 2018.
No match for argument: chromedriver-63.0.*
No match for argument: chromium-63.0.*
Error: Unable to find a match
The command '/bin/sh -c dnf upgrade -y && dnf install -y chromedriver-$CHROMIUM_VERSION chromium-$CHROMIUM_VERSION firefox-$FIREFOX_VERSION python2-pip-9.0.1-* xauth xorg-x11-server-Xvfb-1.19.* which wget && dnf clean all' returned a non-zero code: 1

Document how to switch browsers

It would be useful to have more information about how to switch browsers in test suites, by only setting the browser on the command-line.

Error: Suite 'Tests' contains no tests.

Hi,

When I try to run a test I get [Error] Suite 'Tests' contains no tests.
I've downloaded sources from GitHub and I'm in "C:\DockerTests\docker-robot-framework-master" folder and I run following command:
docker run
-v ${PWD}/reports:/opt/robotframework/reports:Z
-v ${PWD}/test:/opt/robotframework/tests:Z
-e BROWSER=chrome
ppodgorsek/robot-framework:latest

Any hint?

BR
Jakub

Create simple test

The repository should include a simple test in order to check that the project is always working.

Set up automated build of pull requests

All pull requests should be built automatically before being merged to the master branch.
The master branch should always remain stable, as it built on the Docker Hub.

Missing drivers

I'm not sure how is this supposed to work, since it doesn't contain selenium drivers?

WebDriverException: Message: 'chromedriver' executable needs to be in PATH. Please see https://sites.google.com/a/chromium.org/chromedriver/home

WebDriverException: Message: 'geckodriver' executable needs to be in PATH.

Am I missing something obvious?

[ ERROR ] Suite 'Tests' contains no tests

Getting [ ERROR ] Suite 'Tests' contains no tests when trying to run the image and when specifying either browser.

Running Docker toolbox:
command:
docker run -v /Users/dthmacpro/Documents/robotfw/reports:/opt/robotframework/reports -v /Users/dthmacpro/Documents/robotfw/test_suites:/opt/robotframework/tests -e BROWSER=firefox ppodgorsek/robot-framework:latest
[ ERROR ] Suite 'Tests' contains no tests.

not sure why it's not seeing the Tests... please assist, thanks!

Make dependency resolution more flexible

Currently, all packages which are installed have a specific version. This makes the build break often, as those versions quickly become outdated and replaced by new releases.
The installed packages should therefore be declared in a more flexible manner.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.