Skip to content

Commit

Permalink
e2e: Sim4Life uses plus button (#6167)
Browse files Browse the repository at this point in the history
Co-authored-by: sanderegg <[email protected]>
  • Loading branch information
odeimaiz and sanderegg authored Aug 12, 2024
1 parent 684a11c commit 248fba2
Show file tree
Hide file tree
Showing 4 changed files with 60 additions and 9 deletions.
16 changes: 11 additions & 5 deletions tests/e2e-playwright/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
28 changes: 28 additions & 0 deletions tests/e2e-playwright/tests/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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],
Expand Down
12 changes: 12 additions & 0 deletions tests/e2e-playwright/tests/sim4life/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
13 changes: 9 additions & 4 deletions tests/e2e-playwright/tests/sim4life/test_sim4life.py
Original file line number Diff line number Diff line change
Expand Up @@ -113,22 +113,27 @@ 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
), "Expected workbench to be a dict!"
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,
Expand Down

0 comments on commit 248fba2

Please sign in to comment.