3
3
from selenium .webdriver .common .by import By
4
4
from selenium .webdriver .support .ui import WebDriverWait
5
5
from selenium .webdriver .support import expected_conditions as EC
6
+
7
+ from notebook .utils import url_path_join
6
8
pjoin = os .path .join
7
9
8
10
@@ -13,16 +15,20 @@ class PageError(Exception):
13
15
def __init__ (self , message ):
14
16
self .message = message
15
17
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
+
17
25
18
26
def get_list_items (browser ):
19
27
"""Gets list items from a directory listing page
20
28
21
29
Raises PageError if not in directory listing page (url has tree in it)
22
30
"""
23
- try :
24
- assert 'tree' in browser .current_url
25
- except PageError :
31
+ if not url_in_tree (browser ):
26
32
raise PageError ("You are not in the notebook's file tree view."
27
33
"This function can only be used the file tree context." )
28
34
# we need to make sure that at least one item link loads
@@ -40,7 +46,8 @@ def only_dir_links(browser):
40
46
41
47
"""
42
48
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' ] != '..' ]
44
51
45
52
46
53
def wait_for_selector (browser , selector , timeout = 10 ):
0 commit comments