From 07daa50b571558d747ce0d4ddbe751c89c3686fc 2014-01-30 23:23:58 From: Jonathan Frederic Date: 2014-01-30 23:23:58 Subject: [PATCH] Use waitFor instead of sleeping. --- diff --git a/IPython/html/tests/casperjs/test_cases/widgets.js b/IPython/html/tests/casperjs/test_cases/widgets.js index 115e467..19afaf9 100644 --- a/IPython/html/tests/casperjs/test_cases/widgets.js +++ b/IPython/html/tests/casperjs/test_cases/widgets.js @@ -16,8 +16,6 @@ casper.notebook_test(function () { 'print("Success")'); this.execute_cell_then(index); - this.wait(500); // Wait for require.js async callbacks to load dependencies. - this.then(function () { // Check if the widget manager has been instantiated. this.test.assert(this.evaluate(function() { @@ -28,7 +26,7 @@ casper.notebook_test(function () { throttle_index = this.append_cell( 'import time\n' + 'textbox = widgets.TextWidget()\n' + - 'display(textbox)\n'+ + 'display(textbox)\n' + 'textbox.add_class("my-throttle-textbox")\n' + 'def handle_change(name, old, new):\n' + ' print(len(new))\n' + @@ -47,12 +45,17 @@ casper.notebook_test(function () { '.my-throttle-textbox'), 'Textbox exists.'); // Send 20 characters - this.sendKeys('.my-throttle-textbox', '....................'); + this.sendKeys('.my-throttle-textbox', '...................A'); }); - this.wait(2000); // Wait for clicks to execute in kernel - - this.then(function(){ + this.waitFor(function check() { + var outputs = this.evaluate(function(i) { + return IPython.notebook.get_cell(i).output_area.outputs; + }, {i : throttle_index}); + var output = outputs[outputs.length-1].text; + return (output[output.length-1] == 'A'); + + }, function then() { var outputs = this.evaluate(function(i) { return IPython.notebook.get_cell(i).output_area.outputs; }, {i : throttle_index}); diff --git a/IPython/html/tests/casperjs/test_cases/widgets_button.js b/IPython/html/tests/casperjs/test_cases/widgets_button.js index aca1b90..13a29fb 100644 --- a/IPython/html/tests/casperjs/test_cases/widgets_button.js +++ b/IPython/html/tests/casperjs/test_cases/widgets_button.js @@ -34,10 +34,11 @@ casper.notebook_test(function () { '.widget-area .widget-subarea button', 'click'); }); - this.wait(500); // Wait for click to execute in kernel and write output - - this.then(function () { - this.test.assertEquals(this.get_output_cell(button_index, 1).text, 'Clicked\n', - 'Button click event fires.'); + this.waitFor(function check() { + return (this.get_output_cell(button_index, 1).text == 'Clicked\n'); + }, function then() { + this.test.assert(true, 'Button click event fires.'); + }), function timeout() { + this.test.assert(false, 'Button click event fires.'); }); }); \ No newline at end of file