diff --git a/apps/trading/e2e/README.md b/apps/trading/e2e/README.md index 78cddb358..69585507d 100644 --- a/apps/trading/e2e/README.md +++ b/apps/trading/e2e/README.md @@ -87,10 +87,9 @@ docker build -f docker/node-outside-docker.Dockerfile --build-arg APP=trading -- ## Running Tests 🧪 -Before running make sure the docker daemon is runnign so that the app can be served. +Before running make sure the docker daemon is running. To run a specific test, use the `-k` option followed by the name of the test. - Run all tests: ```bash @@ -109,6 +108,25 @@ Run from anywhere: yarn trading:test -- "test_name" -s --headed ``` +Run using your locally served console: + +Within one terminal + +```bash +yarn nx build trading +``` + +```bash +yarn nx serve trading + +``` + +Once console is served you can use the flag --local-server + +```bash +poetry run pytest -k "test_name" -s --headed --local-server +``` + ## Running Tests in Parallel 🔢 To run tests in parallel, use the `--numprocesses auto` option. The `--dist loadfile` setting ensures that multiple runners are not assigned to a single test file. diff --git a/apps/trading/e2e/conftest.py b/apps/trading/e2e/conftest.py index 2c7434856..573d6f256 100644 --- a/apps/trading/e2e/conftest.py +++ b/apps/trading/e2e/conftest.py @@ -7,7 +7,6 @@ import time import docker import http.server - from contextlib import contextmanager from vega_sim.null_service import VegaServiceNull from playwright.sync_api import Browser, Page @@ -102,11 +101,23 @@ def init_vega(request=None): logger.info(f"Removing container {container.id}") container.remove() + +def pytest_addoption(parser): + parser.addoption( + "--local-server", action="store_true", default=False, + help="Build and serve locally instead of using a container" + ) + +@pytest.fixture(scope="session") +def local_server(pytestconfig): + return pytestconfig.getoption("--local-server") + @contextmanager -def init_page(vega: VegaServiceNull, browser: Browser, request: pytest.FixtureRequest): +def init_page(vega: VegaServiceNull, browser: Browser, request: pytest.FixtureRequest, local_server: bool): + server_port = "4200" if local_server else str(vega.console_port) with browser.new_context( viewport={"width": 1920, "height": 1080}, - base_url=f"http://localhost:{vega.console_port}", + base_url=f"http://localhost:{server_port}", ) as context, context.new_page() as page: context.tracing.start(screenshots=True, snapshots=True, sources=True) try: @@ -115,7 +126,7 @@ def init_page(vega: VegaServiceNull, browser: Browser, request: pytest.FixtureRe while attempts < 100: try: code = requests.get( - f"http://localhost:{vega.console_port}/" + f"http://localhost:{server_port}/" ).status_code if code == 200: break @@ -161,8 +172,8 @@ def vega(request): @pytest.fixture -def page(vega, browser, request): - with init_page(vega, browser, request) as page_instance: +def page(vega, browser, request, local_server): + with init_page(vega, browser, request, local_server) as page_instance: yield page_instance diff --git a/apps/trading/e2e/tests/market/test_market_info.py b/apps/trading/e2e/tests/market/test_market_info.py index 05cf1e229..602f1a0df 100644 --- a/apps/trading/e2e/tests/market/test_market_info.py +++ b/apps/trading/e2e/tests/market/test_market_info.py @@ -17,8 +17,8 @@ def vega(): # setting up everything in this single fixture, as all of the tests need the same setup, so no point in creating separate ones @pytest.fixture(scope="module") -def page(vega, browser, request): - with init_page(vega, browser, request) as page: +def page(vega, browser, request, local_server): + with init_page(vega, browser, request, local_server) as page: setup_continuous_market(vega) risk_accepted_setup(page) page.goto("/") diff --git a/apps/trading/e2e/tests/market/test_markets_no_markets.py b/apps/trading/e2e/tests/market/test_markets_no_markets.py index fd2e2a6f0..c4b08ae1c 100644 --- a/apps/trading/e2e/tests/market/test_markets_no_markets.py +++ b/apps/trading/e2e/tests/market/test_markets_no_markets.py @@ -12,8 +12,8 @@ def vega(request): @pytest.fixture(scope="module") -def page(vega, browser, request): - with init_page(vega, browser, request) as page: +def page(vega, browser, request, local_server): + with init_page(vega, browser, request, local_server) as page: risk_accepted_setup(page) page.goto("/#/markets/all") yield page diff --git a/apps/trading/e2e/tests/navigation/test_navigation.py b/apps/trading/e2e/tests/navigation/test_navigation.py index a4bfa8614..f7016dd3a 100644 --- a/apps/trading/e2e/tests/navigation/test_navigation.py +++ b/apps/trading/e2e/tests/navigation/test_navigation.py @@ -12,8 +12,8 @@ def vega(): # we can reuse single page instance in all tests @pytest.fixture(scope="module") -def page(vega, browser, request): - with init_page(vega, browser, request) as page: +def page(vega, browser, request, local_server): + with init_page(vega, browser, request, local_server) as page: yield page diff --git a/apps/trading/e2e/tests/order/test_order_status.py b/apps/trading/e2e/tests/order/test_order_status.py index 2487c5fe4..fee6fcd16 100644 --- a/apps/trading/e2e/tests/order/test_order_status.py +++ b/apps/trading/e2e/tests/order/test_order_status.py @@ -223,8 +223,8 @@ def markets(vega: VegaService): @pytest.fixture(scope="module") -def page(vega, browser, request): - with init_page(vega, browser, request) as page: +def page(vega, browser, request, local_server): + with init_page(vega, browser, request, local_server) as page: risk_accepted_setup(page) auth_setup(vega, page) page.goto("/")