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