##// END OF EJS Templates
Add scroll_to_bottom method for TextAreaView (StringWidget).
Add scroll_to_bottom method for TextAreaView (StringWidget).

File last commit:

r14147:d95bbff5
r14393:420434fb
Show More
util.js
210 lines | 6.7 KiB | application/javascript | JavascriptLexer
David Wyde
Add CasperJS utility functions, and tests for code and...
r13249 //
// Utility functions for the HTML notebook's CasperJS tests.
//
// Get the URL of a notebook server on which to run tests.
Paul Ivanov
pep8 style function names
r13275 casper.get_notebook_server = function () {
Paul Ivanov
updated js tests README, --port= now optional
r13271 port = casper.cli.get("port")
port = (typeof port === 'undefined') ? '8888' : port;
return 'http://127.0.0.1:' + port
David Wyde
Add CasperJS utility functions, and tests for code and...
r13249 };
// Create and open a new notebook.
Paul Ivanov
pep8 style function names
r13275 casper.open_new_notebook = function () {
var baseUrl = this.get_notebook_server();
Paul Ivanov
use dashboard to simulate clicking new notebook
r13284 this.start(baseUrl);
this.thenClick('button#new_notebook');
this.waitForPopup('');
Paul Ivanov
make sure kernel started running
r13290 this.withPopup('', function () {this.waitForSelector('.CodeMirror-code');});
Paul Ivanov
use dashboard to simulate clicking new notebook
r13284 this.then(function () {
// XXX: Kind of odd, the next line works for one test, but not when
// running multiple tests back-to-back, so we will just point the main
// casper browser to the same URL as the popup we just grabbed.
//this.page = this.popups[0];
this.open(this.popups[0].url);
});
Paul Ivanov
make casperjs test suite pass again
r13258 // initially, the cells aren't created, so wait for them to appear
this.waitForSelector('.CodeMirror-code');
Paul Ivanov
make sure kernel started running
r13290 // and make sure the kernel has started
Paul Ivanov
created a kernel_running method
r13302 this.waitFor( this.kernel_running );
};
// return whether or not the kernel is running
casper.kernel_running = function kernel_running() {
return this.evaluate(function kernel_running() {
return IPython.notebook.kernel.running;
Paul Ivanov
make sure kernel started running
r13290 });
David Wyde
Add CasperJS utility functions, and tests for code and...
r13249 };
// Shut down the current notebook's kernel.
Paul Ivanov
pep8 style function names
r13275 casper.shutdown_current_kernel = function () {
David Wyde
Add CasperJS utility functions, and tests for code and...
r13249 this.thenEvaluate(function() {
David Wyde
Use existing IPython method to kill kernels.
r13255 IPython.notebook.kernel.kill();
David Wyde
Add CasperJS utility functions, and tests for code and...
r13249 });
};
// Delete created notebook.
Paul Ivanov
pep8 style function names
r13275 casper.delete_current_notebook = function () {
David Wyde
Add CasperJS utility functions, and tests for code and...
r13249 this.thenEvaluate(function() {
var nbData = $('body').data();
var url = nbData.baseProjectUrl + 'notebooks/' + nbData.notebookId;
$.ajax(url, {
type: 'DELETE',
});
});
};
Paul Ivanov
wait_for_output utility function
r13294 // wait for output in a given cell
casper.wait_for_output = function (cell_num) {
this.then(function() {
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});
Paul Ivanov
yet another JS race condition fix...
r13463 },
function then() { },
function timeout() {
this.echo("wait_for_output timedout!");
Paul Ivanov
wait_for_output utility function
r13294 });
});
};
Paul Ivanov
refactor of get_output_cell
r13299 // return the output of a given cell
Paul Ivanov
add test for custom mimetypes
r14147 casper.get_output_cell = function (cell_num, out_num) {
out_num = out_num || 0;
var result = casper.evaluate(function (c, o) {
Paul Ivanov
refactor of get_output_cell
r13299 var cell = IPython.notebook.get_cell(c);
Paul Ivanov
add test for custom mimetypes
r14147 return cell.output_area.outputs[o];
Paul Ivanov
refactor of get_output_cell
r13299 },
Paul Ivanov
add test for custom mimetypes
r14147 {c : cell_num, o : out_num});
Paul Ivanov
refactor of get_output_cell
r13299 return result;
};
Paul Ivanov
add checks for new cell added using shift-enter
r13300 // return the number of cells in the notebook
casper.get_cells_length = function () {
var result = casper.evaluate(function () {
return IPython.notebook.get_cells().length;
})
return result;
};
Jonathan Frederic
Added new utility functions to the casper.js testing utils.
r13765 // Set the text content of a cell.
casper.set_cell_text = function(index, text){
this.evaluate(function (index, text) {
var cell = IPython.notebook.get_cell(index);
cell.set_text(text);
}, index, text);
};
Jonathan Frederic
Fixed bug where cell was not getting inserted because index is optional.
r13766 // Inserts a cell at the bottom of the notebook
// Returns the new cell's index.
casper.insert_cell_at_bottom = function(cell_type){
if (cell_type===undefined) {
cell_type = 'code';
}
return this.evaluate(function (cell_type) {
var cell = IPython.notebook.insert_cell_at_bottom(cell_type);
return IPython.notebook.find_cell_index(cell);
}, cell_type);
};
Jonathan Frederic
Added new utility functions to the casper.js testing utils.
r13765 // Insert a cell at the bottom of the notebook and set the cells text.
// Returns the new cell's index.
casper.append_cell = function(text, cell_type) {
Jonathan Frederic
Fixed bug where cell was not getting inserted because index is optional.
r13766 var index = this.insert_cell_at_bottom(cell_type);
Jonathan Frederic
Added new utility functions to the casper.js testing utils.
r13765 if (text !== undefined) {
Jonathan Frederic
Fixed bug where cell was not getting inserted because index is optional.
r13766 this.set_cell_text(index, text);
Jonathan Frederic
Added new utility functions to the casper.js testing utils.
r13765 }
return index;
};
// Asynchronously executes a cell by index.
// Returns the cell's index.
casper.execute_cell = function(index){
var that = this;
this.then(function(){
that.evaluate(function (index) {
var cell = IPython.notebook.get_cell(index);
cell.execute();
}, index);
});
return index;
};
// Synchronously executes a cell by index.
// Optionally accepts a then_callback parameter. then_callback will get called
// when the cell has finished executing.
// Returns the cell's index.
casper.execute_cell_then = function(index, then_callback) {
Jonathan Frederic
Fixed bug where cell was not getting inserted because index is optional.
r13766 var return_val = this.execute_cell(index);
Jonathan Frederic
Added new utility functions to the casper.js testing utils.
r13765
this.wait_for_output(index);
var that = this;
this.then(function(){
if (then_callback!==undefined) {
then_callback.apply(that, [index]);
}
});
return return_val;
};
// Utility function that allows us to easily check if an element exists
// within a cell. Uses JQuery selector to look for the element.
casper.cell_element_exists = function(index, selector){
return casper.evaluate(function (index, selector) {
var $cell = IPython.notebook.get_cell(index).element;
return $cell.find(selector).length > 0;
}, index, selector);
};
// Utility function that allows us to execute a jQuery function on an
// element within a cell.
casper.cell_element_function = function(index, selector, function_name, function_args){
return casper.evaluate(function (index, selector, function_name, function_args) {
var $cell = IPython.notebook.get_cell(index).element;
var $el = $cell.find(selector);
return $el[function_name].apply($el, function_args);
}, index, selector, function_name, function_args);
};
David Wyde
Wrap CasperJS tests in a helper function to reduce boilerplate.
r13253 // Wrap a notebook test to reduce boilerplate.
Paul Ivanov
pep8 style function names
r13275 casper.notebook_test = function(test) {
this.open_new_notebook();
David Wyde
Wrap CasperJS tests in a helper function to reduce boilerplate.
r13253 this.then(test);
Paul Ivanov
don't shutdown kernel after every test
r13285 //XXX: we get sporadic error messages when shutting down some of the tests.
// Since the entire server will go down at the end of running the test
// suite, it's ok for now to not try to shut anything down.
Paul Ivanov
try to shutdown at the end of every notebook run...
r13288 this.shutdown_current_kernel();
Paul Ivanov
don't shutdown kernel after every test
r13285
Paul Ivanov
pep8 style function names
r13275 //XXX: the implementation of delete_current_notebook is currently broken
Paul Ivanov
don't shutdown kernel after every test
r13285 // it's not a big deal, since the notebook directory will be deleted on
// cleanup, but we should add tests for deleting the notebook separately
Paul Ivanov
pep8 style function names
r13275 //this.delete_current_notebook();
David Wyde
Wrap CasperJS tests in a helper function to reduce boilerplate.
r13253
// Run the browser automation.
this.run(function() {
this.test.done();
});
};
Paul Ivanov
give travis 10 seconds to start server
r13309 casper.options.waitTimeout=10000
Paul Ivanov
more informative message on server timeout
r13272 casper.on('waitFor.timeout', function onWaitForTimeout(timeout) {
Paul Ivanov
pep8 style function names
r13275 this.echo("Timeout for " + casper.get_notebook_server());
Paul Ivanov
more informative message on server timeout
r13272 this.echo("Is the notebook server running?");
});
David Wyde
Add CasperJS utility functions, and tests for code and...
r13249 // Pass `console.log` calls from page JS to casper.
casper.printLog = function () {
this.on('remote.message', function(msg) {
this.echo('Remote message caught: ' + msg);
});
};