From 08072107aee06bf6f6c4d112eb08388f1af93a49 Mon Sep 17 00:00:00 2001 From: Thomas Kluyver Date: Wed, 28 Mar 2018 13:04:15 +0200 Subject: [PATCH] Start writing undelete test in Selenium --- notebook/tests/selenium/undelete.py | 45 +++++++++++++++++++++++++++++ notebook/tests/selenium/utils.py | 3 +- 2 files changed, 47 insertions(+), 1 deletion(-) create mode 100644 notebook/tests/selenium/undelete.py diff --git a/notebook/tests/selenium/undelete.py b/notebook/tests/selenium/undelete.py new file mode 100644 index 000000000..d83c36abe --- /dev/null +++ b/notebook/tests/selenium/undelete.py @@ -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] + + diff --git a/notebook/tests/selenium/utils.py b/notebook/tests/selenium/utils.py index 3aed1d554..99b547f7f 100644 --- a/notebook/tests/selenium/utils.py +++ b/notebook/tests/selenium/utils.py @@ -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")