diff --git a/notebook/tests/selenium/test_deletecell.py b/notebook/tests/selenium/test_deletecell.py index 60f7d8127..388dd2ad8 100644 --- a/notebook/tests/selenium/test_deletecell.py +++ b/notebook/tests/selenium/test_deletecell.py @@ -1,14 +1,6 @@ import os import pytest -def get_cells_contents(nb): - JS = 'return Jupyter.notebook.get_cells().map(function(c) {return c.get_text();})' - return nb.browser.execute_script(JS) - -def set_cell_metadata(nb, index, key, value): - JS = 'Jupyter.notebook.get_cell({}).metadata.{} = {}'.format(index, key, value) - return nb.browser.execute_script(JS) - def cell_is_deletable(nb, index): JS = 'return Jupyter.notebook.get_cell({}).is_deletable();'.format(index) return nb.browser.execute_script(JS) @@ -28,12 +20,12 @@ def test_delete_cells(notebook): notebook.to_command_mode() # Validate initial state - assert get_cells_contents(notebook) == [a, b, c] + assert notebook.get_cells_contents() == [a, b, c] for cell in range(0, 3): assert cell_is_deletable(notebook, cell) - set_cell_metadata(notebook, 0, 'deletable', 'false') - set_cell_metadata(notebook, 1, 'deletable', 0 + notebook.set_cell_metadata(0, 'deletable', 'false') + notebook.set_cell_metadata(1, 'deletable', 0 ) assert not cell_is_deletable(notebook, 0) assert cell_is_deletable(notebook, 1) @@ -41,18 +33,18 @@ def test_delete_cells(notebook): # Try to delete cell a (should not be deleted) delete_cell(notebook, 0) - assert get_cells_contents(notebook) == [a, b, c] + assert notebook.get_cells_contents() == [a, b, c] # Try to delete cell b (should succeed) delete_cell(notebook, 1) - assert get_cells_contents(notebook) == [a, c] + assert notebook.get_cells_contents() == [a, c] # Try to delete cell c (should succeed) delete_cell(notebook, 1) - assert get_cells_contents(notebook) == [a] + assert notebook.get_cells_contents() == [a] # Change the deletable state of cell a - set_cell_metadata(notebook, 0, 'deletable', 'true') + notebook.set_cell_metadata(0, 'deletable', 'true') # Try to delete cell a (should succeed) delete_cell(notebook, 0) @@ -60,7 +52,7 @@ def test_delete_cells(notebook): # Make sure copied cells are deletable notebook.edit_cell(index=0, content=a) - set_cell_metadata(notebook, 0, 'deletable', 'false') + notebook.set_cell_metadata(0, 'deletable', 'false') assert not cell_is_deletable(notebook, 0) notebook.to_command_mode() notebook.current_cell.send_keys('cv') diff --git a/notebook/tests/selenium/utils.py b/notebook/tests/selenium/utils.py index efe49fb4c..ef4092772 100644 --- a/notebook/tests/selenium/utils.py +++ b/notebook/tests/selenium/utils.py @@ -127,6 +127,14 @@ class Notebook: wait = WebDriverWait(self.browser, 10) element = wait.until(EC.staleness_of(cell)) + def get_cells_contents(self): + JS = 'return Jupyter.notebook.get_cells().map(function(c) {return c.get_text();})' + return self.browser.execute_script(JS) + + def set_cell_metadata(self, index, key, value): + JS = 'Jupyter.notebook.get_cell({}).metadata.{} = {}'.format(index, key, value) + return self.browser.execute_script(JS) + def edit_cell(self, cell=None, index=0, content="", render=False): """Set the contents of a cell to *content*, by cell object or by index """