-
Notifications
You must be signed in to change notification settings - Fork 5.1k
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
Update selenium tests #3412
Merged
Merged
Update selenium tests #3412
Changes from 3 commits
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
0c28482
Fix going back to root directory with history in notebook list
takluyver 965970a
creates selenium driver(session-scope) & authenticated_browser fixtures
mpacer 1f549fc
change dashboard test to click on links, go back, and check for contents
mpacer f4c90eb
introduce only_dir_links function to extract tree links from listing
mpacer c8605f1
use only_dir_links inside test to avoid clicking '..' or non-dir links
mpacer 47d2be4
move check & wait from only_dir_links to get_list_items; add docstrings
mpacer f17e775
add jupyter_server_info to authenticated browser fixture
mpacer e688774
add explicit url_in_tree function to test whether urls are in the tree
mpacer File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -3,43 +3,42 @@ | |
from selenium.webdriver.common.by import By | ||
from selenium.webdriver.support.ui import WebDriverWait | ||
from selenium.webdriver.support import expected_conditions as EC | ||
|
||
pjoin = os.path.join | ||
|
||
def get_list_items(browser): | ||
return [{ | ||
'link': a.get_attribute('href'), | ||
'label': a.find_element_by_class_name('item_name').text, | ||
'element': a, | ||
} for a in browser.find_elements_by_class_name('item_link')] | ||
|
||
|
||
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(browser, visited=None): | ||
tree_root_url = browser.current_url | ||
if visited is None: | ||
visited = set() | ||
|
||
wait_for_selector(browser, '.item_link') | ||
items = get_list_items(browser) | ||
print(browser.current_url, len(items)) | ||
for item in items: | ||
print(item) | ||
url = item['link'] | ||
if url.startswith(tree_root_url): | ||
print("Going to", url) | ||
if url in visited: | ||
continue | ||
visited.add(url) | ||
browser.get(url) | ||
wait_for_selector(browser, '.item_link') | ||
assert browser.current_url == url | ||
|
||
test_items(browser, visited) | ||
#browser.back() | ||
|
||
print() | ||
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'] | ||
item["element"].click() | ||
assert authenticated_browser.current_url == url | ||
else: | ||
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_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] | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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() |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why does it not work with 1 item? Does it catch the link to go up a directory?
I think it would be good to filter out which items are directories, so that this doesn't accidentally load a notebook or another file.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
For the first, I was using that to filter out
..
but I see now that that actually introduces weird behaviour at the root.For the second, I gather that I can distinguish that based on the link target being on the
/tree
vs./notebook
or/file
endpoints?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yep, that's right.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Oops! i forgot about this simple fix and have been focused on getting the notebook navigation stuff working on the markdown stuff. I'll fix this quickly