Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Research: run Playwright tests based on marker #2559

Closed
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions tests/playwright/pytest.ini
Original file line number Diff line number Diff line change
@@ -1,2 +1,6 @@
[pytest]
addopts = --tracing on -v --template=html1/index.html --report=test-results/report.html --video on
markers =
dev
test
prod
85 changes: 83 additions & 2 deletions tests/playwright/test_healthcheck.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,88 @@
from playwright.sync_api import Page, expect
import pytest


def test_dev_healthcheck(page: Page):
page.goto("https://dev-benefits.calitp.org/healthcheck")
@pytest.fixture
def env_base_url(request):
marker = (
request.node.get_closest_marker("dev")
or request.node.get_closest_marker("test")
or request.node.get_closest_marker("prod")
)
print(marker)

if marker:
env = marker.name
else:
env = None

if env == "dev":
return "https://dev-benefits.calitp.org"
elif env == "test":
return "https://test-benefits.calitp.org"
elif env == "prod":
return "http://dev-benefits.calitp.org" # use dev for now, don't want to spam prod
else:
return "http://localhost:11369" # use port that will work with IdG


# region --- Test that needs to run for multiple environments


# region helper function
def env(*marks):
return pytest.mark.parametrize("env_name", [pytest.param(mark.name, marks=mark) for mark in marks])


# endregion


# this is what the helper function evaluates to
# @pytest.mark.parametrize(
# "env_name",
# [
# pytest.param("dev", marks=[pytest.mark.dev]),
# pytest.param("test", marks=[pytest.mark.test]),
# pytest.param("prod", marks=[pytest.mark.prod]),
# ],
# )
@env(pytest.mark.dev, pytest.mark.test, pytest.mark.prod)
def test_healthcheck(page: Page, env_base_url, env_name):
page.goto(env_base_url + "/healthcheck")

expect(page.get_by_text("Healthy")).to_be_visible()


# endregion


# region--- Test that needs to run for multiple environments with parametrized values


@pytest.mark.parametrize(
"sub,name",
[
pytest.param("12345", "Example", marks=[pytest.mark.dev]),
pytest.param("1234", "Le", marks=[pytest.mark.dev]),
pytest.param("4321", "Garcia", marks=[pytest.mark.test]),
pytest.param("54321", "Sample", marks=[pytest.mark.prod]),
],
)
def test_agency_card_flow(page, env_base_url, sub, name):
print(env_base_url)
print(sub)
print(name)


# endregion


# region --- Test specific to only one environment that does not need parameterization, can use mark more simply


@pytest.mark.dev
def test_only_for_dev(env_base_url):
print(env_base_url)


# endregion
Loading