From 35a19e930860e6cecd12a4dfecac357769edc47d Mon Sep 17 00:00:00 2001 From: Emilio Talamante Lugo Date: Sun, 24 Mar 2019 21:20:18 -0700 Subject: [PATCH 1/2] Fixed dualmode insert test and convert dualmode arrows test to selenium --- notebook/tests/notebook/dualmode_arrows.js | 51 --------- .../tests/selenium/test_dualmode_arrows.py | 103 ++++++++++++++++++ notebook/tests/selenium/utils.py | 4 +- 3 files changed, 105 insertions(+), 53 deletions(-) delete mode 100644 notebook/tests/notebook/dualmode_arrows.js create mode 100644 notebook/tests/selenium/test_dualmode_arrows.py diff --git a/notebook/tests/notebook/dualmode_arrows.js b/notebook/tests/notebook/dualmode_arrows.js deleted file mode 100644 index 034929b5f..000000000 --- a/notebook/tests/notebook/dualmode_arrows.js +++ /dev/null @@ -1,51 +0,0 @@ - -// Test -casper.notebook_test(function () { - var a = 'print("a")'; - var index = this.append_cell(a); - this.execute_cell_then(index); - - var b = 'print("b")'; - index = this.append_cell(b); - this.execute_cell_then(index); - - var c = 'print("c")'; - index = this.append_cell(c); - this.execute_cell_then(index); - - this.then(function () { - - // Up and down in command mode - this.select_cell(3); - this.trigger_keydown('j'); - this.validate_notebook_state('j at end of notebook', 'command', 3); - this.trigger_keydown('down'); - this.validate_notebook_state('down at end of notebook', 'command', 3); - this.trigger_keydown('up'); - this.validate_notebook_state('up', 'command', 2); - this.select_cell(0); - this.validate_notebook_state('select 0', 'command', 0); - this.trigger_keydown('k'); - this.validate_notebook_state('k at top of notebook', 'command', 0); - this.trigger_keydown('up'); - this.validate_notebook_state('up at top of notebook', 'command', 0); - this.trigger_keydown('down'); - this.validate_notebook_state('down', 'command', 1); - - // Up and down in edit mode - this.click_cell_editor(3); - this.validate_notebook_state('click cell 3', 'edit', 3); - this.trigger_keydown('down'); - this.validate_notebook_state('down at end of notebook', 'edit', 3); - this.set_cell_editor_cursor(3, 0, 0); - this.trigger_keydown('up'); - this.validate_notebook_state('up', 'edit', 2); - this.click_cell_editor(0); - this.validate_notebook_state('click 0', 'edit', 0); - this.trigger_keydown('up'); - this.validate_notebook_state('up at top of notebook', 'edit', 0); - this.set_cell_editor_cursor(0, 0, 10); - this.trigger_keydown('down'); - this.validate_notebook_state('down', 'edit', 1); - }); -}); diff --git a/notebook/tests/selenium/test_dualmode_arrows.py b/notebook/tests/selenium/test_dualmode_arrows.py new file mode 100644 index 000000000..c881f053c --- /dev/null +++ b/notebook/tests/selenium/test_dualmode_arrows.py @@ -0,0 +1,103 @@ +"""Tests arrow keys on both command and edit mode""" +from selenium.webdriver.common.keys import Keys + +def test_dualmode_arrows(notebook): + + # Tests in command mode. + # Setting up the cells to test the keys to move up. + notebook.to_command_mode() + [notebook.body.send_keys("b") for i in range(3)] + + # Use both "k" and up arrow keys to moving up and enter a value. + # Once located on the top cell, use the up arrow keys to prove the top cell is still selected. + notebook.body.send_keys("k") + notebook.body.send_keys(Keys.ENTER) + notebook.body.send_keys("2") + notebook.to_command_mode() + notebook.body.send_keys(Keys.UP) + notebook.body.send_keys(Keys.ENTER) + notebook.body.send_keys("1") + notebook.to_command_mode() + notebook.body.send_keys("k") + notebook.body.send_keys(Keys.UP) + notebook.body.send_keys(Keys.ENTER) + notebook.body.send_keys("0") + notebook.to_command_mode() + assert notebook.get_cells_contents() == ["0", "1", "2", ""] + + # Use the "k" key on the top cell as well + notebook.body.send_keys("k") + notebook.body.send_keys(Keys.ENTER) + notebook.body.send_keys(" edit #1") + notebook.to_command_mode() + assert notebook.get_cells_contents() == ["0 edit #1", "1", "2", ""] + + # Setting up the cells to test the keys to move down + [notebook.body.send_keys("j") for i in range(3)] + [notebook.body.send_keys("a") for i in range(2)] + notebook.body.send_keys("k") + + # Use both "j" key and down arrow keys to moving down and enter a value. + # Once located on the bottom cell, use the down arrow key to prove the bottom cell is still selected. + notebook.body.send_keys(Keys.DOWN) + notebook.body.send_keys(Keys.ENTER) + notebook.body.send_keys("3") + notebook.to_command_mode() + notebook.body.send_keys("j") + notebook.body.send_keys(Keys.ENTER) + notebook.body.send_keys("4") + notebook.to_command_mode() + notebook.body.send_keys("j") + notebook.body.send_keys(Keys.DOWN) + notebook.body.send_keys(Keys.ENTER) + notebook.body.send_keys("5") + notebook.to_command_mode() + assert notebook.get_cells_contents() == ["0 edit #1", "1", "2", "3", "4", "5"] + + # Use the "j" key on the top cell as well + notebook.body.send_keys("j") + notebook.body.send_keys(Keys.ENTER) + notebook.body.send_keys(" edit #1") + notebook.to_command_mode() + assert notebook.get_cells_contents() == ["0 edit #1", "1", "2", "3", "4", "5 edit #1"] + + # On the bottom cell, use both left and right arrow keys to prove the bottom cell is still selected. + notebook.body.send_keys(Keys.LEFT) + notebook.body.send_keys(Keys.ENTER) + notebook.body.send_keys(", #2") + notebook.to_command_mode() + assert notebook.get_cells_contents() == ["0 edit #1", "1", "2", "3", "4", "5 edit #1, #2"] + notebook.body.send_keys(Keys.RIGHT) + notebook.body.send_keys(Keys.ENTER) + notebook.body.send_keys(" and #3") + notebook.to_command_mode() + assert notebook.get_cells_contents() == ["0 edit #1", "1", "2", "3", "4", "5 edit #1, #2 and #3"] + + + # Tests in edit mode. + # First, erase the previous content and then setup the cells to test the keys to move up. + [notebook.browser.find_element_by_class_name("fa-cut.fa").click() for i in range(6)] + [notebook.body.send_keys("b") for i in range(2)] + notebook.body.send_keys("a") + notebook.body.send_keys(Keys.ENTER) + + # Use the up arrow key to move down and enter a value. + # We will use the left arrow key to move one char to the left since moving up on last character only moves selector to the first one. + # Once located on the top cell, use the up arrow key to prove the top cell is still selected. + notebook.body.send_keys(Keys.UP) + notebook.body.send_keys("1") + notebook.body.send_keys(Keys.LEFT) + [notebook.body.send_keys(Keys.UP) for i in range(2)] + notebook.body.send_keys("0") + + # Use the down arrow key to move down and enter a value. + # We will use the right arrow key to move one char to the right since moving down puts selector to the last character. + # Once located on the bottom cell, use the down arrow key to prove the bottom cell is still selected. + notebook.body.send_keys(Keys.DOWN) + notebook.body.send_keys(Keys.RIGHT) + notebook.body.send_keys(Keys.DOWN) + notebook.body.send_keys("2") + [notebook.body.send_keys(Keys.DOWN) for i in range(2)] + notebook.body.send_keys("3") + notebook.to_command_mode() + assert notebook.get_cells_contents() == ["0", "1", "2", "3"] \ No newline at end of file diff --git a/notebook/tests/selenium/utils.py b/notebook/tests/selenium/utils.py index 60d0bbd92..91cb8ea5a 100644 --- a/notebook/tests/selenium/utils.py +++ b/notebook/tests/selenium/utils.py @@ -356,8 +356,8 @@ def shift(browser, k): trigger_keystrokes(browser, "shift-%s"%k) def ctrl(browser, k): - """Send key combination Ctrl+(k)""" - trigger_keystrokes(browser, "control-%s"%k) + """Send key combination Ctrl+(k) or Command+(k) for MacOS""" + trigger_keystrokes(browser, "command-%s"%k) if os.uname()[0] == "Darwin" else trigger_keystrokes(browser, "control-%s"%k) def trigger_keystrokes(browser, *keys): """ Send the keys in sequence to the browser. From d8120e5845690de2ecf1a02962c8496431b65fd9 Mon Sep 17 00:00:00 2001 From: Emilio Talamante Lugo Date: Fri, 29 Mar 2019 20:24:30 -0700 Subject: [PATCH 2/2] Rename ctrl method to cmdtrl which covers the mains OS --- notebook/tests/selenium/utils.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/notebook/tests/selenium/utils.py b/notebook/tests/selenium/utils.py index 91cb8ea5a..c3ad3a56b 100644 --- a/notebook/tests/selenium/utils.py +++ b/notebook/tests/selenium/utils.py @@ -239,7 +239,7 @@ class Notebook: # Select & delete anything already in the cell self.current_cell.send_keys(Keys.ENTER) - ctrl(self.browser, 'a') + cmdtrl(self.browser, 'a') self.current_cell.send_keys(Keys.DELETE) for line_no, line in enumerate(content.splitlines()): @@ -355,7 +355,7 @@ def shift(browser, k): """Send key combination Shift+(k)""" trigger_keystrokes(browser, "shift-%s"%k) -def ctrl(browser, k): +def cmdtrl(browser, k): """Send key combination Ctrl+(k) or Command+(k) for MacOS""" trigger_keystrokes(browser, "command-%s"%k) if os.uname()[0] == "Darwin" else trigger_keystrokes(browser, "control-%s"%k)