Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

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 ourterms of service andprivacy statement. We’ll occasionally send you account related emails.

Already on GitHub?Sign in to your account

Merged
takluyver merged 8 commits intojupyter:masterfrommpacer:update_selenium_tests
Mar 23, 2018
Merged
Show file tree
Hide file tree
Changes from3 commits
Commits
Show all changes
8 commits
Select commitHold shift + click to select a range
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletionnotebook/static/tree/js/notebooklist.js
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -102,6 +102,7 @@ define([
this.sessions = {};
this.base_url = options.base_url || utils.get_body_data("baseUrl");
this.notebook_path = options.notebook_path || utils.get_body_data("notebookPath");
this.initial_notebook_path = this.notebook_path;
this.contents = options.contents;
if (this.session_list && this.session_list.events) {
this.session_list.events.on('sessions_loaded.Dashboard',
Expand DownExpand Up@@ -358,7 +359,8 @@ define([
var that = this;
// Add an event handler browser back and forward events
window.onpopstate = function(e) {
var path = window.history.state ? window.history.state.path : '';
var path = (window.history.state && window.history.state.path) ?
window.history.state.path : that.initial_notebook_path;
that.update_location(path);
};
var breadcrumb = $('.breadcrumb');
Expand Down
23 changes: 13 additions & 10 deletionsnotebook/tests/selenium/conftest.py
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -63,8 +63,8 @@ def notebook_server():
requests.post(urljoin(info['url'], 'api/shutdown'),
headers={'Authorization': 'token '+info['token']})


def_get_selenium_driver():
@pytest.fixture(scope='session')
defselenium_driver():
if os.environ.get('SAUCE_USERNAME'):
username = os.environ["SAUCE_USERNAME"]
access_key = os.environ["SAUCE_ACCESS_KEY"]
Expand All@@ -81,16 +81,19 @@ def _get_selenium_driver():
capabilities['version'] = '57.0'
hub_url = "%s:%s@localhost:4445" % (username, access_key)
print("Connecting remote driver on Sauce Labs")
return Remote(desired_capabilities=capabilities,
driver = Remote(desired_capabilities=capabilities,
command_executor="http://%s/wd/hub" % hub_url)
elif os.environ.get('JUPYTER_TEST_BROWSER') == 'chrome':
return Chrome()
driver = Chrome()
else:
return Firefox()
driver = Firefox()

yield driver

# Teardown
driver.quit()

@pytest.fixture
def browser(notebook_server):
b = _get_selenium_driver()
b.get("{url}?token={token}".format(**notebook_server))
yield b
b.quit()
def authenticated_browser(selenium_driver, notebook_server):
selenium_driver.get("{url}?token={token}".format(**notebook_server))
return selenium_driver
53 changes: 26 additions & 27 deletionsnotebook/tests/selenium/test_dashboard_nav.py
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -3,43 +3,42 @@
fromselenium.webdriver.common.byimportBy
fromselenium.webdriver.support.uiimportWebDriverWait
fromselenium.webdriver.supportimportexpected_conditionsasEC

pjoin=os.path.join

defget_list_items(browser):
return [{
'link':a.get_attribute('href'),
'label':a.find_element_by_class_name('item_name').text,
'element':a,
}forainbrowser.find_elements_by_class_name('item_link')]


defwait_for_selector(browser,selector,timeout=10):
wait=WebDriverWait(browser,timeout)
returnwait.until(EC.visibility_of_element_located((By.CSS_SELECTOR,selector)))



deftest_items(browser,visited=None):
tree_root_url=browser.current_url
ifvisitedisNone:
visited=set()

wait_for_selector(browser,'.item_link')
items=get_list_items(browser)
print(browser.current_url,len(items))
foriteminitems:
print(item)
url=item['link']
ifurl.startswith(tree_root_url):
print("Going to",url)
ifurlinvisited:
continue
visited.add(url)
browser.get(url)
wait_for_selector(browser,'.item_link')
assertbrowser.current_url==url

test_items(browser,visited)
#browser.back()

print()
deftest_items(authenticated_browser):
tree_root_url=authenticated_browser.current_url
visited_dict= {}
# Going down the tree to collect links
whileTrue:
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))
iflen(items)>1:
Copy link
Member

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.

Copy link
MemberAuthor

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?

Copy link
Member

Choose a reason for hiding this comment

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

Yep, that's right.

Copy link
MemberAuthor

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

item=items[1]
url=item['link']
item["element"].click()
assertauthenticated_browser.current_url==url
else:
break
# Going back up the tree while we still have unvisited links
whilevisited_dict:
wait_for_selector(authenticated_browser,'.item_link')
current_items=get_list_items(authenticated_browser)
current_items_links= [item["link"]foritemincurrent_items]
stored_items=visited_dict.pop(authenticated_browser.current_url)
stored_items_links= [item["link"]foriteminstored_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.

assertstored_items_links==current_items_links
authenticated_browser.back()

[8]ページ先頭

©2009-2025 Movatter.jp