[WIP] Add new automated test framework (#1)

Co-authored-by: Daniel <d.brummerloh@gmail.com>
Co-committed-by: Daniel <d.brummerloh@gmail.com>
This commit is contained in:
Daniel 2023-11-22 21:40:13 +01:00 committed by dan
parent 859bd57006
commit 97ed87c79f
31 changed files with 769 additions and 6 deletions

View file

@ -0,0 +1,28 @@
# 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

View file

@ -0,0 +1,20 @@
from pathlib import Path
from runner import Runner, SubTest
def condition_always_true(dotenv_path: Path) -> bool:
return True
def condition_always_false(dotenv_path: Path) -> bool:
return False
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"),
]

View file

@ -0,0 +1,29 @@
import re
import pytest
from playwright.sync_api import Page, expect
def test_one():
assert 1 + 1 == 2
def test_two():
assert 2 + 1 == 3
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_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()

View file

@ -0,0 +1,26 @@
import re
from icecream import ic
from playwright.sync_api import Page, expect
def test_one(config):
ic(config)
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_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()

View file

@ -0,0 +1,22 @@
# WIP localization
from playwright.sync_api import Page, expect
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_wordpress(admin_session):
context, page = admin_session
with page.expect_popup() as info:
page.get_by_role("link", name="Wordpress").click()
wordpress = info.value
check_for(wordpress.locator("#wpcontent"))
if CONFIG["locale"] == "de":
check_for(wordpress.get_by_role("heading", name="Willkommen bei WordPress!"))
context.tracing.stop(path=f"{RECORDS}/wordpress.zip")