Use waitFor instead of sleeping.

This commit is contained in:
Jonathan Frederic 2014-01-29 17:04:46 -08:00
parent 94636f079e
commit d68112885b
2 changed files with 16 additions and 12 deletions

View File

@ -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});

View File

@ -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.');
});
});