Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions .gitattributes
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
* text=auto

*.dockerfile text eol=lf
*.sh text eol=lf
108 changes: 89 additions & 19 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ There are three levels of tests in this project:
### Python Unit Tests
Python unit tests are located in `tests/python/` and run with pytest.
```sh
bash scripts/unittests.sh
bash scripts/python-tests.sh
```

### JavaScript Unit Tests
Expand All @@ -32,7 +32,7 @@ npm run test:js
```
Or on Windows:
```
scripts\jstests.bat
scripts\javascript-tests.bat
```
To run in watch mode during development:
```sh
Expand All @@ -54,50 +54,89 @@ All tests run automatically in GitHub Actions. They are triggered through the `.
Results can be found at the `PR > checks > Upload robot logs`.
The check will have a failed status if any tests has failed.

### Running Tests Locally
Perhaps you want to run the tests locally on your PC before pushing and waiting for the results from the GitHub actions. But this requires to install the required components in your native PC. In most cases this will not work as expected bacause of the differemt versions used. E.g. screenshots taken during the tests may differ, so that the tests will fail.
## Running Tests Locally - in a Docker Container
Run the tests locally on your PC before pushing and waiting for the results from the GitHub actions is always a good idea. But this requires to install the required components in your native PC. In some cases this will not work as expected bacause of the differemt versions used. E.g. screenshots taken during the tests may differ, so that the tests might fail.

Using a Docker container to run the tests in avoids both, messing up your local system with installing the required parts for the tests and getting failed tests due to your setup.
Using a Docker container to run the tests in avoids both, messing up your local system with installing the required parts for the tests and getting failed tests due to your setup. You just need to create the respective docker *images* by running the scripts as described below.

> Note: To use this methond there is no need to understand how Docker is working in detail.
> Note: To use this method there is no need to understand how Docker is working in detail.

To run all the tests in the Docker container in the same way as in the GitHub action:
### Python Unit Tests - in Docker Container
To run the python based tests in a docker container, execute:
```bash
bash scripts/run-in-test-container.sh bash scripts/robot-tests.sh
# Linux
bash scripts/docker/run-in-python-container.sh bash scripts/python-tests.sh
# Windows
C:> scripts\docker\run-in-python-container.bat bash scripts/python-tests.sh
```

### JavaScript Unit Tests - in Docker Container
To run the javascript based tests in a docker container, execute:
```bash
# Linux
bash scripts/docker/run-in-js-container.sh bash scripts/javascript-tests.sh
# Windows
C:> scripts\docker\run-in-js-container.bat bash scripts/javascript-tests.sh
```

### Robot Framework End-to-End Tests - in Docker Container
To run all the robot framework end-to-end tests in the Docker container in the same way as in the GitHub action:
```bash
# Linux
bash scripts/docker/run-in-robot-container.sh bash scripts/robot-tests.sh
# Windows
C:> scripts\docker\run-in-robot-container.bat bash scripts/robot-tests.sh
```

To run a individual tests out of a suite:
```bash
bash scripts/run-in-test-container.sh robot -t "*version*" tests/robot/testsuites/00_cli.robot
# Linux
bash scripts/docker/run-in-robot-container.sh robot -t "*version*" tests/robot/testsuites/00_cli.robot
# Windows
C:> scripts\docker\run-in-robot-container.bat robot -t "*version*" tests/robot/testsuites/00_cli.robot
```
To run a single test suite in such a container:
```bash
bash scripts/run-in-test-container.sh robot tests/robot/testsuites/02_overview.robot
# Linux
bash scripts/docker/run-in-robot-container.sh robot tests/robot/testsuites/02_overview.robot
# Windows
C:> scripts\docker\run-in-robot-container.bat robot tests/robot/testsuites/02_overview.robot
```

> Note: It is not required to run any `pip install .` as this will be done by the script within the Docker container.

#### How does it Work
Using the script requires that you are in the top-level directory of your working copy of the git repository. When using the script, the following happens:
Using the scripts require that you are in the top-level directory of your working copy of the git repository. When using the script, the following happens:
- It is launching a new Docker container based on the image created (see below)
- The current working directory is getting mounted to `/robotframework-dashboard` within the container
- In the container the working copy is installed by `pip install .`
- Depending on the script / image you use:
- The python based container contains all the setup required to run the python utit tests.
- The javascript based container contains all the setup of node.js and npm. The dependenies are getting installed automatically by `npm ci`.
- The robot based container contains the setup to run robot framework tests. Your current version of the dashboard from the working directory is installed by `pip install .`
- The arguments you provide are executed as a bash command within the container
- Due to the mounted working directory all the generated results can be accessed directly
- Once the command is completed, the running container is stopped and throw away
- Once the command is completed, the running container is stopped and thrown away

#### Prerequisuites and Setup
Running the tests in a Docker container requires a working docker installation. To check if your system has Docker installed check for the version:
```bash
# Linux
$ docker -v
Docker version 29.3.0, build 5927d80
# Windows
C:> docker -v
Docker version 29.3.1, build c2be9cc
```
If you have no Docker installer yet, follow the instructions to [Install Docker Engine](https://docs.docker.com/engine/install/) depending on your OS. One way is to use the *convenient script*:
If you have no Docker installer yet, follow the instructions to [Install Docker Engine](https://docs.docker.com/engine/install/) depending on your Linux OS. One way is to use the *convenient script*:
```bash
$ curl -fsSL https://get.docker.com -o get-docker.sh
$ sudo sh get-docker.sh
```
If you are running on Windows, follow the instructions in [Install Docker Desktop on Windows](https://docs.docker.com/desktop/setup/install/windows-install/)

Once Docker is available verify if you are allowed to run docker commands.
```bash
# Linux
$ docker ps
permission denied while trying to connect to the docker API at unix:///var/run/docker.sock
```
Expand All @@ -107,21 +146,52 @@ $ sudo usermod -aG docker $USER
```
Don't forget to relogin to make the new group membership effective for your user.

