Skip to content

Commit eab1e70

Browse files
committed
Add basic selenium test case
1 parent 84e565c commit eab1e70

File tree

2 files changed

+43
-1
lines changed

2 files changed

+43
-1
lines changed

notebook/static/notebook/js/notebook.js

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2858,6 +2858,7 @@ define([
28582858
$('<br/>')
28592859
).append(
28602860
$('<input/>').attr('type','text').attr('size','25')
2861+
.attr('data-testid', 'save-as')
28612862
.addClass('form-control')
28622863
);
28632864

@@ -2894,7 +2895,8 @@ define([
28942895
that.events.trigger('notebook_renamed.Notebook', data);
28952896

28962897
},function(error) {
2897-
console.error(i18n.msg._(error.message || 'Unknown error saving notebook'));
2898+
const msg = i18n.msg._(error.message || 'Unknown error saving notebook');
2899+
$('.save-message').html(`<span style='color:red;'>${msg}</span>`);
28982900
});
28992901
}
29002902
that.contents.get(nb_path, {type: 'notebook'}).then(function(data) {
Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
from notebook.tests.selenium.utils import wait_for_selector
2+
from selenium.webdriver.common.keys import Keys
3+
from selenium.webdriver.support.ui import WebDriverWait
4+
5+
def wait_for_rename(browser, nbname, timeout=10):
6+
wait = WebDriverWait(browser, timeout)
7+
def notebook_renamed(browser):
8+
elem = browser.find_element_by_id('notebook_name')
9+
current_name = browser.execute_script('return arguments[0].innerText', elem)
10+
return current_name == nbname
11+
return wait.until(notebook_renamed)
12+
13+
def save_as(nb):
14+
JS = 'Jupyter.notebook.save_notebook_as()'
15+
return nb.browser.execute_script(JS)
16+
17+
def get_notebook_name(nb):
18+
JS = 'return Jupyter.notebook.notebook_name'
19+
return nb.browser.execute_script(JS)
20+
21+
def set_notebook_name(nb, name):
22+
JS = 'Jupyter.notebook.rename("{}")'.format(name)
23+
nb.browser.execute_script(JS)
24+
25+
def test_save_notebook_as(notebook):
26+
# Set a name for comparison later
27+
set_notebook_name(notebook, name="nb1.ipynb")
28+
wait_for_rename(notebook.browser, "nb1")
29+
assert get_notebook_name(notebook) == "nb1.ipynb"
30+
# Wait for Save As modal, save
31+
save_as(notebook)
32+
wait_for_selector(notebook.browser, '.save-message')
33+
inp = notebook.browser.find_element_by_xpath('//input[@data-testid="save-as"]')
34+
inp.send_keys('new_notebook.ipynb')
35+
inp.send_keys(Keys.RETURN)
36+
wait_for_rename(notebook.browser, "new_notebook")
37+
# Test that the name changed
38+
assert get_notebook_name(notebook) == "new_notebook.ipynb"
39+
# Test that address bar was updated (TODO: get the base url)
40+
assert "new_notebook.ipynb" in notebook.browser.current_url

0 commit comments

Comments
 (0)