Sign inSign up

sbennet2k/robot-framework

By sbennet2k

•Updated over 4 years ago

Docker image based on ubuntu to run Robot Framework tests (SeleniumLibrary and Browser library)

Image
0

1.0K

sbennet2k/robot-framework repository overview

⁠docker-robot-framework

⁠About the project:

This project consists of a Docker image based on ubuntu to run Robot Framework tests.

Setup includes the latest stable version of Google Chrome, latest Firefox version and corresponding webdrivers for running Selenium library tests.

Running Browser library tests is also supported making use of latest browser versions bundled with Playwright: chromium, firefox, webkit

⁠Background & Need:

A docker image that can be used to:

  • run RF Selenium library tests with the latest stable versions of Google Chrome and Firefox
  • run RF Browser library tests with Playwright bundled browsers
  • make use of the latest versions of Robot Framework packages (no strict version requirement)
⁠Reference:

This docker image is structured on the popular ppodgorsek/docker-robot-framework⁠ project. You will notice that usage and running tests using this docker image is similar to ppodgorsek/docker-robot-framework⁠.

⁠Available Packages, Browsers

Latest version of the following packages are used:

⁠Using the container

Following command structure can be used to run the container:

docker run --shm-size=<shm_size> \
    -v <local path to the reports dir>:/opt/robotframework/reports:Z \
    -v <local path to the test suites dir>:/opt/robotframework/tests:Z \
    -e ROBOT_WORK_DIR=<working_dir_to_run_tests>
    -e BROWSER=<browser_to_use>
    -e ROBOT_OPTIONS="<robot_options>" \
    -e ROBOT_THREADS=<num_of_parallel_threads> \
    -e PABOT_OPTIONS="<pabot_options>" \
    sbennet2k/robot-framework:<version>
⁠Changing container's tests, reports and working directories

It is possible to use different directories to read tests from, to generate reports to and working directory. Following environment variables can be set in the run command to change the defaults:

  • ROBOT_REPORTS_DIR (default: /opt/robotframework/reports)
  • ROBOT_TESTS_DIR (default: /opt/robotframework/tests)
  • ROBOT_WORK_DIR (default: /opt/robotframework/temp)
⁠Setting browser to use
⁠Using Docker Env Variable

Browser to use for running tests can be defined by passing an env variable -e BROWSER=<browser_to_use> to the docker run command. e.g. -e BROWSER=chrome, -e BROWSER=firefox.

And in the test script, the following variable can be defined to get the value from BROWSER env variable. ${BROWSER} RF variable now refers to the browser to use for running the tests.

*** Variables ***
${BROWSER}    %{BROWSER}
⁠Using env variable in ROBOT_OPTIONS

Alternatively, the browser to use variable can be passed via ROBOT_OPTIONS: -e ROBOT_OPTIONS="--variable BROWSER:chrome"

In test script, browser to use value will be directly available in ${BROWSER} variable.

⁠Changing screen resolution

Following environment variables can be set to define the virtual screen settings:

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

Refer the sample tests on how these values can be leveraged from Test Scripts to set the window size (SeleniumLibrary) or viewport (Browser library).

⁠Passing robot options

Robot Framework options can be passed by using the ROBOT_OPTIONS environment variable, e.g.:

docker run \
    -v `pwd`/tests:/opt/robotframework/tests:Z
    -e ROBOT_OPTIONS="--loglevel DEBUG --include browser_lib_test --xunit /opt/robotframework/reports/xunit_report.xml" \
    sbennet2k/robot-framework:latest

Refer: RobotFramework Command Line Options⁠

⁠Parallelization using pabot

Executing Test Suites in parallel using pabot can be defined by ROBOT_THREADS (default: 1, no parallelization) environment variable, e.g.:

docker run \
    -v `pwd`/tests:/opt/robotframework/tests:Z
    -e ROBOT_THREADS=2 \
    sbennet2k/robot-framework:latest
⁠pabot options

When using parallelization, it is possible to pass additional pabot options⁠. These can be passed by using the PABOT_OPTIONS environment variable, e.g.:

docker run \
    -v `pwd`/tests:/opt/robotframework/tests:Z
    -e ROBOT_THREADS=2 \
    -e PABOT_OPTIONS="--testlevelsplit" \
    sbennet2k/robot-framework:latest
⁠Setting Timezone

To set the timezone used inside the Docker image, TZ environment variable can be set (defaults to Europe/Helsinki ):

docker run \
    -v `pwd`/tests:/opt/robotframework/tests:Z
    -e TZ=America/New_York \
    sbennet2k/robot-framework:latest
⁠Defining unique Test Run ID

There may be a need at times to define a test run ID to avoid overwriting consecutive execution reports and uniquely identifying test rums.

This can be accomplished with environment variable ROBOT_TEST_RUN_ID:

  • If the test run ID is empty, the final reports folder will be: ${ROBOT_REPORTS_DIR}

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

    docker run
    -v pwd/tests:/opt/robotframework/tests:Z -e ROBOT_TEST_RUN_ID="<unique_test_id>"
    sbennet2k/robot-framework:latest

The final reports folder is also available to robot test scripts via exported variable ROBOT_REPORTS_FINAL_DIR.

⁠Testing this project

Tests are available in tests directory for trying out.

Screenshots and Robot output, log & reports for the run will be available under reports directory.

⁠On Linux / Mac terminal:
# Run SeleniumLibrary and Browser library tests with Chrome/Chromium
docker run \
    -v `pwd`/reports:/opt/robotframework/reports:Z \
    -v `pwd`/tests:/opt/robotframework/tests:Z \
    -e BROWSER=chrome \
    sbennet2k/robot-framework:latest

# Run SeleniumLibrary and Browser library tests with Firefox
docker run \
    -v `pwd`/reports:/opt/robotframework/reports:Z \
    -v `pwd`/tests:/opt/robotframework/tests:Z \
    -e BROWSER=firefox \
    sbennet2k/robot-framework:latest

# Run Browser library test with Webkit
docker run \
    -v `pwd`/reports:/opt/robotframework/reports:Z \
    -v `pwd`/tests:/opt/robotframework/tests:Z
    -e ROBOT_OPTIONS="--include browser_lib_test" \
    -e BROWSER=safari \
    sbennet2k/robot-framework:latest
⁠On Windows command prompt:
# Run SeleniumLibrary and Browser library tests with Chrome/Chromium
docker run \
    -v %cd%\reports:/opt/robotframework/reports:Z \
    -v %cd%\tests:/opt/robotframework/tests:Z \
    -e BROWSER=chrome \
    sbennet2k/robot-framework:latest

# Run SeleniumLibrary and Browser library tests with Firefox
docker run \
    -v %cd%\reports:/opt/robotframework/reports:Z \
    -v %cd%\tests:/opt/robotframework/tests:Z \
    -e BROWSER=firefox \
    sbennet2k/robot-framework:latest

# Run only Browser library test with Webkit
docker run \
    -v %cd%\reports:/opt/robotframework/reports:Z \
    -v %cd%\tests:/opt/robotframework/tests:Z
    -e ROBOT_OPTIONS="--include browser_lib_test" \
    -e BROWSER=safari \
    sbennet2k/robot-framework:latest

⁠Acknowledgements

⁠Contributions

Feel free to contribute improvement ideas and issues in the GitHub project⁠.

Tag summary

Content type

Image

Digest

Size

1.1 GB

Last updated

over 4 years ago

docker pull sbennet2k/robot-framework