#### Creating the the Docker Image
Once Docker is working you need to generate an *image*. The image can be easily created by:
#### Creating the Docker Images
Once Docker is working you need to generate an *image* for each type of tests (python, javascript, robot framework).
> Note: If you are not familar with docker, imagine an *image* as an ISO image of a Linux live-CD. It is an immutable preconfigured setup of an OS which can be used to run it without installing.

The respective image can be easily created by one of the following:
```bash
$ bash scripts/create-test-image.sh
# Linux
$ bash scripts/docker/create-test-image.sh python
$ bash scripts/docker/create-test-image.sh js
$ bash scripts/docker/create-test-image.sh robot
# Windows
C:> scripts\docker\create-test-image.bat python
C:> scripts\docker\create-test-image.bat js
C:> scripts\docker\create-test-image.bat robot
```
> Note: If you are not familar with docker, imagine an *image* as an ISO image of a Linux live-CD. It is an immutable preconfigured setup of an OS which can be used to run it without installing.

The image is created in the following steps:
##### Image for Python Tests
For the python based one:
- It is based on the public image `ubuntu:latest`, as of writing 24.04 LTS.
- Installs the latest `python3` and `pip` from the distribution
- Installs all the project requirements to perform the tests from `requirements-dev.txt`
- Creates and go into the working directory `/robotframework-dashboard`

##### Image for Javascript Tests
For the javascript based one:
- It is based on the public image `ubuntu:latest`, as of writing 24.04 LTS.
- Installs `curl` and the latest `node.js v24` from the distribution
- Creates and go into the working directory `/robotframework-dashboard`

##### Image for Robot Framework Tests
For the robot framework based one:
- It is based on the public image `mcr.microsoft.com/playwright:v1.56.0-jammy`, a *framework for Web Testing and Automation*.
- which is based on `ubuntu:jammy` (ubuntu 22.04)
- Installs the latest `python3-pip` from the distribution
- Installs all the project requirements to perform the tests from `requirements-test.txt`
- Initializes the `robotframework-browser` library
- Creates a working directory `/robotframework-dashboard`
The image created is being used whenever a new docker container is launched by the `scripts/run-in-test-container.sh`. The image is static. To address changes in the `requirements-test.txt` you can recreate (and replace) the image by running the `create-test-image.sh` once again.

