Merge pull request #3518 from lmcdon14/selenium-interrupt

Create selenium interrupt test
Thomas Kluyver 7 years ago committed by GitHub
commit 0fba208654
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

@ -255,8 +255,8 @@ data-notebook-path="{{notebook_path | urlencode}}"
</li>
</ul>
</li>
<li class="dropdown"><a href="#" class="dropdown-toggle" data-toggle="dropdown">{% trans %}Kernel{% endtrans %}</a>
<ul id="kernel_menu" class="dropdown-menu">
<li class="dropdown"><a href="#" class="dropdown-toggle" data-toggle="dropdown" id="kernellink">{% trans %}Kernel{% endtrans %}</a>
<ul id="kernel_menu" class="dropdown-menu" aria-labelledby="kernellink">
<li id="int_kernel"
title="{% trans %}Send Keyboard Interrupt (CTRL-C) to the Kernel{% endtrans %}">
<a href="#">{% trans %}Interrupt{% endtrans %}</a>

@ -1,45 +0,0 @@
//
// Test kernel interrupt
//
casper.notebook_test(function () {
this.evaluate(function () {
var cell = IPython.notebook.get_cell(0);
cell.set_text(
'import time'+
'\nfor x in range(3):'+
'\n time.sleep(1)'
);
cell.execute();
});
this.wait_for_busy();
// interrupt using menu item (Kernel -> Interrupt)
this.thenClick('li#int_kernel');
this.wait_for_output(0);
this.then(function () {
var result = this.get_output_cell(0);
this.test.assertEquals(result.ename, 'KeyboardInterrupt', 'keyboard interrupt (mouseclick)');
});
// run cell 0 again, now interrupting using keyboard shortcut
this.thenEvaluate(function () {
var cell = IPython.notebook.get_cell(0);
cell.clear_output();
cell.execute();
});
// interrupt using ii keyboard shortcut
this.then(function(){
this.trigger_keydown('esc', 'i', 'i');
});
this.wait_for_output(0);
this.then(function () {
var result = this.get_output_cell(0);
this.test.assertEquals(result.ename, 'KeyboardInterrupt', 'keyboard interrupt (shortcut)');
});
});

@ -0,0 +1,36 @@
from .utils import wait_for_selector
def interrupt_from_menu(notebook):
# Click interrupt button in kernel menu
notebook.browser.find_element_by_id('kernellink').click()
wait_for_selector(notebook.browser, '#int_kernel', single=True).click()
def interrupt_from_keyboard(notebook):
notebook.body.send_keys("ii")
def test_interrupt(notebook):
""" Test the interrupt function using both the button in the Kernel menu and the keyboard shortcut "ii"
Having trouble accessing the Interrupt message when execution is halted. I am assuming that the
message does not lie in the "outputs" field of the cell's JSON object. Using a timeout work-around for
test with an infinite loop. We know the interrupt function is working if this test passes.
Hope this is a good start.
"""
text = ('import time\n'
'for x in range(3):\n'
' time.sleep(1)')
notebook.edit_cell(index=0, content=text)
for interrupt_method in (interrupt_from_menu, interrupt_from_keyboard):
notebook.clear_cell_output(0)
notebook.to_command_mode()
notebook.execute_cell(0)
interrupt_method(notebook)
# Wait for an output to appear
output = wait_for_selector(notebook.browser, '.output_subarea', single=True)
assert 'KeyboardInterrupt' in output.text

@ -304,6 +304,10 @@ class Notebook:
"return Jupyter.notebook.kernel && Jupyter.notebook.kernel.is_connected()"
)
def clear_cell_output(self, index):
JS = 'Jupyter.notebook.clear_output({})'.format(index)
self.browser.execute_script(JS)
@classmethod
def new_notebook(cls, browser, kernel_name='kernel-python3'):
with new_window(browser, selector=".cell"):

Loading…
Cancel
Save