From 1c87821dc17c84362c4de9821d8408b70e1f58b1 Mon Sep 17 00:00:00 2001 From: Andres Sanchez Date: Wed, 7 Nov 2018 21:00:21 -0600 Subject: [PATCH] Modifications to test JS funcion in test_merge_cells.py --- notebook/tests/selenium/test_merge_cells.py | 20 +++++++++++--------- notebook/tests/selenium/utils.py | 13 +++++++++++++ 2 files changed, 24 insertions(+), 9 deletions(-) diff --git a/notebook/tests/selenium/test_merge_cells.py b/notebook/tests/selenium/test_merge_cells.py index 1c3c68dd9..135e8ccad 100644 --- a/notebook/tests/selenium/test_merge_cells.py +++ b/notebook/tests/selenium/test_merge_cells.py @@ -4,29 +4,31 @@ def test_merge_cells(notebook): # Add cells to notebook a = "foo = 5" b = "bar = 10" - c = "print(foo)" - d = "print(bar)" + c = "baz = 15" + d = "print(foo)" + e = "print(bar)" + f = "print(baz)" notebook.edit_cell(index=0, content=a) - notebook.append(b, c, d) + notebook.append(b, c, d, e, f) # Before merging, there are 4 separate cells - assert notebook.get_cells_contents() == [a, b, c, d] + assert notebook.get_cells_contents() == [a, b, c, d, e, f] # Focus on the second cell and merge it with the cell above notebook.focus_cell(1) notebook.browser.execute_script("Jupyter.notebook.merge_cell_above();") merged_a_b = "%s\n\n%s" % (a, b) - assert notebook.get_cells_contents() == [merged_a_b, c, d] + assert notebook.get_cells_contents() == [merged_a_b, c, d, e, f] # Focus on the second cell and merge it with the cell below notebook.focus_cell(1) notebook.browser.execute_script("Jupyter.notebook.merge_cell_below();") merged_c_d = "%s\n\n%s" % (c, d) - assert notebook.get_cells_contents() == [merged_a_b, merged_c_d] + assert notebook.get_cells_contents() == [merged_a_b, merged_c_d, e, f] # Merge everything down to a single cell - notebook.focus_cell(0) - notebook.browser.execute_script("Jupyter.notebook.merge_cell_below();") - merged_all = "%s\n\n%s" % (merged_a_b, merged_c_d) + notebook.select_command_lines(0,3) + notebook.browser.execute_script("Jupyter.notebook.merge_selected_cells();") + merged_all = "%s\n\n%s\n\n%s\n\n%s" % (merged_a_b, merged_c_d, e, f) assert notebook.get_cells_contents() == [merged_all] diff --git a/notebook/tests/selenium/utils.py b/notebook/tests/selenium/utils.py index c93200dc6..14af0b934 100644 --- a/notebook/tests/selenium/utils.py +++ b/notebook/tests/selenium/utils.py @@ -69,6 +69,13 @@ class Notebook: """ return self.browser.find_elements_by_class_name("cell") + + @property + def inputs(self): + """Gets all inputs once they are visible. + + """ + return self.browser.find_elements_by_class_name("input") @property def current_index(self): @@ -99,6 +106,12 @@ class Notebook: cell.click() self.to_command_mode() self.current_cell = cell + + def select_command_lines(self, initial_index=0, final_index=0): + self.focus_cell(initial_index) + self.to_command_mode() + for i in range(final_index - initial_index): + shift(self.browser, 'j') def find_and_replace(self, index=0, find_txt='', replace_txt=''): self.focus_cell(index)