From 248fba279f1d3f7e4bcb738ed35c2fad1c9ef0d8 Mon Sep 17 00:00:00 2001 From: Odei Maiz <33152403+odeimaiz@users.noreply.github.com> Date: Mon, 12 Aug 2024 13:32:12 +0200 Subject: [PATCH] e2e: Sim4Life uses plus button (#6167) Co-authored-by: sanderegg <35365065+sanderegg@users.noreply.github.com> --- tests/e2e-playwright/Makefile | 16 +++++++---- tests/e2e-playwright/tests/conftest.py | 28 +++++++++++++++++++ .../e2e-playwright/tests/sim4life/conftest.py | 12 ++++++++ .../tests/sim4life/test_sim4life.py | 13 ++++++--- 4 files changed, 60 insertions(+), 9 deletions(-) diff --git a/tests/e2e-playwright/Makefile b/tests/e2e-playwright/Makefile index f0ccd4322c0..af4a8d48538 100644 --- a/tests/e2e-playwright/Makefile +++ b/tests/e2e-playwright/Makefile @@ -131,27 +131,33 @@ $(SLEEPERS_INPUT_FILE) $(JUPYTER_LAB_INPUT_FILE) $(CLASSIC_TIP_INPUT_FILE) $(S4L read -p "Enter the size of the large file (human readable form e.g. 3Gib): " LARGE_FILE_SIZE; \ echo "--service-key=jupyter-math --large-file-size=$$LARGE_FILE_SIZE" >> $@; \ elif [ "$@" = "$(S4L_INPUT_FILE)" ]; then \ - echo "--service-key=sim4life-8-0-0-dy" >> $@; \ + echo "--plus_button_test_id=startS4LButton" >> $@; \ read -p "Do you want to check the videostreaming ? (requires to run with chrome/msedge) [y/n]: " VIDEOSTREAM; \ if [ "$$VIDEOSTREAM" = "y" ]; then \ echo "--check-videostreaming" >> $@; \ fi; \ + read -p "Do you want to use the plus button (NOTE: if yes then pass the osparc-test-ID of the plus button in the service key) ? [y/n]: " PLUS_BUTTON; \ + if [ "$$PLUS_BUTTON" = "y" ]; then \ + echo "--use-plus-button" >> $@; \ + fi; \ + read -p "Enter the service key: " SERVICE_KEY; \ + echo "--service-key=$$SERVICE_KEY" >> $@; \ elif [ "$@" = "$(SLEEPERS_INPUT_FILE)" ]; then \ read -p "Enter the number of sleepers: " NUM_SLEEPERS; \ echo "--num-sleepers=$$NUM_SLEEPERS" >> $@; \ fi # Run the tests -test-sleepers-anywhere: _check_venv_active $(SLEEPERS_INPUT_FILE) +test-sleepers-anywhere: _check_venv_active $(SLEEPERS_INPUT_FILE) ## run sleepers test and cache settings @$(call run_test, $(SLEEPERS_INPUT_FILE), tests/sleepers/test_sleepers.py) -test-s4l-anywhere: _check_venv_active $(S4L_INPUT_FILE) +test-s4l-anywhere: _check_venv_active $(S4L_INPUT_FILE) ## run s4l test and cache settings @$(call run_test_on_chrome, $(S4L_INPUT_FILE), tests/sim4life/test_sim4life.py) -test-jupyterlab-anywhere: _check_venv_active $(JUPYTER_LAB_INPUT_FILE) +test-jupyterlab-anywhere: _check_venv_active $(JUPYTER_LAB_INPUT_FILE) ## run jupyterlab test and cache settings @$(call run_test, $(JUPYTER_LAB_INPUT_FILE), tests/jupyterlabs/test_jupyterlab.py) -test-tip-anywhere: _check_venv_active $(CLASSIC_TIP_INPUT_FILE) +test-tip-anywhere: _check_venv_active $(CLASSIC_TIP_INPUT_FILE) ## run classic tip test and cache settings $(call run_test, $(CLASSIC_TIP_INPUT_FILE), tests/tip/test_ti_plan.py) # Define the common test running function diff --git a/tests/e2e-playwright/tests/conftest.py b/tests/e2e-playwright/tests/conftest.py index 26992facc38..cdae590ad8e 100644 --- a/tests/e2e-playwright/tests/conftest.py +++ b/tests/e2e-playwright/tests/conftest.py @@ -453,6 +453,19 @@ def _( _INNER_CONTEXT_TIMEOUT_MS = 0.8 * _OUTER_CONTEXT_TIMEOUT_MS +@pytest.fixture +def start_study_from_plus_button( + page: Page, +) -> Callable[[str], None]: + def _(plus_button_test_id: str) -> None: + with log_context( + logging.INFO, f"Find plus button {plus_button_test_id=} in study browser" + ): + page.get_by_test_id(plus_button_test_id).click() + + return _ + + @pytest.fixture def find_and_start_service_in_dashboard( page: Page, @@ -474,6 +487,21 @@ def _( return _ +@pytest.fixture +def create_project_from_new_button( + start_study_from_plus_button: Callable[[str], None], + create_new_project_and_delete: Callable[ + [tuple[RunningState], bool], dict[str, Any] + ], +) -> Callable[[str], dict[str, Any]]: + def _(plus_button_test_id: str) -> dict[str, Any]: + start_study_from_plus_button(plus_button_test_id) + expected_states = (RunningState.UNKNOWN,) + return create_new_project_and_delete(expected_states, False) + + return _ + + @pytest.fixture def create_project_from_service_dashboard( find_and_start_service_in_dashboard: Callable[[ServiceType, str, str | None], None], diff --git a/tests/e2e-playwright/tests/sim4life/conftest.py b/tests/e2e-playwright/tests/sim4life/conftest.py index d41448d97fc..0f927d22f13 100644 --- a/tests/e2e-playwright/tests/sim4life/conftest.py +++ b/tests/e2e-playwright/tests/sim4life/conftest.py @@ -19,9 +19,21 @@ def pytest_addoption(parser: pytest.Parser) -> None: default=False, help="check if video streaming is functional", ) + group.addoption( + "--use-plus-button", + action="store_true", + default=False, + help="The service key option will be used as the plus button ID instead of service key", + ) @pytest.fixture(scope="session") def check_videostreaming(request: pytest.FixtureRequest) -> bool: check_video = request.config.getoption("--check-videostreaming") return TypeAdapter(bool).validate_python(check_video) + + +@pytest.fixture(scope="session") +def use_plus_button(request: pytest.FixtureRequest) -> bool: + use_plus_button = request.config.getoption("--use-plus-button") + return TypeAdapter(bool).validate_python(use_plus_button) diff --git a/tests/e2e-playwright/tests/sim4life/test_sim4life.py b/tests/e2e-playwright/tests/sim4life/test_sim4life.py index b130fbae9e6..3fca6f36b54 100644 --- a/tests/e2e-playwright/tests/sim4life/test_sim4life.py +++ b/tests/e2e-playwright/tests/sim4life/test_sim4life.py @@ -113,14 +113,19 @@ def test_sim4life( create_project_from_service_dashboard: Callable[ [ServiceType, str, str | None], dict[str, Any] ], + create_project_from_new_button: Callable[[str], dict[str, Any]], log_in_and_out: WebSocket, service_key: str, + use_plus_button: bool, autoscaled: bool, check_videostreaming: bool, ): - project_data = create_project_from_service_dashboard( - ServiceType.DYNAMIC, service_key, None - ) + if use_plus_button: + project_data = create_project_from_new_button(service_key) + else: + project_data = create_project_from_service_dashboard( + ServiceType.DYNAMIC, service_key, None + ) assert "workbench" in project_data, "Expected workbench to be in project data!" assert isinstance( project_data["workbench"], dict @@ -128,7 +133,7 @@ def test_sim4life( node_ids: list[str] = list(project_data["workbench"]) assert len(node_ids) == 1, "Expected 1 node in the workbench!" - with log_context(logging.INFO, "launch S4l") as ctx: + with log_context(logging.INFO, "launch S4L") as ctx: predicate = _S4LWaitForWebsocket(logger=ctx.logger) with page.expect_websocket( predicate,