The image created is being used whenever a new docker container is launched by the `scripts/docker/run-in-test-container.sh`. The image is static. To address changes in the `requirements-test.txt` you can recreate (and replace) the image by running the `create-test-image.sh` or `create-test-image.bat` once again. You can also force a complete requild of the image by:
```bash
# Linux
$ bash scripts/docker/create-test-image.sh python --no-cache
# Windows
C:> scripts\docker\create-test-image.bat python --no-cache
```

## 📖 Docs

Expand Down
39 changes: 0 additions & 39 deletions scripts/create-test-image.sh

This file was deleted.

44 changes: 44 additions & 0 deletions scripts/docker/create-test-image.bat
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
@ECHO OFF
REM Creates a docker image to used to run tests locally, without
REM installing all the required tool into your system

SET IMAGE=
IF [%1] == [] GOTO ARGS_MISSING
IF %1 == python SET IMAGE=test-dashboard-python
IF %1 == robot SET IMAGE=test-dashboard-robot
IF %1 == js SET IMAGE=test-dashboard-js
IF [%IMAGE%] == [] GOTO TYPE_UNKNOWN
SET IMAGE_TYPE=%1
SHIFT

REM Check for docker installation
docker -v
IF NOT %ERRORLEVEL% == 0 GOTO DOCKER_NOT_FOUND

REM Start docker container
docker build --tag %IMAGE% -f scripts/docker/%IMAGE%.dockerfile %1 %2 %3 %4 %5 %6 %7 %8 %9 .

REM To run the container in an interactive mode:
REM docker run -it --rm --ipc=host -v.:/robotframework-dashboard test-dashboard-robot
REM Within the container install the current code from the working directory
REM pip install .
REM add the ~/.local/bin to your path
REM export PATH=$PATH:~/.local/bin
REM and run the tests, e.g.
REM robot tests/robot/testsuites/06_filters.robot
GOTO END

:ARGS_MISSING
ECHO Missing argument for container type (robot, python, js) to use
GOTO END

:TYPE_UNKNOWN
ECHO Unknown container type (robot, python, js) to use
GOTO END

:DOCKER_NOT_FOUND
ECHO Make sure that you have installed Docker Desktop on your system (see CONTRIBUTING.md)
GOTO END

:END

29 changes: 29 additions & 0 deletions scripts/docker/create-test-image.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
#!/usr/bin/env bash
#
# Creates a docker image to used to run tests locally, without
# installing all the required tool into your system

die() { echo "FATAL: $*"; exit 1; }

IMAGE=

