##// END OF EJS Templates
make casperjs test suite pass again
Paul Ivanov -
Show More
@@ -1,52 +1,54
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:8888';
7 return 'http://127.0.0.1:8888';
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
15 this.waitForSelector('.CodeMirror-code');
14 };
16 };
15
17
16 // Shut down the current notebook's kernel.
18 // Shut down the current notebook's kernel.
17 casper.shutdownCurrentKernel = function () {
19 casper.shutdownCurrentKernel = function () {
18 this.thenEvaluate(function() {
20 this.thenEvaluate(function() {
19 IPython.notebook.kernel.kill();
21 IPython.notebook.kernel.kill();
20 });
22 });
21 };
23 };
22
24
23 // Delete created notebook.
25 // Delete created notebook.
24 casper.deleteCurrentNotebook = function () {
26 casper.deleteCurrentNotebook = function () {
25 this.thenEvaluate(function() {
27 this.thenEvaluate(function() {
26 var nbData = $('body').data();
28 var nbData = $('body').data();
27 var url = nbData.baseProjectUrl + 'notebooks/' + nbData.notebookId;
29 var url = nbData.baseProjectUrl + 'notebooks/' + nbData.notebookId;
28 $.ajax(url, {
30 $.ajax(url, {
29 type: 'DELETE',
31 type: 'DELETE',
30 });
32 });
31 });
33 });
32 };
34 };
33
35
34 // Wrap a notebook test to reduce boilerplate.
36 // Wrap a notebook test to reduce boilerplate.
35 casper.notebookTest = function(test) {
37 casper.notebookTest = function(test) {
36 this.openNewNotebook();
38 this.openNewNotebook();
37 this.then(test);
39 this.then(test);
38 this.shutdownCurrentKernel();
40 this.shutdownCurrentKernel();
39 this.deleteCurrentNotebook();
41 this.deleteCurrentNotebook();
40
42
41 // Run the browser automation.
43 // Run the browser automation.
42 this.run(function() {
44 this.run(function() {
43 this.test.done();
45 this.test.done();
44 });
46 });
45 };
47 };
46
48
47 // Pass `console.log` calls from page JS to casper.
49 // Pass `console.log` calls from page JS to casper.
48 casper.printLog = function () {
50 casper.printLog = function () {
49 this.on('remote.message', function(msg) {
51 this.on('remote.message', function(msg) {
50 this.echo('Remote message caught: ' + msg);
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