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