diff --git a/src/tests_authentik/fixtures_authentik.py b/src/tests_authentik/fixtures_authentik.py new file mode 100644 index 0000000..4a67d49 --- /dev/null +++ b/src/tests_authentik/fixtures_authentik.py @@ -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 diff --git a/src/tests_wordpress/conftest.py b/src/tests_wordpress/conftest.py index 0dd75fc..dcd6fde 100644 --- a/src/tests_wordpress/conftest.py +++ b/src/tests_wordpress/conftest.py @@ -1,28 +1 @@ -# this conftest cannot be executed directly if there is a second conftest -# 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 +from src.tests_authentik.fixtures_authentik import admin_session, user_session diff --git a/src/tests_wordpress/runner_wordpress.py b/src/tests_wordpress/runner_wordpress.py index eddccfa..b0fef11 100644 --- a/src/tests_wordpress/runner_wordpress.py +++ b/src/tests_wordpress/runner_wordpress.py @@ -15,7 +15,6 @@ class RunnerWordpress(Runner): test_dir_name = "tests_wordpress" # main_test_name = "test_wordpress.py" sub_tests = [ - SubTest(condition=condition_always_false, test_file="test_wordpress_feature1.py"), - SubTest(condition=condition_always_true, test_file="conftest.py"), + SubTest(condition=condition_always_true, test_file="test_wordpress_feature1.py"), ] dependencies: list[str] = ["authentik"] diff --git a/src/tests_wordpress/test_wordpress_feature1.py b/src/tests_wordpress/test_wordpress_feature1.py index 865fd93..7f81d8c 100644 --- a/src/tests_wordpress/test_wordpress_feature1.py +++ b/src/tests_wordpress/test_wordpress_feature1.py @@ -1,26 +1,31 @@ import re from icecream import ic -from playwright.sync_api import Page, expect +from playwright.sync_api import BrowserContext, Page, expect -def test_one(config): - ic(config) +def test_demo(admin_session: BrowserContext): + admin_session.new_page() assert 1 + 1 == 2 -def test_has_title(page: Page): - page.goto("https://playwright.dev/") - - # Expect a title "to contain" a substring. - expect(page).to_have_title(re.compile("Playwright")) +# def test_one(config): +# ic(config) +# assert 1 + 1 == 2 -def test_get_started_link(page: Page): - page.goto("https://playwright.dev/") +# def test_has_title(page: Page): +# page.goto("https://playwright.dev/") - # Click the get started link. - page.get_by_role("link", name="Get started").click() +# # Expect a title "to contain" a substring. +# 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()