diff --git a/IPython/html/tests/casperjs/util.js b/IPython/html/tests/casperjs/util.js
index d8da2da2d..8abf656ca 100644
--- a/IPython/html/tests/casperjs/util.js
+++ b/IPython/html/tests/casperjs/util.js
@@ -57,15 +57,18 @@ casper.delete_current_notebook = function () {
});
};
-// wait for output in a given cell
-casper.wait_for_output = function (cell_num) {
- this.waitFor(function (c) {
- return this.evaluate(function get_output(c) {
- var cell = IPython.notebook.get_cell(c);
- return cell.output_area.outputs.length != 0;
- },
- // pass parameter from the test suite js to the browser code js
- {c : cell_num});
+// wait for the nth output in a given cell
+casper.wait_for_output = function (cell_num, out_num) {
+ out_num = out_num || 0;
+ this.then(function() {
+ this.waitFor(function (c, o) {
+ return this.evaluate(function get_output(c, o) {
+ var cell = IPython.notebook.get_cell(c);
+ return cell.output_area.outputs.length > o;
+ },
+ // pass parameter from the test suite js to the browser code js
+ {c : cell_num, o : out_num});
+ });
},
function then() { },
function timeout() {