Start writing undelete test in Selenium

pull/3475/head
Thomas Kluyver 8 years ago
parent b49ba398c6
commit 08072107ae

@ -0,0 +1,45 @@
from selenium.webdriver import ActionChains
from selenium.webdriver.common.keys import Keys
def get_cells_contents(nb):
return [c.find_element_by_class_name('input_area').text
for c in nb.cells]
def shift_down(browser):
ActionChains(browser)\
.key_down(Keys.SHIFT).send_keys(Keys.DOWN).key_up(Keys.SHIFT)\
.perform()
def test_undelete_cells(notebook):
a = 'print("a")'
b = 'print("b")'
c = 'print("c")'
d = 'print("d")'
notebook.edit_cell(index=0, content=a)
notebook.append(b, c, d)
notebook.focus_cell(0)
# Verify initial state
assert get_cells_contents(notebook) == [a, b, c, d]
# Delete cells [1, 2]
notebook.focus_cell(1)
shift_down(notebook.browser)
notebook.current_cell.send_keys('dd')
assert get_cells_contents(notebook) == [a, d]
# Delete new cell 1 (which contains d)
notebook.focus_cell(1)
notebook.current_cell.send_keys('dd')
assert get_cells_contents(notebook) == [a]
# Undelete d
notebook.browser.execute_script('Jupyter.notebook.undelete_cell();')
assert get_cells_contents(notebook) == [a, d]
# Undelete b, c
notebook.browser.execute_script('Jupyter.notebook.undelete_cell();')
assert get_cells_contents(notebook) == [a, b, c, d]

@ -154,7 +154,8 @@ class Notebook:
new_index = index + 1 if index >= 0 else index
if content:
self.edit_cell(index=index, content=content)
self.convert_cell_type(index=new_index, cell_type=cell_type)
if cell_type != 'code':
self.convert_cell_type(index=new_index, cell_type=cell_type)
def add_markdown_cell(self, index=-1, content="", render=True):
self.add_cell(index, cell_type="markdown")

Loading…
Cancel
Save