Skip to content

Commit

Permalink
feat: add tests, build and push
Browse files Browse the repository at this point in the history
  • Loading branch information
f-necas committed Feb 4, 2025
1 parent 7262e2d commit 336e6e3
Show file tree
Hide file tree
Showing 20 changed files with 374 additions and 136 deletions.
Original file line number Diff line number Diff line change
@@ -1,9 +1,14 @@
name: Playwright Tests
name: Execute tests on georchestra/docker:master
on:
push:
branches: [ main, master ]
pull_request:
branches: [ main, master ]
schedule:
- cron: "0 4 * * 1"

permissions: write-all

jobs:
test:
timeout-minutes: 60
Expand All @@ -12,6 +17,9 @@ jobs:
- uses: actions/checkout@v4
with:
path: tests
- name: Add hosts to /etc/hosts
run: |
sudo echo "127.0.0.1 georchestra-127-0-0-1.nip.io" | sudo tee -a /etc/hosts
- name: Set up Python
uses: actions/setup-python@v4
with:
Expand All @@ -30,14 +38,17 @@ jobs:
with:
repository: georchestra/docker
submodules: 'recursive'
ref: 'rbmq-limited'
ref: 'data-api-24'
path: 'docker'

- name: Launch docker-compose
run: |
cd docker
docker compose up -d --wait --quiet-pull
cd ..
echo "Trigger GN wro4j..."
curl -k https://georchestra-127-0-0-1.nip.io/geonetwork/srv/eng/catalog.search
- name: Caddy trust
run: |
Expand All @@ -46,7 +57,11 @@ jobs:
./caddy trust
- name: Run your tests
run: pytest tests --tracing=retain-on-failure --alluredir=allure-results
run: |
cd ./tests
pwd
pytest tests --tracing=retain-on-failure --alluredir=allure-results --base-url=https://georchestra-127-0-0-1.nip.io --reruns=1
cd ..
- name: Load test report history
uses: actions/checkout@v3
Expand All @@ -60,9 +75,8 @@ jobs:
uses: simple-elf/[email protected]
if: always()
with:
gh_pages: gh-pages
allure_history: allure-history
allure_results: allure-results
allure_results: tests/allure-results
keep_reports: 5

- name: Publish test report
uses: peaceiris/actions-gh-pages@v3
Expand All @@ -71,9 +85,10 @@ jobs:
github_token: ${{ secrets.GITHUB_TOKEN }}
publish_branch: gh-pages
publish_dir: allure-history
force_orphan: true

- uses: actions/upload-artifact@v4
if: ${{ !cancelled() }}
with:
name: playwright-traces
path: test-results/
path: test-results/
41 changes: 41 additions & 0 deletions .github/workflows/push-to-docker-hub.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
name: Push on docker hub
on:
push:
branches: [ main, master ]
pull_request:
branches: [ main, master ]

jobs:
build:
if: "!startsWith(github.event.head_commit.message, '[skip ci] ')"
runs-on: ubuntu-latest
timeout-minutes: 15
steps:
- name: "Checking out"
uses: actions/checkout@v4

- name: "Building docker image"
if: github.repository == 'georchestra/e2e-tests'
run: |
docker build -t georchestra/e2e-tests:latest .
- name: "Logging in docker.io"
if: github.repository == 'georchestra/e2e-tests' && github.actor != 'dependabot[bot]' && github.event_name != 'pull_request'
uses: azure/docker-login@v1
with:
username: '${{ secrets.DOCKER_HUB_USERNAME }}'
password: '${{ secrets.DOCKER_HUB_PASSWORD }}'

- name: "Update Docker Hub Description"
uses: peter-evans/dockerhub-description@v3
with:
username: ${{ secrets.DOCKER_HUB_USERNAME }}
password: ${{ secrets.DOCKER_HUB_PASSWORD }}
repository: georchestra/e2e-tests
readme-filepath: ./DOCKER_HUB.md
short-description: 'End to end tests for the geOrchestra SDI'

