Skip to content
This repository has been archived by the owner on Apr 24, 2024. It is now read-only.

Commit

Permalink
Suggested review changes
Browse files Browse the repository at this point in the history
4ydan committed Aug 5, 2023
1 parent 26d26cb commit bd2862b
Showing 9 changed files with 34 additions and 49 deletions.
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
@@ -32,7 +32,7 @@ test: test-frontend test-backend test-mdbook test-e2e ## Test everything.
pre-commit

.PHONY: test-e2e
test-e2e: ## End-to-End tests. Needs backend and frontend running.
test-e2e: ## End-to-End tests. Needs install-e2e, backend and frontend running.
cd e2e && ./e2e.sh

.PHONY: test-frontend
4 changes: 2 additions & 2 deletions ci/Jenkinsfile
Original file line number Diff line number Diff line change
@@ -276,9 +276,9 @@ lock("${env.NODE_NAME}-exclusive") {
checkout scm
def e2eImage = docker.build("permaplant-e2e:build", "./e2e")
try {
e2eImage.inside("-e CI=1 -e E2E_URL=http://pr.permaplant.net") {
e2eImage.inside("-e E2E_URL=http://pr.permaplant.net") {
wait_for_pr_db()
sh "make test-e2e"
sh 'make test-e2e'
}
} catch (err) {
echo "Error occurred during the e2eImage.inside block: ${err}"
11 changes: 0 additions & 11 deletions e2e/.env

This file was deleted.

3 changes: 3 additions & 0 deletions e2e/.env.sample
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
E2E_URL=localhost:5173
E2E_USERNAME=Adi
E2E_PASSWORD=1234
38 changes: 18 additions & 20 deletions e2e/README.md
Original file line number Diff line number Diff line change
@@ -1,9 +1,5 @@
# PermaplanT E2E tests

The Jenkins pipeline executes exactly this [Dockerfile](Dockerfile) invoking [e2e.sh](e2e.sh).
It only skips the clean_db.py step, since its not needed in CI.
So running this setup locally should give you fast feedback.

All commands/scripts in this README are executed from this folder (/e2e).

## Directory structure
@@ -17,10 +13,24 @@ All commands/scripts in this README are executed from this folder (/e2e).
├── test-results Screenshots, videos, etc.
```

## Environment Variables

All environment variables are optional, since they have defaults.

- `E2E_URL` (Default: localhost:5173)
The url where the app is running.

- `E2E_USERNAME` (Default: Adi)
The username to login to permaplant.

- `E2E_PASSWORD` (Default: 1234)
The password to login to permaplant.

## Quickstart

Make sure you have a virtual environment or you are inside [.devcontainer](../.devcontainer/README.md).
This will install all dependencies and run e2e tests with these [ENV](.env) variables.
- Make sure your app is running.
- Make sure the [ENV](#environment-variables) variables are set according to your desire.
- Make sure you have a virtual environment as this will install all python dependencies.

```sh
./install.sh
@@ -48,20 +58,8 @@ docker build -t permaplant-e2e .
docker run --network="host" permaplant-e2e ./e2e.sh
```

If you have a more complicated network/database setup you might need to configure all env variables and use `docker run --network`.

Lets say:

- Your app/db are both inside a docker network called `plant`
- The web apps container name is `rudolph`
- The db is at postgres:5433 (for cleaning up after tests)

```sh
docker run --network="plant" -e TEST_URL=rudolph:5173 -e POSTGRES_HOST=postgres -e POSTGRES_PORT=5433 permaplant-e2e
```

There is probably plenty of other setups, we haven't tested all.
Feel free to open an Issue/PR if something is not working.
The Jenkins pipeline performs exactly these two steps.
So running this dockerfile locally should mirror CI.

### Optional arguments

13 changes: 7 additions & 6 deletions e2e/clean_db.py
Original file line number Diff line number Diff line change
@@ -7,14 +7,15 @@
import os
import psycopg2
from dotenv import load_dotenv
from urllib.parse import urlparse

load_dotenv(verbose=True)
load_dotenv()

dbname = str(os.getenv("POSTGRES_DB"))
user = str(os.getenv("POSTGRES_USER"))
password = str(os.getenv("POSTGRES_PASSWORD"))
host = str(os.getenv("POSTGRES_HOST"))
port = str(os.getenv("POSTGRES_PORT"))
dbname = str(os.getenv("POSTGRES_DB", "permaplant"))
user = str(os.getenv("POSTGRES_USER", "permaplant"))
password = str(os.getenv("POSTGRES_PASSWORD", "permaplant"))
host = urlparse(os.environ.get("DATABASE_URL", "postgres://permaplant:permaplant@db/permaplant")).hostname
port = str(os.getenv("DATABASE_PORT", "5432"))


def delete_maps_with_sut(dbname, user, password, host, port):
6 changes: 0 additions & 6 deletions e2e/e2e.sh
Original file line number Diff line number Diff line change
@@ -1,10 +1,4 @@
#!/bin/bash

# Only run clean_db script
# when env variable CI is set
if [ -z "$CI" ]; then
python3 clean_db.py
fi

# Run the pytest command
python3 -m pytest -n auto --retries 2 --video retain-on-failure --html=test-reports/report.html --self-contained-html --cucumberjson=test-reports/cucumber.json
2 changes: 1 addition & 1 deletion e2e/pages/home.py
Original file line number Diff line number Diff line change
@@ -5,7 +5,7 @@

class HomePage(AbstractPage):
"""The homepage permaplant"""
URL = os.getenv("E2E_URL")
URL = os.getenv("E2E_URL", "localhost:5173")
TITLE: str = 'PermaplanT'
HELLO_MSG: str = 'Hello adi'

4 changes: 2 additions & 2 deletions e2e/pages/login.py
Original file line number Diff line number Diff line change
@@ -13,14 +13,14 @@ def __init__(self, page: Page):
self.password_field = page.get_by_label("Password")
self.username_field = page.get_by_label("Username or email")

def fill_username(self, username=os.getenv("E2E_USERNAME")):
def fill_username(self, username=os.getenv("E2E_USERNAME", "Adi")):
"""
Fills the username field.
Default to ENV variable.
"""
self.username_field.fill(username)

def fill_password(self, password=os.getenv("E2E_PASSWORD")):
def fill_password(self, password=os.getenv("E2E_PASSWORD", "1234")):
"""
Fills the password field.
Default to ENV variable.

0 comments on commit bd2862b

Please sign in to comment.