Skip to content

Commit f76be28

Browse files
⚗️ ♻️ improving e2e tests (adding structure for additional CI tests) (#6765)
1 parent 793318d commit f76be28

File tree

6 files changed

+127
-2
lines changed

6 files changed

+127
-2
lines changed

ci/github/system-testing/e2e-playwright.bash

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ test() {
2424
source .venv/bin/activate
2525
pushd tests/e2e-playwright
2626
make test-sleepers
27+
make test-platform
2728
popd
2829
}
2930

packages/pytest-simcore/src/pytest_simcore/helpers/playwright.py

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -339,9 +339,14 @@ def __call__(self, message: str) -> bool:
339339
url = f"https://{self.node_id}.services.{self.get_partial_product_url()}"
340340
response = httpx.get(url, timeout=10)
341341
self.logger.info(
342-
"Querying the service endpoint from the E2E test. Url: %s Response: %s",
342+
"Querying the service endpoint from the E2E test. Url: %s Response: %s TIP: %s",
343343
url,
344344
response,
345+
(
346+
"Response 401 is OK. It means that service is ready."
347+
if response.status_code == 401
348+
else "We are emulating the frontend; a 500 response is acceptable if the service is not yet ready."
349+
),
345350
)
346351
if response.status_code <= 401:
347352
# NOTE: If the response status is less than 400, it means that the backend is ready (There are some services that respond with a 3XX)

tests/e2e-playwright/Makefile

Lines changed: 24 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,8 @@ install-dev install-prod install-ci: _check_venv_active ## install app in develo
6464
RETRY_DURATION_SECONDS := 30
6565
RETRY_INTERVAL_SECONDS := 1
6666

67-
install-ci-up-simcore: install-ci
67+
.PHONY: install-ci-up-simcore
68+
install-ci-up-simcore: install-ci ## run registry and simcore stack locally (push sleepers image and modifies DB)
6869
@$(MAKE_C) $(REPO_BASE_DIR) local-registry
6970
@$(_transfer-images-to-registry)
7071
@$(_up_simcore)
@@ -106,6 +107,28 @@ test-sleepers-dev: _check_venv_active ## runs sleepers test on local deploy
106107
--autoregister \
107108
$(CURDIR)/tests/sleepers/test_sleepers.py
108109

110+
.PHONY: test-platform
111+
test-platform: _check_venv_active ## runs platform test on local deploy
112+
@pytest \
113+
-sxvv \
114+
--color=yes \
115+
--product-url=http://$(get_my_ip):9081 \
116+
--autoregister \
117+
--tracing=on \
118+
$(CURDIR)/tests/platform_CI_tests/test_platform.py
119+
120+
.PHONY: test-platform-dev
121+
test-platform-dev: _check_venv_active ## runs platform test on local deploy (with PWDEBUG=1)
122+
@PWDEBUG=1 pytest \
123+
-sxvv \
124+
--color=yes \
125+
--pdb \
126+
--product-url=http://$(get_my_ip):9081 \
127+
--headed \
128+
--autoregister \
129+
--tracing=on \
130+
$(CURDIR)/tests/platform_CI_tests/test_platform.py
131+
109132

110133
# Define the files where user input will be saved
111134
SLEEPERS_INPUT_FILE := .e2e-playwright-sleepers-env.txt

tests/e2e-playwright/tests/conftest.py

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -323,6 +323,11 @@ def _do() -> AutoRegisteredUser:
323323
return _do
324324

325325

326+
@pytest.fixture(scope="session")
327+
def store_browser_context() -> bool:
328+
return False
329+
330+
326331
@pytest.fixture
327332
def log_in_and_out(
328333
page: Page,
@@ -331,6 +336,8 @@ def log_in_and_out(
331336
user_password: Secret4TestsStr,
332337
auto_register: bool,
333338
register: Callable[[], AutoRegisteredUser],
339+
store_browser_context: bool,
340+
context: BrowserContext,
334341
) -> Iterator[RestartableWebSocket]:
335342
with log_context(
336343
logging.INFO,
@@ -389,6 +396,9 @@ def log_in_and_out(
389396
if quickStartWindowCloseBtnLocator.is_visible():
390397
quickStartWindowCloseBtnLocator.click()
391398

399+
if store_browser_context:
400+
context.storage_state(path="state.json")
401+
392402
# with web_socket_default_log_handler(ws):
393403
yield restartable_wb
394404

tests/e2e-playwright/tests/platform_CI_tests/conftest.py

Whitespace-only changes.
Lines changed: 86 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,86 @@
1+
# pylint: disable=redefined-outer-name
2+
# pylint: disable=unused-argument
3+
# pylint: disable=unused-variable
4+
# pylint: disable=too-many-arguments
5+
# pylint: disable=too-many-statements
6+
# pylint: disable=no-name-in-module
7+
8+
from pathlib import Path
9+
10+
import pytest
11+
12+
13+
@pytest.fixture(scope="session")
14+
def store_browser_context() -> bool:
15+
return True
16+
17+
18+
@pytest.fixture
19+
def logged_in_context(
20+
playwright,
21+
store_browser_context: bool,
22+
request: pytest.FixtureRequest,
23+
pytestconfig,
24+
):
25+
is_headed = "--headed" in pytestconfig.invocation_params.args
26+
27+
file_path = Path("state.json")
28+
if not file_path.exists():
29+
request.getfixturevalue("log_in_and_out")
30+
31+
browser = playwright.chromium.launch(headless=not is_headed)
32+
context = browser.new_context(storage_state="state.json")
33+
yield context
34+
context.close()
35+
browser.close()
36+
37+
38+
@pytest.fixture(scope="module")
39+
def test_module_teardown():
40+
41+
yield # Run the tests
42+
43+
file_path = Path("state.json")
44+
if file_path.exists():
45+
file_path.unlink()
46+
47+
48+
def test_simple_folder_workflow(logged_in_context, product_url, test_module_teardown):
49+
page = logged_in_context.new_page()
50+
51+
page.goto(f"{product_url}")
52+
page.wait_for_timeout(1000)
53+
page.get_by_test_id("newFolderButton").click()
54+
55+
with page.expect_response(
56+
lambda response: "folders" in response.url
57+
and response.status == 201
58+
and response.request.method == "POST"
59+
) as response_info:
60+
page.get_by_test_id("folderEditorTitle").fill("My new folder")
61+
page.get_by_test_id("folderEditorCreate").click()
62+
63+
_folder_id = response_info.value.json()["data"]["folderId"]
64+
page.get_by_test_id(f"folderItem_{_folder_id}").click()
65+
page.get_by_test_id("workspacesAndFoldersTreeItem_null_null").click()
66+
67+
68+
def test_simple_workspace_workflow(
69+
logged_in_context, product_url, test_module_teardown
70+
):
71+
page = logged_in_context.new_page()
72+
73+
page.goto(f"{product_url}")
74+
page.wait_for_timeout(1000)
75+
page.get_by_test_id("workspacesAndFoldersTreeItem_-1_null").click()
76+
77+
with page.expect_response(
78+
lambda response: "workspaces" in response.url
79+
and response.status == 201
80+
and response.request.method == "POST"
81+
) as response_info:
82+
page.get_by_test_id("newWorkspaceButton").click()
83+
page.get_by_test_id("workspaceEditorSave").click()
84+
_workspace_id = response_info.value.json()["data"]["workspaceId"]
85+
page.get_by_test_id(f"workspaceItem_{_workspace_id}").click()
86+
page.get_by_test_id("workspacesAndFoldersTreeItem_null_null").click()

0 commit comments

Comments
 (0)