use fixture from authentik in wordpress

This commit is contained in:
Daniel 2023-11-24 20:58:23 +01:00
parent c9844bc688
commit 050be3709f
4 changed files with 42 additions and 44 deletions

View file

@ -0,0 +1,21 @@
import json
from pathlib import Path
import pytest
from playwright.sync_api import BrowserContext
@pytest.fixture
def admin_session(context: BrowserContext, STATES: Path) -> BrowserContext:
state_file = STATES / "admin_state.json"
storage_state = json.loads(state_file.read_bytes())
context.add_cookies(storage_state["cookies"])
return context
@pytest.fixture
def user_session(context: BrowserContext, STATES: Path) -> BrowserContext:
state_file = STATES / "user_state.json"
storage_state = json.loads(state_file.read_bytes())
context.add_cookies(storage_state["cookies"])
return context

View file

@ -1,28 +1 @@
# this conftest cannot be executed directly if there is a second conftest from src.tests_authentik.fixtures_authentik import admin_session, user_session
# on a higher level. might work if other tests are executed though
# -> at least bad for debugging
import json
from pathlib import Path
import pytest
from playwright.sync_api import Browser, Locator, expect, sync_playwright
# playwright = sync_playwright().start()
# browser = playwright.chromium.launch(headless=False)
cred_file = Path("credentials.json")
with open(cred_file, "r") as f:
CREDENTIALS = json.load(f)
print(CREDENTIALS)
RECORDS = Path("records")
RECORDS.mkdir(exist_ok=True)
STATES = Path("states")
STATES.mkdir(exist_ok=True)
def test_dummy():
assert 1 + 1 == 2

View file

@ -15,7 +15,6 @@ class RunnerWordpress(Runner):
test_dir_name = "tests_wordpress" test_dir_name = "tests_wordpress"
# main_test_name = "test_wordpress.py" # main_test_name = "test_wordpress.py"
sub_tests = [ sub_tests = [
SubTest(condition=condition_always_false, test_file="test_wordpress_feature1.py"), SubTest(condition=condition_always_true, test_file="test_wordpress_feature1.py"),
SubTest(condition=condition_always_true, test_file="conftest.py"),
] ]
dependencies: list[str] = ["authentik"] dependencies: list[str] = ["authentik"]

View file

@ -1,26 +1,31 @@
import re import re
from icecream import ic from icecream import ic
from playwright.sync_api import Page, expect from playwright.sync_api import BrowserContext, Page, expect
def test_one(config): def test_demo(admin_session: BrowserContext):
ic(config) admin_session.new_page()
assert 1 + 1 == 2 assert 1 + 1 == 2
def test_has_title(page: Page): # def test_one(config):
page.goto("https://playwright.dev/") # ic(config)
# assert 1 + 1 == 2
# Expect a title "to contain" a substring.
expect(page).to_have_title(re.compile("Playwright"))
def test_get_started_link(page: Page): # def test_has_title(page: Page):
page.goto("https://playwright.dev/") # page.goto("https://playwright.dev/")
# Click the get started link. # # Expect a title "to contain" a substring.
page.get_by_role("link", name="Get started").click() # expect(page).to_have_title(re.compile("Playwright"))
# Expects page to have a heading with the name of Installation.
expect(page.get_by_role("heading", name="Installation")).to_be_visible() # def test_get_started_link(page: Page):
# page.goto("https://playwright.dev/")
# # Click the get started link.
# page.get_by_role("link", name="Get started").click()
# # Expects page to have a heading with the name of Installation.
# expect(page.get_by_role("heading", name="Installation")).to_be_visible()