public
Created

Simple test of IPython Notebook using phantomjs and casperjs

  • Download Gist
test_basic.js
JavaScript
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64
// Simple IPython Notebook test
// Requires PhantomJS and CasperJS.
// To run:
// 1) Start a notebook server in an empty directory.
// 2) casperjs test_basic.js
 
var casper = require('casper').create({
// verbose: true,
// logLevel: "debug"
});
 
casper.start('http://127.0.0.1:8888',function () {
});
 
casper.thenOpen('http://127.0.0.1:8888/new');
 
casper.then(function () {
this.echo(this.getCurrentUrl());
});
 
casper.then(function () {
this.evaluate(function () {
var cell = IPython.notebook.get_selected_cell();
cell.set_text('a=10; print a');
cell.execute();
});
});
 
casper.wait(2000);
 
casper.then(function () {
var result = this.evaluate(function () {
// This code is run in the pages context.
// All of our custom JavaScript objects can be used.
IPython.notebook.save_notebook();
var cell = IPython.notebook.get_cell(0);
// And jQuery works too!
var output = cell.element.find('.output_area').find('pre').html();
return output
})
// Tests can be written in a familiar form
this.test.assertEquals(result, '10\n', 'stdout output matches')
});
 
casper.back();
 
casper.thenEvaluate(function () {
// Click the Shutdown button.
$('#project_name').next().find('button').click();
})
 
casper.wait(1000);
 
casper.thenEvaluate(function () {
// Click the Delete button and confirm.
$('#project_name').next().find('button').click();
$('.ui-dialog').find('button').first().click();
})
 
casper.wait(1000);
 
casper.run(function () {
this.test.renderResults(true);
});

Please sign in to comment on this gist.

Something went wrong with that request. Please try again.