Skip to content

Commit

Permalink
Merge pull request #473 from ppodgorsek/issue-376
Browse files Browse the repository at this point in the history
Issue #376 - Cannot install easily custom libraries
  • Loading branch information
ppodgorsek committed Feb 7, 2024
2 parents 746a6cb + 6ae3d09 commit 569a433
Show file tree
Hide file tree
Showing 6 changed files with 176 additions and 56 deletions.
169 changes: 113 additions & 56 deletions .github/workflows/docker-build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -37,44 +37,124 @@ jobs:
run:
podman build . --tag $IMAGE_NAME --file Dockerfile
- name: Basic Test
run:
podman run --shm-size=1g -v `pwd`/test:/opt/robotframework/tests:Z -e BROWSER=$BROWSER $IMAGE_NAME
run: |
podman run --shm-size=1g \
-v `pwd`/test/browser-library.robot:/opt/robotframework/tests/browser-library.robot:Z \
-v `pwd`/test/faker.robot:/opt/robotframework/tests/faker.robot:Z \
-v `pwd`/test/requests.robot:/opt/robotframework/tests/requests.robot:Z \
-v `pwd`/test/selenium.robot:/opt/robotframework/tests/selenium.robot:Z \
-v `pwd`/test/timezones.robot:/opt/robotframework/tests/timezones.robot:Z \
-e BROWSER=$BROWSER \
$IMAGE_NAME
- name: Test dependency installation
run: |
podman run --shm-size=1g \
-v `pwd`/test/pip-dependencies/main.robot:/opt/robotframework/tests/pip-dependencies.robot:Z \
-v `pwd`/test/pip-dependencies/requirements.txt:/opt/robotframework/pip-requirements.txt:Z \
-e BROWSER=$BROWSER \
$IMAGE_NAME
- name: Colour Depth 16 Test
run:
podman run --shm-size=1g -v `pwd`/test:/opt/robotframework/tests:Z -e BROWSER=$BROWSER -e SCREEN_COLOUR_DEPTH=16 $IMAGE_NAME
run: |
podman run --shm-size=1g \
-v `pwd`/test/browser-library.robot:/opt/robotframework/tests/browser-library.robot:Z \
-v `pwd`/test/selenium.robot:/opt/robotframework/tests/selenium.robot:Z \
-e BROWSER=$BROWSER \
-e SCREEN_COLOUR_DEPTH=16 \
$IMAGE_NAME
- name: Screen Width 800x600 Test
run:
podman run --shm-size=1g -v `pwd`/test:/opt/robotframework/tests:Z -e BROWSER=$BROWSER -e SCREEN_WIDTH=800 -e SCREEN_HEIGHT=600 $IMAGE_NAME
run: |
podman run --shm-size=1g \
-v `pwd`/test/browser-library.robot:/opt/robotframework/tests/browser-library.robot:Z \
-v `pwd`/test/selenium.robot:/opt/robotframework/tests/selenium.robot:Z \
-e BROWSER=$BROWSER \
-e SCREEN_WIDTH=800 \
-e SCREEN_HEIGHT=600 \
$IMAGE_NAME
- name: Screen Width 1024x768 Test
run:
podman run --shm-size=1g -v `pwd`/test:/opt/robotframework/tests:Z -e BROWSER=$BROWSER -e SCREEN_WIDTH=1024 -e SCREEN_HEIGHT=768 $IMAGE_NAME
run: |
podman run --shm-size=1g \
-v `pwd`/test/browser-library.robot:/opt/robotframework/tests/browser-library.robot:Z \
-v `pwd`/test/selenium.robot:/opt/robotframework/tests/selenium.robot:Z \
-e BROWSER=$BROWSER \
-e SCREEN_WIDTH=1024 \
-e SCREEN_HEIGHT=768 \
$IMAGE_NAME
- name: Screen Width 1280x1024 Test
run:
podman run --shm-size=1g -v `pwd`/test:/opt/robotframework/tests:Z -e BROWSER=$BROWSER -e SCREEN_WIDTH=1280 -e SCREEN_HEIGHT=1024 $IMAGE_NAME
run: |
podman run --shm-size=1g \
-v `pwd`/test/browser-library.robot:/opt/robotframework/tests/browser-library.robot:Z \
-v `pwd`/test/selenium.robot:/opt/robotframework/tests/selenium.robot:Z \
-e BROWSER=$BROWSER \
-e SCREEN_WIDTH=1280 \
-e SCREEN_HEIGHT=1024 \
$IMAGE_NAME
- name: Screen Width 2560x1440 Test
run:
podman run --shm-size=1g -v `pwd`/test:/opt/robotframework/tests:Z -e BROWSER=$BROWSER -e SCREEN_WIDTH=2560 -e SCREEN_HEIGHT=1440 $IMAGE_NAME
run: |
podman run --shm-size=1g \
-v `pwd`/test/browser-library.robot:/opt/robotframework/tests/browser-library.robot:Z \
-v `pwd`/test/selenium.robot:/opt/robotframework/tests/selenium.robot:Z \
-e BROWSER=$BROWSER \
-e SCREEN_WIDTH=2560 \
-e SCREEN_HEIGHT=1440 \
$IMAGE_NAME
- name: Screen Width 3840x2160 Test
run:
podman run --shm-size=1g -v `pwd`/test:/opt/robotframework/tests:Z -e BROWSER=$BROWSER -e SCREEN_WIDTH=3840 -e SCREEN_HEIGHT=2160 $IMAGE_NAME
run: |
podman run --shm-size=1g \
-v `pwd`/test/browser-library.robot:/opt/robotframework/tests/browser-library.robot:Z \
-v `pwd`/test/selenium.robot:/opt/robotframework/tests/selenium.robot:Z \
-e BROWSER=$BROWSER \
-e SCREEN_WIDTH=3840 \
-e SCREEN_HEIGHT=2160 \
$IMAGE_NAME
- name: Debug Log Level Test
run:
podman run --shm-size=1g -v `pwd`/test:/opt/robotframework/tests:Z -e BROWSER=$BROWSER -e ROBOT_OPTIONS="--loglevel DEBUG" $IMAGE_NAME
run: |
podman run --shm-size=1g \
-v `pwd`/test/faker.robot:/opt/robotframework/tests/faker.robot:Z \
-e BROWSER=$BROWSER \
-e ROBOT_OPTIONS="--loglevel DEBUG" \
$IMAGE_NAME
- name: Basic Multithreaded Test
run:
podman run --shm-size=1g -v `pwd`/test:/opt/robotframework/tests:Z -e BROWSER=$BROWSER -e ROBOT_THREADS=4 $IMAGE_NAME
run: |
podman run --shm-size=1g \
-v `pwd`/test/browser-library.robot:/opt/robotframework/tests/browser-library.robot:Z \
-v `pwd`/test/faker.robot:/opt/robotframework/tests/faker.robot:Z \
-v `pwd`/test/requests.robot:/opt/robotframework/tests/requests.robot:Z \
-v `pwd`/test/selenium.robot:/opt/robotframework/tests/selenium.robot:Z \
-v `pwd`/test/timezones.robot:/opt/robotframework/tests/timezones.robot:Z \
-e BROWSER=$BROWSER \
-e ROBOT_THREADS=4 \
$IMAGE_NAME
- name: Test Level Multithreaded Test
run:
podman run --shm-size=1g -v `pwd`/test:/opt/robotframework/tests:Z -e BROWSER=$BROWSER -e ROBOT_THREADS=4 -e PABOT_OPTIONS="--testlevelsplit" $IMAGE_NAME
run: |
podman run --shm-size=1g \
-v `pwd`/test/browser-library.robot:/opt/robotframework/tests/browser-library.robot:Z \
-v `pwd`/test/faker.robot:/opt/robotframework/tests/faker.robot:Z \
-v `pwd`/test/requests.robot:/opt/robotframework/tests/requests.robot:Z \
-v `pwd`/test/selenium.robot:/opt/robotframework/tests/selenium.robot:Z \
-v `pwd`/test/timezones.robot:/opt/robotframework/tests/timezones.robot:Z \
-e BROWSER=$BROWSER \
-e ROBOT_THREADS=4 \
-e PABOT_OPTIONS="--testlevelsplit" \
$IMAGE_NAME
- name: Custom User Test
run:
podman run --user=2000 --shm-size=1g -v `pwd`/test:/opt/robotframework/tests:Z -e BROWSER=$BROWSER $IMAGE_NAME
run: |
podman run --user=2000 --shm-size=1g \
-v `pwd`/test/faker.robot:/opt/robotframework/tests/faker.robot:Z \
-e BROWSER=$BROWSER \
$IMAGE_NAME
- name: Custom User and Group Test
run:
podman run --user=2000:2000 --shm-size=1g -v `pwd`/test:/opt/robotframework/tests:Z -e BROWSER=$BROWSER $IMAGE_NAME
run: |
podman run --user=2000:2000 --shm-size=1g \
-v `pwd`/test/faker.robot:/opt/robotframework/tests/faker.robot:Z \
-e BROWSER=$BROWSER \
$IMAGE_NAME
- name: Datetime
run:
podman run --user=2000:2000 --shm-size=1g -v `pwd`/test:/opt/robotframework/tests:Z -e BROWSER=$BROWSER -e TZ="America/New_York" $IMAGE_NAME
run: |
podman run --user=2000:2000 --shm-size=1g \
-v `pwd`/test/timezones.robot:/opt/robotframework/tests/timezones.robot:Z \
-e BROWSER=$BROWSER \
-e TZ="America/New_York" \
$IMAGE_NAME
# Build and run tests for Microsoft Edge.
# This must be processed separately from Firefox and Chrome, due to the Browser library not handling Microsoft Edge by default
Expand All @@ -98,67 +178,56 @@ jobs:
-v `pwd`/test/timezones.robot:/opt/robotframework/tests/timezones.robot:Z \
-e BROWSER=$BROWSER \
$IMAGE_NAME
- name: Test dependency installation
run: |
podman run --shm-size=1g \
-v `pwd`/test/pip-dependencies/main.robot:/opt/robotframework/tests/pip-dependencies.robot:Z \
-v `pwd`/test/pip-dependencies/requirements.txt:/opt/robotframework/pip-requirements.txt:Z \
-e BROWSER=$BROWSER \
$IMAGE_NAME
- name: Colour Depth 16 Test
run: |
podman run --shm-size=1g \
-v `pwd`/test/faker.robot:/opt/robotframework/tests/faker.robot:Z \
-v `pwd`/test/requests.robot:/opt/robotframework/tests/requests.robot:Z \
-v `pwd`/test/selenium.robot:/opt/robotframework/tests/selenium.robot:Z \
-v `pwd`/test/timezones.robot:/opt/robotframework/tests/timezones.robot:Z \
-e BROWSER=$BROWSER \
-e SCREEN_COLOUR_DEPTH=16 \
$IMAGE_NAME
- name: Screen Width 800x600 Test
run: |
podman run --shm-size=1g \
-v `pwd`/test/faker.robot:/opt/robotframework/tests/faker.robot:Z \
-v `pwd`/test/requests.robot:/opt/robotframework/tests/requests.robot:Z \
-v `pwd`/test/selenium.robot:/opt/robotframework/tests/selenium.robot:Z \
-v `pwd`/test/timezones.robot:/opt/robotframework/tests/timezones.robot:Z \
-e BROWSER=$BROWSER \
-e SCREEN_WIDTH=800 \
-e SCREEN_HEIGHT=600 \
$IMAGE_NAME
- name: Screen Width 1024x768 Test
run: |
podman run --shm-size=1g \
-v `pwd`/test/faker.robot:/opt/robotframework/tests/faker.robot:Z \
-v `pwd`/test/requests.robot:/opt/robotframework/tests/requests.robot:Z \
-v `pwd`/test/selenium.robot:/opt/robotframework/tests/selenium.robot:Z \
-v `pwd`/test/timezones.robot:/opt/robotframework/tests/timezones.robot:Z \
-e BROWSER=$BROWSER \
-e SCREEN_WIDTH=1024 \
-e SCREEN_HEIGHT=768 \
$IMAGE_NAME
- name: Screen Width 1280x1024 Test
run: |
podman run --shm-size=1g \
-v `pwd`/test/faker.robot:/opt/robotframework/tests/faker.robot:Z \
-v `pwd`/test/requests.robot:/opt/robotframework/tests/requests.robot:Z \
-v `pwd`/test/selenium.robot:/opt/robotframework/tests/selenium.robot:Z \
-v `pwd`/test/timezones.robot:/opt/robotframework/tests/timezones.robot:Z \
-e BROWSER=$BROWSER \
-e SCREEN_WIDTH=1280 \
-e SCREEN_HEIGHT=1024 \
$IMAGE_NAME
- name: Screen Width 2560x1440 Test
run: |
podman run --shm-size=1g \
-v `pwd`/test/faker.robot:/opt/robotframework/tests/faker.robot:Z \
-v `pwd`/test/requests.robot:/opt/robotframework/tests/requests.robot:Z \
-v `pwd`/test/selenium.robot:/opt/robotframework/tests/selenium.robot:Z \
-v `pwd`/test/timezones.robot:/opt/robotframework/tests/timezones.robot:Z \
-e BROWSER=$BROWSER \
-e SCREEN_WIDTH=2560 \
-e SCREEN_HEIGHT=1440 \
$IMAGE_NAME
- name: Screen Width 3840x2160 Test
run: |
podman run --shm-size=1g \
-v `pwd`/test/faker.robot:/opt/robotframework/tests/faker.robot:Z \
-v `pwd`/test/requests.robot:/opt/robotframework/tests/requests.robot:Z \
-v `pwd`/test/selenium.robot:/opt/robotframework/tests/selenium.robot:Z \
-v `pwd`/test/timezones.robot:/opt/robotframework/tests/timezones.robot:Z \
-e BROWSER=$BROWSER \
-e SCREEN_WIDTH=3840 \
-e SCREEN_HEIGHT=2160 \
Expand All @@ -167,9 +236,6 @@ jobs:
run: |
podman run --shm-size=1g \
-v `pwd`/test/faker.robot:/opt/robotframework/tests/faker.robot:Z \
-v `pwd`/test/requests.robot:/opt/robotframework/tests/requests.robot:Z \
-v `pwd`/test/selenium.robot:/opt/robotframework/tests/selenium.robot:Z \
-v `pwd`/test/timezones.robot:/opt/robotframework/tests/timezones.robot:Z \
-e BROWSER=$BROWSER \
-e ROBOT_OPTIONS="--loglevel DEBUG" \
$IMAGE_NAME
Expand Down Expand Up @@ -198,26 +264,17 @@ jobs:
run: |
podman run --user=2000 --shm-size=1g \
-v `pwd`/test/faker.robot:/opt/robotframework/tests/faker.robot:Z \
-v `pwd`/test/requests.robot:/opt/robotframework/tests/requests.robot:Z \
-v `pwd`/test/selenium.robot:/opt/robotframework/tests/selenium.robot:Z \
-v `pwd`/test/timezones.robot:/opt/robotframework/tests/timezones.robot:Z \
-e BROWSER=$BROWSER \
$IMAGE_NAME
- name: Custom User and Group Test
run: |
podman run --user=2000:2000 --shm-size=1g \
-v `pwd`/test/faker.robot:/opt/robotframework/tests/faker.robot:Z \
-v `pwd`/test/requests.robot:/opt/robotframework/tests/requests.robot:Z \
-v `pwd`/test/selenium.robot:/opt/robotframework/tests/selenium.robot:Z \
-v `pwd`/test/timezones.robot:/opt/robotframework/tests/timezones.robot:Z \
-e BROWSER=$BROWSER \
$IMAGE_NAME
- name: Datetime
run: |
podman run --user=2000:2000 --shm-size=1g \
-v `pwd`/test/faker.robot:/opt/robotframework/tests/faker.robot:Z \
-v `pwd`/test/requests.robot:/opt/robotframework/tests/requests.robot:Z \
-v `pwd`/test/selenium.robot:/opt/robotframework/tests/selenium.robot:Z \
-v `pwd`/test/timezones.robot:/opt/robotframework/tests/timezones.robot:Z \
-e BROWSER=$BROWSER \
-e TZ="America/New_York" \
Expand Down
7 changes: 7 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,9 @@ FROM fedora:39
MAINTAINER Paul Podgorsek <ppodgorsek@users.noreply.github.com>
LABEL description Robot Framework in Docker.

