From 6c7ad0417e00963dd4cd6500eeb05b69f353feb6 Mon Sep 17 00:00:00 2001 From: TPartida Date: Fri, 10 May 2019 11:49:37 -0700 Subject: [PATCH] Convert execute_code to Selenium --- notebook/tests/selenium/test_execute_code.py | 46 ++++++++++++++++++++ 1 file changed, 46 insertions(+) create mode 100644 notebook/tests/selenium/test_execute_code.py diff --git a/notebook/tests/selenium/test_execute_code.py b/notebook/tests/selenium/test_execute_code.py new file mode 100644 index 000000000..1b9892236 --- /dev/null +++ b/notebook/tests/selenium/test_execute_code.py @@ -0,0 +1,46 @@ +from selenium.webdriver.common.keys import Keys +from .utils import shift, cmdtrl +import time + + +def test_execute_code(notebook): + def get_output_text(index=0): + result = notebook.get_cell_output(index=index) + return result[0].text + + def clear_outputs(): + return notebook.browser.execute_script( + "Jupyter.notebook.clear_all_output();") + + notebook.edit_cell(index=0, content='a=10; print(a)') + notebook.execute_cell(0) + assert get_output_text() == '10', 'cell execute (using js)' + + notebook.edit_cell(index=0, content='a=11; print(a)') + clear_outputs() + shift(notebook.browser, Keys.ENTER) + notebook.delete_cell(index=1) + assert get_output_text() == '11', 'cell execute (using shift-enter)' + + notebook.edit_cell(index=0, content='a=12; print(a)') + clear_outputs() + cmdtrl(notebook.browser, Keys.ENTER) + assert get_output_text() == '12', 'cell execute (using ctrl-enter)' + + notebook.edit_cell(index=0, content='a=13; print(a)') + clear_outputs() + notebook.browser.find_element_by_css_selector( + "button[data-jupyter-action='jupyter-notebook:run-cell-and-select-next']").click() + assert get_output_text() == '13', 'cell execute (cell execute (using "play" toolbar button))' + + notebook.edit_cell(index=0, content='raise IOError') + notebook.edit_cell(index=1, content='a=14; print(a)') + clear_outputs() + notebook.execute_cell(1) + assert get_output_text(1) == '14', "cell execute, don't stop on error" + + clear_outputs() + notebook.browser.execute_script( + "Jupyter.notebook.execute_all_cells;") + assert len(notebook.get_cell_output(index=1)) == 0, "cell execute, stop on error (default)" +