use fixture from authentik in wordpress
This commit is contained in:
parent
c9844bc688
commit
050be3709f
4 changed files with 42 additions and 44 deletions
21
src/tests_authentik/fixtures_authentik.py
Normal file
21
src/tests_authentik/fixtures_authentik.py
Normal 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
|
||||
|
|
@ -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
|
||||
|
|
|
|||
|
|
@ -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"]
|
||||
|
|
|
|||
|
|
@ -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()
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue