Skip to content

Commit

Permalink
✨E2E Playwright: add extra headers for all requests (ITISFoundation#5746
Browse files Browse the repository at this point in the history
)
  • Loading branch information
sanderegg authored Apr 26, 2024
1 parent bfcff8c commit df75228
Showing 1 changed file with 31 additions and 7 deletions.
38 changes: 31 additions & 7 deletions tests/e2e-playwright/tests/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
import pytest
from faker import Faker
from playwright.sync_api import APIRequestContext, BrowserContext, Page, WebSocket
from playwright.sync_api._generated import Playwright
from pydantic import AnyUrl, TypeAdapter
from pytest_simcore.logging_utils import log_context
from pytest_simcore.playwright_utils import (
Expand Down Expand Up @@ -75,20 +76,27 @@ def pytest_addoption(parser: pytest.Parser) -> None:
default=None,
help="Service Key",
)
group.addoption(
"--user-agent",
action="store",
type=str,
default="e2e-playwright",
help="defines a specific user agent osparc header",
)


@pytest.fixture(autouse=True)
def osparc_test_id_attribute(playwright):
def osparc_test_id_attribute(playwright: Playwright) -> None:
# Set a custom test id attribute
playwright.selectors.set_test_id_attribute("osparc-test-id")


@pytest.fixture
def api_request_context(context: BrowserContext):
def api_request_context(context: BrowserContext) -> APIRequestContext:
return context.request


@pytest.fixture
@pytest.fixture(scope="session")
def product_url(request: pytest.FixtureRequest) -> AnyUrl:
if passed_product_url := request.config.getoption("--product-url"):
return TypeAdapter(AnyUrl).validate_python(passed_product_url)
Expand Down Expand Up @@ -118,33 +126,49 @@ def user_password(
return os.environ["USER_PASSWORD"]


@pytest.fixture
@pytest.fixture(scope="session")
def product_billable(request: pytest.FixtureRequest) -> bool:
billable = request.config.getoption("--product-billable")
return TypeAdapter(bool).validate_python(billable)


@pytest.fixture
@pytest.fixture(scope="session")
def service_test_id(request: pytest.FixtureRequest) -> str:
if test_id := request.config.getoption("--service-test-id"):
assert isinstance(test_id, str)
return test_id
return os.environ["SERVICE_TEST_ID"]


@pytest.fixture
@pytest.fixture(scope="session")
def service_key(request: pytest.FixtureRequest) -> str:
if key := request.config.getoption("--service-key"):
assert isinstance(key, str)
return key
return os.environ["SERVICE_KEY"]


@pytest.fixture
@pytest.fixture(scope="session")
def auto_register(request: pytest.FixtureRequest) -> bool:
return bool(request.config.getoption("--autoregister"))


@pytest.fixture(scope="session")
def user_agent(request: pytest.FixtureRequest) -> str:
return str(request.config.getoption("--user-agent"))


@pytest.fixture(scope="session")
def browser_context_args(
browser_context_args: dict[str, dict[str, str]], user_agent: str
) -> dict[str, dict[str, str]]:
# Override browser context options, see https://playwright.dev/python/docs/test-runners#fixtures
return {
**browser_context_args,
"extra_http_headers": {"X-Simcore-User-Agent": user_agent},
}


@pytest.fixture
def register(
page: Page,
Expand Down

0 comments on commit df75228

Please sign in to comment.