Skip to content

Update selenium tests #3412

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 8 commits into from
Mar 23, 2018
27 changes: 19 additions & 8 deletions notebook/tests/selenium/test_dashboard_nav.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,32 +13,43 @@ def get_list_items(browser):
} for a in browser.find_elements_by_class_name('item_link')]


def only_dir_links(browser):
try:
assert 'tree' in browser.current_url
except AssertionError:
raise("You currently ")
wait_for_selector(browser, '.item_link')
items = get_list_items(browser)
return [i for i in items if 'tree' in i['link'] and i['label'] != '..']
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This will go wrong for any file that has tree in the name. Maybe that's unlikely, but I think it's worth doing it a bit more thoroughly.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ok addressed by using an explicit check for whether urls point to something in the tree (with url_in_tree)



def wait_for_selector(browser, selector, timeout=10):
wait = WebDriverWait(browser, timeout)
return wait.until(EC.visibility_of_element_located((By.CSS_SELECTOR, selector)))


def test_items(authenticated_browser):
tree_root_url = authenticated_browser.current_url
visited_dict = {}
# Going down the tree to collect links
while True:
wait_for_selector(authenticated_browser, '.item_link')
items = get_list_items(authenticated_browser)
visited_dict[authenticated_browser.current_url] = items
print(authenticated_browser.current_url, len(items))
if len(items)>1:
item = items[1]
url = item['link']
current_url = authenticated_browser.current_url
items = visited_dict[current_url] = only_dir_links(authenticated_browser)
try:
item = items[0]
text, url = (item['label'], item['link'])
item["element"].click()
assert authenticated_browser.current_url == url
else:
except IndexError:
break
# Going back up the tree while we still have unvisited links
while visited_dict:
wait_for_selector(authenticated_browser, '.item_link')
current_items = get_list_items(authenticated_browser)
current_items = only_dir_links(authenticated_browser)
current_items_links = [item["link"] for item in current_items]
stored_items = visited_dict.pop(authenticated_browser.current_url)
stored_items_links = [item["link"] for item in stored_items]
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Neat, I like the comparison of what's here now vs what was here before.

assert stored_items_links == current_items_links
authenticated_browser.back()