88 lines
3.6 KiB
Python
88 lines
3.6 KiB
Python
import json
|
|
from pathlib import Path
|
|
|
|
from icecream import ic
|
|
from playwright.sync_api import Browser, BrowserContext, expect
|
|
|
|
cred_file = Path("credentials.json")
|
|
with open(cred_file, "r") as f:
|
|
CREDENTIALS = json.load(f)
|
|
|
|
ic("RUNNING SETUP")
|
|
ic(CREDENTIALS)
|
|
|
|
TESTUSER = {"username": "testuser", "name": "Test User", "password": "test123", "email": "test@example.com"}
|
|
TIMEOUT = 5000
|
|
|
|
|
|
def test_create_admin_login(context: BrowserContext, dotenv_config: dict[str, str], STATES: Path):
|
|
# go to page
|
|
page = context.new_page()
|
|
url = "https://" + dotenv_config["DOMAIN"]
|
|
page.goto(url)
|
|
|
|
# check welcome message
|
|
welcome_message = dotenv_config.get("welcome_message")
|
|
if welcome_message:
|
|
expect(page.get_by_text(welcome_message)).to_be_visible(timeout=TIMEOUT)
|
|
|
|
# login
|
|
page.locator('input[name="uidField"]').fill(CREDENTIALS["admin"])
|
|
page.locator('ak-stage-identification input[name="password"]').fill(CREDENTIALS["admin_pw"])
|
|
page.get_by_role("button", name="Log In").click()
|
|
expect(page.locator("ak-library")).to_be_visible(timeout=TIMEOUT)
|
|
|
|
# save state
|
|
context.storage_state(path=f"{STATES}/admin_state.json")
|
|
|
|
|
|
def create_invite_link(admin_context: BrowserContext, dotenv_config: dict[str, str]):
|
|
page = admin_context.new_page()
|
|
url = "https://" + dotenv_config["DOMAIN"]
|
|
page.goto(url)
|
|
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
|
|
|
|
|
|
def create_user(context: BrowserContext, invitelink, STATES: Path):
|
|
# warning: only works on german site
|
|
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()
|
|
expect(page.locator("ak-library")).to_be_visible()
|
|
|
|
|
|
def test_create_user_session(browser: Browser, dotenv_config: dict[str, str], STATES: Path):
|
|
# create invite_link
|
|
admin_context = browser.new_context(storage_state=f"{STATES}/admin_state.json")
|
|
admin_context.set_default_timeout(TIMEOUT)
|
|
invite_link = create_invite_link(admin_context, dotenv_config)
|
|
|
|
# create user
|
|
user_context = browser.new_context()
|
|
user_context.set_default_timeout(TIMEOUT)
|
|
create_user(user_context, invite_link, STATES)
|
|
user_context.storage_state(path=f"{STATES}/user_state.json")
|