[ $# -gt 0 ] || die "Missing argument for container type (robot, python, js) to use"
[ "$1" = robot ] && IMAGE=test-dashboard-robot
[ "$1" = python ] && IMAGE=test-dashboard-python
[ "$1" = js ] && IMAGE=test-dashboard-js
[ -n "$IMAGE" ] || die "Unknown container type ($1)"
shift

docker -v || die "docker seems not being installed"

docker build --tag $IMAGE -f scripts/docker/$IMAGE.dockerfile "${@}" .

# To run the container in an interactive mode:
# docker run -it --rm --ipc=host -v.:/robotframework-dashboard --user 1000:1000 test-dashboard-robot
# Within the container install the current code from the working directory
# pip install .
# add the ~/.local/bin to your path
# export PATH=$PATH:~/.local/bin
# and run the tests, e.g.
# robot tests/robot/testsuites/06_filters.robot
#
49 changes: 49 additions & 0 deletions scripts/docker/run-in-container.bat
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
@ECHO OFF

SET IMAGE=
IF [%1] == [] GOTO ARGS_MISSING
IF %1 == python SET IMAGE=test-dashboard-python
IF %1 == robot SET IMAGE=test-dashboard-robot
IF %1 == js SET IMAGE=test-dashboard-js
IF [%IMAGE%] == [] GOTO TYPE_UNKNOWN
SET IMAGE_TYPE=%1
SHIFT

REM Check for docker installation
docker -v
IF NOT %ERRORLEVEL% == 0 GOTO DOCKER_NOT_FOUND

REM Check for docker image
SET FOUND=
FOR /F %%I IN ('docker image ls -q %IMAGE%') DO SET "FOUND=%%I"
IF [%FOUND%] == [] GOTO IMAGE_NOT_FOUND

REM Check for workspace
IF NOT EXIST robotframework_dashboard\robotdashboard.py GOTO WORKSPACE_NOT_FOUND

REM Start docker container
docker run -it --rm --ipc=host -v.:/robotframework-dashboard %IMAGE% %1 %2 %3 %4 %5 %6 %7 %8 %9
GOTO END

:ARGS_MISSING
ECHO Missing argument for container type (robot, python, js) to use
GOTO END

:TYPE_UNKNOWN
ECHO Unknown container type (%1) to use
GOTO END

:IMAGE_NOT_FOUND
ECHO Missing container image %IMAGE%. You need to run scripts\docker\create-test-image.bat %IMAGE_TYPE%
GOTO END

:WORKSPACE_NOT_FOUND
ECHO It looks like that you are not in the top-level workspace directory of the
ECHO robotframework_dashboard repository. Please start this script from there.
GOTO END

:DOCKER_NOT_FOUND
ECHO Make sure that you have installed Docker Desktop on your system (see CONTRIBUTING.md)
GOTO END

:END
24 changes: 24 additions & 0 deletions scripts/docker/run-in-container.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
#!/usr/bin/env bash

die() { echo "FATAL: $*"; exit 1; }
IMAGE=

[ $# -gt 0 ] || die "Missing argument for container type (robot, python, js) to use"
[ $# -gt 1 ] || die "Missing command to run in the container"
[ "$1" = robot ] && IMAGE=test-dashboard-robot
[ "$1" = python ] && IMAGE=test-dashboard-python
[ "$1" = js ] && IMAGE=test-dashboard-js
[ -n "$IMAGE" ] || die "Unknown container type ($1)"
shift

docker -v 2> /dev/null ||
die "Docker seems not being installed"
[ -n "$(docker images -q "$IMAGE" 2> /dev/null)" ] ||
die "Docker image $IMAGE not found, please run 'scripts/docker/create-test-image.sh $1'"
[ -f robotframework_dashboard/robotdashboard.py ] ||
die "you need to start this script from the toplevel directory of the robotframework-dashboard repository"

USER_MAPPING="--user $(id -u):$(id -g)"
[ "$(uname -o)" = Msys ] && USER_MAPPING=""

docker run -it --rm --ipc=host -v"/$(pwd)":/robotframework-dashboard $USER_MAPPING $IMAGE "${@}"
1 change: 1 addition & 0 deletions scripts/docker/run-in-js-container.bat
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
@scripts\docker\run-in-container.bat js bash -c "npm ci; %*"
5 changes: 5 additions & 0 deletions scripts/docker/run-in-js-container.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
#!/usr/bin/env bash

echo "Installing node.js dependencies and running '$*'"

bash scripts/docker/run-in-container.sh js bash -c "npm ci; ${*}"
1 change: 1 addition & 0 deletions scripts/docker/run-in-python-container.bat
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
@scripts\docker\run-in-container.bat python %*
3 changes: 3 additions & 0 deletions scripts/docker/run-in-python-container.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
#!/usr/bin/env bash

bash scripts/docker/run-in-container.sh python "${@}"
3 changes: 3 additions & 0 deletions scripts/docker/run-in-robot-container.bat
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
@ECHO OFF
ECHO Deploying current workingdirectory into the container and running "%*"
scripts\docker\run-in-container.bat robot /bin/bash -c "pip install .; export PATH=$PATH:~/.local/bin; %*"
6 changes: 6 additions & 0 deletions scripts/docker/run-in-robot-container.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
#!/usr/bin/env bash

echo "Deploying current workingdirectory into the container and running"
echo " $*"
echo ""
bash scripts/docker/run-in-container.sh robot /bin/bash -c "pip install .; export PATH=\$PATH:~/.local/bin; ${*}"
Loading
Loading