# Set the Python dependencies' directory environment variable
ENV ROBOT_DEPENDENCY_DIR /opt/robotframework/dependencies

# Set the reports directory environment variable
ENV ROBOT_REPORTS_DIR /opt/robotframework/reports

Expand Down Expand Up @@ -155,6 +158,10 @@ RUN chmod ugo+w /var/log \
# Update system path
ENV PATH=/opt/robotframework/bin:/opt/robotframework/drivers:$PATH

# Ensure the directory for Python dependencies exists
RUN mkdir -p ${ROBOT_DEPENDENCY_DIR} \
&& chown ${ROBOT_UID}:${ROBOT_GID} ${ROBOT_DEPENDENCY_DIR}

# Set up a volume for the generated reports
VOLUME ${ROBOT_REPORTS_DIR}

Expand Down
23 changes: 23 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
* [Passing additional options](#passing-additional-options)
* [Testing emails](#testing-emails)
* [Dealing with Datetimes and Timezones](#dealing-with-datetimes-and-timezones)
* [Installing additional dependencies](#installing-additional-dependencies)
* [Security consideration](#security-consideration)
* [Continuous integration](#continuous-integration)
* [Defining a test run ID](#defining-a-test-run-id)
Expand Down Expand Up @@ -138,6 +139,28 @@ To set the timezone used inside the Docker image, you can set the `TZ` environme
-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](https://pip.pypa.io/en/stable/reference/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:
Expand Down
11 changes: 11 additions & 0 deletions bin/run-tests-in-virtual-screen.sh
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,17 @@ fi
# Ensure the output folder exists
mkdir -p ${ROBOT_REPORTS_FINAL_DIR}

# Check if additional dependencies should be installed via pip
if [ -e "/opt/robotframework/pip-requirements.txt" ]
then
echo "Installing pip dependencies..."

mkdir -p ${ROBOT_DEPENDENCY_DIR}
pip install -r /opt/robotframework/pip-requirements.txt -t ${ROBOT_DEPENDENCY_DIR}

export PYTHONPATH=${ROBOT_DEPENDENCY_DIR}:${PYTHONPATH}
fi

# No need for the overhead of Pabot if no parallelisation is required
if [ $ROBOT_THREADS -eq 1 ]
then
Expand Down
20 changes: 20 additions & 0 deletions test/pip-dependencies/main.robot
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
# This test scenario was taken from https://github.com/FormulatedAutomation/robotframework-otp

*** Settings ***
Library OTP
Library DateTime

*** Variables ***
${SECRET} base32secret

*** Test Cases ***
Get OTP from secret
${otp}= Get OTP ${SECRET}
Log To Console ${SECRET}
Should Match Regexp ${otp} \\d{6}

Get OTP from secret with time
${timestamp}= Convert Date ${1402481262} epoch
${otp}= Get OTP ${SECRET} ${timestamp}
Should Match Regexp ${otp} \\d{6}
Should Be Equal As Strings ${otp} 055118
2 changes: 2 additions & 0 deletions test/pip-dependencies/requirements.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
pyotp==2.9.0
robotframework-otp==1.1.0

0 comments on commit 569a433

Please sign in to comment.