Skip to content

Commit

Permalink
Modify Playwright test to account for changes in JupyterLab UI. (#2232)
Browse files Browse the repository at this point in the history
  • Loading branch information
marcelovilla authored Feb 8, 2024
2 parents 3c7c315 + 446d790 commit 4432ee9
Show file tree
Hide file tree
Showing 7 changed files with 41 additions and 35 deletions.
16 changes: 0 additions & 16 deletions .github/workflows/test_local_integration.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -167,22 +167,6 @@ jobs:
run: |
pytest tests/tests_deployment/ -v -s
- name: JupyterHub Notebook Tests
timeout-minutes: 2
# run jhub-client after pytest since jhubctl can cleanup
# the running server
env:
JUPYTERHUB_USERNAME: ${{ env.TEST_USERNAME }}
JUPYTERHUB_PASSWORD: ${{ env.TEST_PASSWORD }}
run: |
sleep 60
jhubctl --verbose run --hub=https://github-actions.nebari.dev\
--auth-type=keycloak \
--validate --no-verify-ssl \
--kernel python3 \
--stop-server \
--notebook tests/tests_deployment/assets/notebook/simple.ipynb \
### CLEANUP AFTER TESTS
- name: Cleanup nebari deployment
if: always()
Expand Down
29 changes: 21 additions & 8 deletions tests/common/navigator.py
Original file line number Diff line number Diff line change
Expand Up @@ -320,15 +320,13 @@ def _set_environment_via_popup(self, kernel=None):
# failure here indicates that the environment doesn't exist either
# because of incorrect naming syntax or because the env is still
# being built
self.page.get_by_role("combobox").nth(1).select_option(
f'{{"name":"{kernel}"}}'
)
self.page.get_by_role("combobox").nth(1).select_option(kernel)
# click Select to close popup (deal with the two formats of this dialog)
try:
self.page.get_by_role("button", name="Select", exact=True).click()
self.page.get_by_role("button", name="Select Kernel").click()
except Exception:
self.page.locator("div").filter(has_text="No KernelSelect").get_by_role(
"button", name="Select"
"button", name="Select Kernel"
).click()

def set_environment(self, kernel):
Expand Down Expand Up @@ -360,10 +358,8 @@ def set_environment(self, kernel):
self._set_environment_via_popup(kernel)

# wait for the jupyter UI to catch up before moving forward
# extract conda env name
conda_env_label = re.search("conda-env-(.*)-py", kernel).group(1)
# see if the jupyter notebook label for the conda env is visible
kernel_label_loc = self.page.get_by_role("button", name=conda_env_label)
kernel_label_loc = self.page.get_by_role("button", name=kernel)
if not kernel_label_loc.is_visible():
kernel_label_loc.wait_for(state="attached")

Expand Down Expand Up @@ -411,3 +407,20 @@ def write_file(self, filepath, content):
self.run_terminal_command(f"ls {filepath}")
logger.debug(f"time to complete {dt.datetime.now() - start}")
time.sleep(2)

def stop_server(self) -> None:
"""Stops the JupyterHub server by navigating to the Hub Control Panel."""
self.page.get_by_text("File", exact=True).click()

with self.context.expect_page() as page_info:
self.page.get_by_role(
"menuitem", name="Hub Control Panel", exact=True
).click()

home_page = page_info.value
home_page.wait_for_load_state()
stop_button = home_page.get_by_role("button", name="Stop My Server")
if not stop_button.is_visible():
stop_button.wait_for(state="visible")
stop_button.click()
stop_button.wait_for(state="hidden")
4 changes: 4 additions & 0 deletions tests/common/playwright_fixtures.py
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,10 @@ def _navigator_session(request, browser_name, pytestconfig):
logger.debug(e)
raise
finally:
try:
nav.stop_server()
except Exception as e:
logger.debug(e)
nav.teardown()


Expand Down
2 changes: 1 addition & 1 deletion tests/common/run_notebook.py
Original file line number Diff line number Diff line change
Expand Up @@ -220,7 +220,7 @@ def _restart_run_all(self):
# Restart dialog appears most, but not all of the time (e.g. set
# No Kernel, then Restart Run All)
restart_dialog_button = self.nav.page.get_by_role(
"button", name="Restart", exact=True
"button", name="Confirm Kernel Restart"
)
if restart_dialog_button.is_visible():
restart_dialog_button.click()
Expand Down
8 changes: 6 additions & 2 deletions tests/tests_deployment/test_jupyterhub_ssh.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,14 @@
TIMEOUT_SECS = 300


@pytest.fixture(scope="session")
def api_token():
return get_jupyterhub_token("jupyterhub-ssh")


@pytest.fixture(scope="function")
def paramiko_object():
def paramiko_object(api_token):
"""Connects to JupyterHub ssh cluster from outside the cluster."""
api_token = get_jupyterhub_token("jupyterhub-ssh")

try:
client = paramiko.SSHClient()
Expand Down
15 changes: 8 additions & 7 deletions tests/tests_deployment/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,16 +28,17 @@ def get_jupyterhub_session():

def get_jupyterhub_token(note="jupyterhub-tests-deployment"):
session = get_jupyterhub_session()
xsrf_token = session.cookies.get("_xsrf")
headers = {"Referer": f"https://{constants.NEBARI_HOSTNAME}/hub/token"}
if xsrf_token:
headers["X-XSRFToken"] = xsrf_token
data = {"note": note, "expires_in": None}
r = session.post(
f"https://{constants.NEBARI_HOSTNAME}/hub/api/users/{constants.KEYCLOAK_USERNAME}/tokens",
headers={
"Referer": f"https://{constants.NEBARI_HOSTNAME}/hub/token",
},
json={
"note": note,
"expires_in": None,
},
headers=headers,
json=data,
)

return r.json()["token"]


Expand Down
2 changes: 1 addition & 1 deletion tests/tests_e2e/playwright/test_playwright.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,6 @@ def test_notebook(navigator, test_data_root):
test_app.run(
path=notebook_name,
expected_outputs=["success: 6"],
conda_env="conda-env-default-py",
conda_env="default *",
timeout=500,
)

0 comments on commit 4432ee9

Please sign in to comment.