##// END OF EJS Templates
make sure kernel started running
Paul Ivanov -
Show More
@@ -1,81 +1,88 b''
1 1 //
2 2 // Utility functions for the HTML notebook's CasperJS tests.
3 3 //
4 4
5 5 // Get the URL of a notebook server on which to run tests.
6 6 casper.get_notebook_server = function () {
7 7 port = casper.cli.get("port")
8 8 port = (typeof port === 'undefined') ? '8888' : port;
9 9 return 'http://127.0.0.1:' + port
10 10 };
11 11
12 12 // Create and open a new notebook.
13 13 casper.open_new_notebook = function () {
14 14 var baseUrl = this.get_notebook_server();
15 15 this.start(baseUrl);
16 16 this.thenClick('button#new_notebook');
17 17 this.waitForPopup('');
18 18
19 this.withPopup('', function () {this.waitForSelector('.CodeMirror-code');});
19 20 this.then(function () {
20 21 // XXX: Kind of odd, the next line works for one test, but not when
21 22 // running multiple tests back-to-back, so we will just point the main
22 23 // casper browser to the same URL as the popup we just grabbed.
23 24
24 25 //this.page = this.popups[0];
25 26 this.open(this.popups[0].url);
26 27 });
27 28
28 29 // initially, the cells aren't created, so wait for them to appear
29 30 this.waitForSelector('.CodeMirror-code');
31 // and make sure the kernel has started
32 this.waitFor(function kernel_ready() {
33 return this.evaluate(function kernel_ready() {
34 return IPython.notebook.kernel.running;
35 });
36 });
30 37 };
31 38
32 39 // Shut down the current notebook's kernel.
33 40 casper.shutdown_current_kernel = function () {
34 41 this.thenEvaluate(function() {
35 42 IPython.notebook.kernel.kill();
36 43 });
37 44 };
38 45
39 46 // Delete created notebook.
40 47 casper.delete_current_notebook = function () {
41 48 this.thenEvaluate(function() {
42 49 var nbData = $('body').data();
43 50 var url = nbData.baseProjectUrl + 'notebooks/' + nbData.notebookId;
44 51 $.ajax(url, {
45 52 type: 'DELETE',
46 53 });
47 54 });
48 55 };
49 56
50 57 // Wrap a notebook test to reduce boilerplate.
51 58 casper.notebook_test = function(test) {
52 59 this.open_new_notebook();
53 60 this.then(test);
54 61 //XXX: we get sporadic error messages when shutting down some of the tests.
55 62 // Since the entire server will go down at the end of running the test
56 63 // suite, it's ok for now to not try to shut anything down.
57 64 this.shutdown_current_kernel();
58 65
59 66 //XXX: the implementation of delete_current_notebook is currently broken
60 67 // it's not a big deal, since the notebook directory will be deleted on
61 68 // cleanup, but we should add tests for deleting the notebook separately
62 69 //this.delete_current_notebook();
63 70
64 71 // Run the browser automation.
65 72 this.run(function() {
66 73 this.test.done();
67 74 });
68 75 };
69 76
70 77 casper.options.waitTimeout=5000
71 78 casper.on('waitFor.timeout', function onWaitForTimeout(timeout) {
72 79 this.echo("Timeout for " + casper.get_notebook_server());
73 80 this.echo("Is the notebook server running?");
74 81 });
75 82
76 83 // Pass `console.log` calls from page JS to casper.
77 84 casper.printLog = function () {
78 85 this.on('remote.message', function(msg) {
79 86 this.echo('Remote message caught: ' + msg);
80 87 });
81 88 };
General Comments 0
You need to be logged in to leave comments. Login now