Skip to content

Commit e688774

Browse files
committed
add explicit url_in_tree function to test whether urls are in the tree
1 parent f17e775 commit e688774

File tree

1 file changed

+12
-5
lines changed

1 file changed

+12
-5
lines changed

notebook/tests/selenium/test_dashboard_nav.py

+12-5
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@
33
from selenium.webdriver.common.by import By
44
from selenium.webdriver.support.ui import WebDriverWait
55
from selenium.webdriver.support import expected_conditions as EC
6+
7+
from notebook.utils import url_path_join
68
pjoin = os.path.join
79

810

@@ -13,16 +15,20 @@ class PageError(Exception):
1315
def __init__(self, message):
1416
self.message = message
1517

16-
18+
19+
def url_in_tree(browser, url=None):
20+
if url is None:
21+
url = browser.current_url
22+
tree_url = url_path_join(browser.jupyter_server_info['url'], 'tree')
23+
return url.startswith(tree_url)
24+
1725

1826
def get_list_items(browser):
1927
"""Gets list items from a directory listing page
2028
2129
Raises PageError if not in directory listing page (url has tree in it)
2230
"""
23-
try:
24-
assert 'tree' in browser.current_url
25-
except PageError:
31+
if not url_in_tree(browser):
2632
raise PageError("You are not in the notebook's file tree view."
2733
"This function can only be used the file tree context.")
2834
# we need to make sure that at least one item link loads
@@ -40,7 +46,8 @@ def only_dir_links(browser):
4046
4147
"""
4248
items = get_list_items(browser)
43-
return [i for i in items if 'tree' in i['link'] and i['label'] != '..']
49+
return [i for i in items
50+
if url_in_tree(browser, i['link']) and i['label'] != '..']
4451

4552

4653
def wait_for_selector(browser, selector, timeout=10):

0 commit comments

Comments
 (0)