Skip to content

Commit

Permalink
Fix test using a non-specific selector (#2475)
Browse files Browse the repository at this point in the history
  • Loading branch information
krassowski authored May 23, 2024
1 parent 43fb770 commit e59a90f
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 11 deletions.
29 changes: 19 additions & 10 deletions tests/common/navigator.py
Original file line number Diff line number Diff line change
Expand Up @@ -256,7 +256,7 @@ def reset_workspace(self):
self._set_environment_via_popup(kernel=None)

# go to Kernel menu
kernel_menuitem = self.page.get_by_text("Kernel", exact=True)
kernel_menuitem = self.page.get_by_role("menuitem", name="Kernel", exact=True)
kernel_menuitem.click()
# shut down multiple running kernels
with contextlib.suppress(Exception):
Expand Down Expand Up @@ -320,14 +320,23 @@ 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(kernel)
# click Select to close popup (deal with the two formats of this dialog)
try:
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 Kernel"
).click()

new_launcher_popup = self.page.locator(
".jp-KernelSelector-Dialog .jp-NewLauncher-table table"
).nth(0)
if new_launcher_popup.is_visible():
# for when the jupyterlab-new-launcher extension is installed
new_launcher_popup.locator("td").nth(0).click()
else:
# for when only the native launcher is available
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 Kernel").click()
except Exception:
self.page.locator("div").filter(
has_text="No KernelSelect"
).get_by_role("button", name="Select Kernel").click()

def set_environment(self, kernel):
"""Set environment of a jupyter notebook.
Expand All @@ -350,7 +359,7 @@ def set_environment(self, kernel):
popup = self._check_for_kernel_popup()
# if there is not a kernel popup, make it appear
if not popup:
self.page.get_by_text("Kernel", exact=True).click()
self.page.get_by_role("menuitem", name="Kernel", exact=True).click()
self.page.get_by_role("menuitem", name="Change Kernel…").get_by_text(
"Change Kernel…"
).click()
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 @@ -212,7 +212,7 @@ def _get_outputs(self) -> List[str]:

def _restart_run_all(self):
# restart run all cells
self.nav.page.get_by_text("Kernel", exact=True).click()
self.nav.page.get_by_role("menuitem", name="Kernel", exact=True).click()
self.nav.page.get_by_role(
"menuitem", name="Restart Kernel and Run All Cells…"
).get_by_text("Restart Kernel and Run All Cells…").click()
Expand Down

0 comments on commit e59a90f

Please sign in to comment.