- name: "Pushing latest to docker.io"
if: github.ref == 'refs/heads/main' && github.repository == 'georchestra/e2e-tests'
run: |
docker push georchestra/e2e-tests:latest
52 changes: 52 additions & 0 deletions DOCKER_HUB.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
# Quick reference

- **Maintained by**:
[georchestra.org](https://www.georchestra.org/)

- **Where to get help**:
the [geOrchestra Github repo](https://github.com/georchestra/georchestra), [IRC chat](https://matrix.to/#/#georchestra:osgeo.org), Stack Overflow

# Featured tags

- `latest`

# Quick reference

- **Where to file issues**:
[https://github.com/georchestra/georchestra/issues](https://github.com/georchestra/e2e-tests/issues)

- **Supported architectures**:
[`amd64`](https://hub.docker.com/r/amd64/docker/)

- **Source of this description**:
[docs repo's directory](https://github.com/georchestra/e2e-tests/blob/main/DOCKER_HUB.md)

# What is `georchestra/e2e-tests` ?

This project contains automated tests for the geOrchestra web applications using Playwright and pytest.

A [complete description](https://github.com/georchestra/e2e-tests/blob/main/console/README.md) is available on github .

# How to use base image and run specific tests

Create a folder where you put your specific tests and create a Dockerfile with the following content:

```Dockerfile
FROM georchestra/e2e-tests:latest

COPY mytests /app/tests/mytests
```

## Where is it built

This image is built using Dockerfile in [docs repo's directory](https://github.com/georchestra/e2e-tests/blob/main/Dockerfile)

# License

View [license information](https://www.georchestra.org/software.html) for the software contained in this image.

As with all Docker images, these likely also contain other software which may be under other licenses (such as Bash, etc from the base distribution, along with any direct or indirect dependencies of the primary software being contained).

[//]: # (Some additional license information which was able to be auto-detected might be found in [the `repo-info` repository's georchestra/ directory]().)

As for any docker image, it is the user's responsibility to ensure that usages of this image comply with any relevant licenses for all software contained within.
10 changes: 10 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
FROM python:3-slim
ENV BASE_URL=https://georchestra-127-0-0-1.nip.io

COPY . /app

WORKDIR /app
RUN pip install -r requirements.txt
RUN python -m playwright install --with-deps

ENTRYPOINT pytest --base-url=$BASE_URL
33 changes: 27 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,12 +1,10 @@
# geOrchestra Playwright Tests

This project contains automated tests for the geOrchestra web applications using Playwright and pytest.
![build-and-tests](https://github.com/georchestra/e2e-tests/actions/workflows/build-and-tests.yml/badge.svg)

## Project Structure
Report : https://www.georchestra.org/e2e-tests

- `tests/`: Contains the test files.
- `conftest.py`: Configuration file for pytest fixtures.
- `.github/workflows/playwright.yml`: GitHub Actions workflow for running the tests.
This project contains automated tests for the geOrchestra web applications using Playwright and pytest.

## Prerequisites

Expand All @@ -19,7 +17,7 @@ This project contains automated tests for the geOrchestra web applications using
1. Install the dependencies:
```sh
python -m pip install --upgrade pip
pip install -r tests/requirements.txt
pip install -r requirements.txt
```

2. Ensure Playwright browsers are installed:
Expand All @@ -37,6 +35,19 @@ This project contains automated tests for the geOrchestra web applications using
chmod +x caddy
./caddy trust
```
4. Change base url in `pytest.ini` file to match your local geOrchestra instance:
```ini
[pytest]
addopts = --base-url=https://georchestra-127-0-0-1.nip.io
```
## Help to generate a test
To help generate a new test, you can use the following command:
```sh
python -m playwright codegen https://<your-sdi>
```
It will open a browser and you can interact with the website. At the end, it will generate a Python script with the interactions you made.
## Running Tests
Expand All @@ -53,3 +64,13 @@ To generate the allure report, use the following command:
```sh
allure serve allure-results
```
## How to use base image and run specific tests
Create a folder where you put your specific tests and create a Dockerfile with the following content:
```Dockerfile
FROM georchestra/e2e-tests:latest
COPY mytests /app/tests/mytests
```
Binary file added fixtures/antenne.zip
Binary file not shown.
Empty file added helper/__init__.py
Empty file.
22 changes: 22 additions & 0 deletions helper/configuration_manager.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
import yaml
import os

def path_from_project_root(file_path: str) -> str:
_root_dir = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
return _root_dir + '/' + file_path

class ConfigurationManager:
with open(path_from_project_root('resources/config.yaml'), 'rb') as __config_file:
__configs = yaml.load(__config_file, Loader=yaml.FullLoader)

@staticmethod
def __config() -> dict:
return ConfigurationManager.__configs

@staticmethod
def local_admin() -> dict:
return ConfigurationManager.__configs['local.account']

@staticmethod
def write_tests_disabled() -> bool:
return ConfigurationManager.__configs['write_tests_disabled'] == 'true'
2 changes: 2 additions & 0 deletions pytest.ini
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
[pytest]
addopts = --base-url=https://georchestra-127-0-0-1.nip.io --reruns=1
4 changes: 3 additions & 1 deletion requirements.txt
Original file line number Diff line number Diff line change
@@ -1,2 +1,4 @@
allure-pytest
pytest-playwright
pytest-playwright
pyyaml
pytest-rerunfailures
Empty file added resources/__init__.py
Empty file.
4 changes: 4 additions & 0 deletions resources/config.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
local.account:
username: 'testadmin'
password: 'testadmin'
write_tests_disabled: 'false'
Empty file added tests/__init__.py
Empty file.
21 changes: 20 additions & 1 deletion tests/common.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,28 @@
import allure
from playwright.sync_api import Page

from helper.configuration_manager import ConfigurationManager



def screenshot_page(page, name):
png_bytes = page.screenshot()
allure.attach(
png_bytes,
name=name,
attachment_type=allure.attachment_type.PNG
)
)

def login(page: Page, cas: bool = False):
page.goto("/datahub/")
page.get_by_role("link", name="login").click()
username_input = page.get_by_placeholder("Username")
if cas:
username_input = page.locator("#username")
username_input.fill(ConfigurationManager.local_admin()["username"])
username_input.press("Tab")
password_input = page.get_by_placeholder("Password")
if cas:
password_input = page.locator("#password")
password_input.fill(ConfigurationManager.local_admin()["password"])
password_input.press("Enter")
Empty file added tests/console/__init__.py
Empty file.
Empty file.
31 changes: 31 additions & 0 deletions tests/georchestra-base/test_01_check_apps_init.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
import os
import allure

from playwright.sync_api import Page, expect

from tests.common import screenshot_page, login
import pytest


@allure.epic("Web interface")
@allure.feature("geOrchestra")
@allure.story("GeoNetwork")
@allure.description("This test attempts to load every GeoNetwork wro4j.")
@allure.title("Test the GeoNetwork webapp")
@pytest.mark.flaky(reruns=5)
def test_geo_network_webapp(page: Page):
login(page)
#Search page
page.goto("/geonetwork/srv/eng/catalog.search")
expect(page.get_by_role("combobox", name="Search")).to_be_visible(timeout=20000)
screenshot_page(page,"geonetwork search")
#Editor page
page.goto("/geonetwork/srv/eng/catalog.edit#/board?from=1&to=30")
expect(page.get_by_role("link", name="+ Add new record")).to_be_visible(timeout=20000)
screenshot_page(page,"geonetwork editor")
#admin page
page.goto("/geonetwork/srv/eng/admin.console#/home")
expect(page.locator("body")).to_contain_text(expected="Harvesting", timeout=20000)
screenshot_page(page,"geonetwork admin")


Loading

0 comments on commit 336e6e3

Please sign in to comment.