##// END OF EJS Templates
don't try to delete notebooks...
Paul Ivanov -
Show More
@@ -1,54 +1,57 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.getNotebookServer = function () {
6 casper.getNotebookServer = function () {
7 return 'http://127.0.0.1:' + casper.cli.get("port");
7 return 'http://127.0.0.1:' + casper.cli.get("port");
8 };
8 };
9
9
10 // Create and open a new notebook.
10 // Create and open a new notebook.
11 casper.openNewNotebook = function () {
11 casper.openNewNotebook = function () {
12 var baseUrl = this.getNotebookServer();
12 var baseUrl = this.getNotebookServer();
13 this.start(baseUrl + '/new');
13 this.start(baseUrl + '/new');
14 // initially, the cells aren't created, so wait for them to appear
14 // initially, the cells aren't created, so wait for them to appear
15 this.waitForSelector('.CodeMirror-code');
15 this.waitForSelector('.CodeMirror-code');
16 };
16 };
17
17
18 // Shut down the current notebook's kernel.
18 // Shut down the current notebook's kernel.
19 casper.shutdownCurrentKernel = function () {
19 casper.shutdownCurrentKernel = function () {
20 this.thenEvaluate(function() {
20 this.thenEvaluate(function() {
21 IPython.notebook.kernel.kill();
21 IPython.notebook.kernel.kill();
22 });
22 });
23 };
23 };
24
24
25 // Delete created notebook.
25 // Delete created notebook.
26 casper.deleteCurrentNotebook = function () {
26 casper.deleteCurrentNotebook = function () {
27 this.thenEvaluate(function() {
27 this.thenEvaluate(function() {
28 var nbData = $('body').data();
28 var nbData = $('body').data();
29 var url = nbData.baseProjectUrl + 'notebooks/' + nbData.notebookId;
29 var url = nbData.baseProjectUrl + 'notebooks/' + nbData.notebookId;
30 $.ajax(url, {
30 $.ajax(url, {
31 type: 'DELETE',
31 type: 'DELETE',
32 });
32 });
33 });
33 });
34 };
34 };
35
35
36 // Wrap a notebook test to reduce boilerplate.
36 // Wrap a notebook test to reduce boilerplate.
37 casper.notebookTest = function(test) {
37 casper.notebookTest = function(test) {
38 this.openNewNotebook();
38 this.openNewNotebook();
39 this.then(test);
39 this.then(test);
40 this.shutdownCurrentKernel();
40 this.shutdownCurrentKernel();
41 this.deleteCurrentNotebook();
41 //XXX: the implementation of deleteCurrentNotebook is currently broken
42 // it's not a big deal, since the notebook directory will be deleted on
43 // cleanup, but we should add tests for deleting the notebook separately
44 //this.deleteCurrentNotebook();
42
45
43 // Run the browser automation.
46 // Run the browser automation.
44 this.run(function() {
47 this.run(function() {
45 this.test.done();
48 this.test.done();
46 });
49 });
47 };
50 };
48
51
49 // Pass `console.log` calls from page JS to casper.
52 // Pass `console.log` calls from page JS to casper.
50 casper.printLog = function () {
53 casper.printLog = function () {
51 this.on('remote.message', function(msg) {
54 this.on('remote.message', function(msg) {
52 this.echo('Remote message caught: ' + msg);
55 this.echo('Remote message caught: ' + msg);
53 });
56 });
54 };
57 };
General Comments 0
You need to be logged in to leave comments. Login now