rework-output-and-test-logic (#3)
* fix flakey tests in authentik / wordpress * make it possible to rerun tests partially -> passed will be skipped, failed will be repeated * improve organization of all outputs (moving, renaming, keeping multiple versions etc.) * add html reports, replace .txt tracebacks * combine all html reports into one * add demo runner with comments for documentation purposes Reviewed-on: local-it-infrastructure/e2e_tests#3 Co-authored-by: Daniel <d.brummerloh@gmail.com> Co-committed-by: Daniel <d.brummerloh@gmail.com>
This commit is contained in:
parent
d2cd6ba47f
commit
8172f685de
24 changed files with 588 additions and 418 deletions
|
|
@ -5,18 +5,22 @@ from playwright.sync_api import BrowserContext
|
|||
|
||||
from src.dirmanager import DirManager
|
||||
|
||||
TIMEOUT = 5000
|
||||
|
||||
|
||||
@pytest.fixture
|
||||
def admin_session(context: BrowserContext, DIR: DirManager) -> BrowserContext:
|
||||
def admin_context(context: BrowserContext, DIR: DirManager) -> BrowserContext:
|
||||
state_file = DIR.STATES / "admin_state.json"
|
||||
storage_state = json.loads(state_file.read_bytes())
|
||||
context.add_cookies(storage_state["cookies"])
|
||||
context.set_default_timeout(TIMEOUT)
|
||||
return context
|
||||
|
||||
|
||||
@pytest.fixture
|
||||
def user_session(context: BrowserContext, DIR: DirManager) -> BrowserContext:
|
||||
def user_context(context: BrowserContext, DIR: DirManager) -> BrowserContext:
|
||||
state_file = DIR.STATES / "user_state.json"
|
||||
storage_state = json.loads(state_file.read_bytes())
|
||||
context.add_cookies(storage_state["cookies"])
|
||||
context.set_default_timeout(TIMEOUT)
|
||||
return context
|
||||
|
|
|
|||
|
|
@ -1,15 +1,11 @@
|
|||
from pathlib import Path
|
||||
|
||||
from src.runner import Runner, SubTest
|
||||
|
||||
# from src.tests_authentik.setup_authentik import setup_authentik
|
||||
|
||||
|
||||
def condition_always_true(dotenv_path: Path) -> bool:
|
||||
def condition_always_true(dotenv_config: dict[str, str]) -> bool:
|
||||
return True
|
||||
|
||||
|
||||
def condition_always_false(dotenv_path: Path) -> bool:
|
||||
def condition_always_false(dotenv_config: dict[str, str]) -> bool:
|
||||
return False
|
||||
|
||||
|
||||
|
|
|
|||
|
|
@ -2,7 +2,6 @@ import json
|
|||
import os
|
||||
import re
|
||||
|
||||
from icecream import ic
|
||||
from playwright.sync_api import BrowserContext, expect
|
||||
|
||||
from src.dirmanager import DirManager
|
||||
|
|
@ -10,13 +9,15 @@ from src.dirmanager import DirManager
|
|||
ADMIN_USER = os.environ["ADMIN_USER"]
|
||||
ADMIN_PASS = os.environ["ADMIN_PASS"]
|
||||
|
||||
|
||||
LOCALE = {"Accept-Language": "de_DE"}
|
||||
TESTUSER = {"username": "testuser", "name": "Test User", "password": "test123", "email": "test@example.com"}
|
||||
TIMEOUT = 10000
|
||||
TIMEOUT = 6000
|
||||
|
||||
|
||||
def test_create_admin_login(context: BrowserContext, dotenv_config: dict[str, str], DIR: DirManager):
|
||||
# go to page
|
||||
context.set_extra_http_headers(LOCALE)
|
||||
context.set_default_timeout(TIMEOUT)
|
||||
page = context.new_page()
|
||||
url = "https://" + dotenv_config["DOMAIN"]
|
||||
page.goto(url)
|
||||
|
|
@ -45,8 +46,10 @@ def check_if_user_exists(admin_context: BrowserContext, dotenv_config: dict[str,
|
|||
nav = page.locator("ak-sidebar-item", has_text=re.compile(r"Directory|Verzeichnis"))
|
||||
nav.click()
|
||||
nav.get_by_role("link", name=re.compile(r"Users|Benutzer")).click()
|
||||
result = page.get_by_text(TESTUSER["username"]).is_visible(timeout=TIMEOUT)
|
||||
return result
|
||||
|
||||
user = page.get_by_text(TESTUSER["username"])
|
||||
user.wait_for(state="visible")
|
||||
return user.is_visible()
|
||||
|
||||
|
||||
def create_invite_link(admin_context: BrowserContext, dotenv_config: dict[str, str]):
|
||||
|
|
@ -100,6 +103,7 @@ def create_user(user_context: BrowserContext, invitelink):
|
|||
|
||||
|
||||
def test_create_user_session(context: BrowserContext, dotenv_config: dict[str, str], DIR: DirManager):
|
||||
context.set_extra_http_headers(LOCALE)
|
||||
context.set_default_timeout(TIMEOUT)
|
||||
|
||||
# load admin cookies
|
||||
|
|
|
|||
|
|
@ -1,179 +0,0 @@
|
|||
## this file will not be used later
|
||||
## split into
|
||||
# -> setup.setup_authentic.py
|
||||
# and
|
||||
# -> tests
|
||||
|
||||
import pytest
|
||||
from icecream import ic
|
||||
from playwright.sync_api import Browser, Locator, expect
|
||||
|
||||
# playwright = sync_playwright().start()
|
||||
# browser = playwright.chromium.launch(headless=False)
|
||||
|
||||
|
||||
testuser = {"username": "testuser", "name": "Test User", "password": "test123", "email": "test@example.com"}
|
||||
|
||||
|
||||
TIMEOUT = 5000
|
||||
|
||||
|
||||
def check_for(locator: Locator):
|
||||
expect(locator).to_be_visible(timeout=TIMEOUT)
|
||||
|
||||
|
||||
def setup_context(browser, state_file=None):
|
||||
if state_file:
|
||||
context = browser.new_context(storage_state=state_file)
|
||||
else:
|
||||
context = browser.new_context()
|
||||
context.set_default_timeout(TIMEOUT)
|
||||
return context
|
||||
|
||||
|
||||
""" Test Authentik Login and DE Locale """
|
||||
|
||||
|
||||
@pytest.fixture(scope="session", autouse=True)
|
||||
def admin_login(browser: Browser, dotenv_config, STATES):
|
||||
# ic(dotenv_config)
|
||||
CONFIG = dotenv_config
|
||||
context = setup_context(browser)
|
||||
page = context.new_page()
|
||||
url = "https://" + CONFIG["DOMAIN"]
|
||||
ic(url)
|
||||
page.goto(url)
|
||||
welcome_message = CONFIG.get("welcome_message")
|
||||
if welcome_message:
|
||||
check_for(page.get_by_text(welcome_message))
|
||||
if CONFIG["locale"] == "de":
|
||||
check_for(page.get_by_text("Benutzername oder Passwort vergessen?"))
|
||||
check_for(page.get_by_text("E-Mail or Anmeldename"))
|
||||
check_for(page.get_by_text("Passwort", exact=True))
|
||||
page.locator('input[name="uidField"]').fill(CONFIG["admin"])
|
||||
page.locator('ak-stage-identification input[name="password"]').fill(CONFIG["admin_pw"])
|
||||
page.get_by_role("button", name="Log In").click()
|
||||
check_for(page.locator("ak-library"))
|
||||
if CONFIG["locale"] == "de":
|
||||
check_for(page.get_by_text("Meine Anwendungen"))
|
||||
context.storage_state(path=f"{STATES}/admin_state.json")
|
||||
page.close()
|
||||
context.close()
|
||||
|
||||
|
||||
""" Create User """
|
||||
|
||||
|
||||
@pytest.fixture(scope="session", autouse=True)
|
||||
def init_create_user(browser: Browser, dotenv_config, STATES):
|
||||
admin_context = setup_context(browser, f"{STATES}/admin_state.json")
|
||||
admin_page = admin_context.new_page()
|
||||
invitelink = create_invite_link(admin_page, dotenv_config)
|
||||
admin_context.close()
|
||||
user_context = setup_context(browser)
|
||||
create_user(user_context, invitelink)
|
||||
user_context.close()
|
||||
|
||||
|
||||
""" Delete User """
|
||||
|
||||
|
||||
@pytest.fixture(scope="session", autouse=True)
|
||||
def post_delete_user(browser: Browser, dotenv_config, RECORDS, STATES):
|
||||
yield
|
||||
context = browser.new_context(storage_state=f"{STATES}/admin_state.json")
|
||||
context.tracing.start(screenshots=True, snapshots=True, sources=True)
|
||||
context.set_default_timeout(TIMEOUT)
|
||||
page = context.new_page()
|
||||
# delete_nextcloud_user(page)
|
||||
delete_authentik_user(page, dotenv_config)
|
||||
context.tracing.stop(path=f"{RECORDS}/delete_user.zip")
|
||||
|
||||
|
||||
""" Create Invite Link """
|
||||
|
||||
|
||||
def create_invite_link(page, dotenv_config):
|
||||
CONFIG = dotenv_config
|
||||
page.goto(CONFIG["domain"])
|
||||
page.get_by_role("link", name="Admin Interface").click()
|
||||
page.get_by_text("Verzeichnis").click()
|
||||
page.get_by_text("Benutzer").nth(2).click()
|
||||
page.get_by_text("Einladungen").click()
|
||||
page.get_by_role("button", name="Erstellen").first.click()
|
||||
page.locator('input[name="name"]').click()
|
||||
linkname = "testlink9433"
|
||||
page.locator('input[name="name"]').fill(linkname)
|
||||
page.get_by_placeholder("Wählen Sie ein Objekt aus.").click()
|
||||
page.get_by_role("option", name="invitation-enrollment-flow invitation-enrollment-flow").click()
|
||||
page.get_by_text("Erstellen", exact=True).first.click()
|
||||
linklocator = page.get_by_role("rowgroup").filter(has=page.get_by_text(linkname))
|
||||
linklocator.locator(".fa-angle-down").click()
|
||||
invitelink = linklocator.get_by_role("textbox").get_attribute(name="value")
|
||||
return invitelink
|
||||
|
||||
|
||||
""" Create User from invitelink """
|
||||
|
||||
|
||||
def create_user(context, invitelink, STATES):
|
||||
page = context.new_page()
|
||||
page.goto(invitelink)
|
||||
page.get_by_placeholder("Benutzername").click()
|
||||
page.get_by_placeholder("Benutzername").fill(testuser["username"])
|
||||
page.locator('input[name="name"]').click()
|
||||
page.locator('input[name="name"]').fill(testuser["name"])
|
||||
page.locator('input[name="email"]').click()
|
||||
page.locator('input[name="email"]').fill(testuser["email"])
|
||||
page.get_by_placeholder("Passwort", exact=True).click()
|
||||
page.get_by_placeholder("Passwort", exact=True).fill(testuser["password"])
|
||||
page.get_by_placeholder("Passwort (wiederholen)").click()
|
||||
page.get_by_placeholder("Passwort (wiederholen)").fill(testuser["password"])
|
||||
page.get_by_role("button", name="Weiter").click()
|
||||
check_for(page.locator("ak-library"))
|
||||
context.storage_state(path=f"{STATES}/user_state.json")
|
||||
|
||||
|
||||
""" Delete Authentik Account """
|
||||
|
||||
|
||||
def delete_authentik_user(page, dotenv_config):
|
||||
CONFIG = dotenv_config
|
||||
page.goto(CONFIG["domain"])
|
||||
page.get_by_role("link", name="Admin Interface").click()
|
||||
page.get_by_text("Verzeichnis").click()
|
||||
page.get_by_text("Benutzer").nth(2).click()
|
||||
page.get_by_role("row").filter(has=page.get_by_text(testuser["username"])).get_by_role("checkbox").click()
|
||||
page.get_by_role("button", name="Löschen").click()
|
||||
page.get_by_role("dialog").get_by_role("button", name="Löschen").click()
|
||||
check_for(page.get_by_text("1 Benutzer erfolgreich gelöscht"))
|
||||
|
||||
|
||||
""" Reuse Authentik Admin Session """
|
||||
|
||||
|
||||
@pytest.fixture
|
||||
def admin_session(browser: Browser, dotenv_config, STATES):
|
||||
CONFIG = dotenv_config
|
||||
context = setup_context(browser, f"{STATES}/admin_state.json")
|
||||
page = context.new_page()
|
||||
page.goto(CONFIG["domain"])
|
||||
yield context, page
|
||||
context.close()
|
||||
|
||||
|
||||
""" Reuse Authentik User Session """
|
||||
|
||||
|
||||
@pytest.fixture
|
||||
def user_session(browser: Browser, dotenv_config, STATES):
|
||||
CONFIG = dotenv_config
|
||||
context = setup_context(browser, f"{STATES}/user_state.json")
|
||||
page = context.new_page()
|
||||
page.goto(CONFIG["domain"])
|
||||
yield context, page
|
||||
context.close()
|
||||
|
||||
|
||||
def test_true():
|
||||
assert 1 + 1 == 2
|
||||
Loading…
Add table
Add a link
Reference in a new issue