Skip to content
This repository

Notebook CasperJS tests #3125

Closed
wants to merge 8 commits into from

5 participants

David Wyde Brian E. Granger Matthias Bussonnier Paul Ivanov Min RK
David Wyde
dwyde commented April 02, 2013

[ not for 1.0 ]

This PR is a starting point for testing the notebook with CasperJS.

See also:
https://github.com/ipython/ipython/wiki/IPEP-14:-Notebook-Regression-Tests

Brian E. Granger
Owner

I am +1 on this idea - will try to provide some details code review soon.

Matthias Bussonnier
Collaborator
David Wyde
dwyde commented April 03, 2013

Each test starts in an empty browser, then openNewNotebook() loads the notebook page.

Good point about key codes, and it looks like they're already in jQuery UI.

Brian E. Granger
Owner

OK for this PR we get the "worse code review responsiveness of the year" award. Paul, you are the lead on our JavaScript testing work for 2.0. It would be great to get that work started. Could you have a look at this PR and maybe use it as a started point for that?

Brian E. Granger
Owner

Opps, I meant to ping @ivanov in my last comment, not just mention his name...

Paul Ivanov
Collaborator

on it - this morning I actually started to pick back up the work on dexy that we started back at the dev meeting, and came to this PR just now to review what had happened here.

Brian E. Granger
Owner

Thanks!

Paul Ivanov ivanov referenced this pull request from a commit September 24, 2013
Commit has since been removed from the repository and is no longer available.
Paul Ivanov ivanov referenced this pull request from a commit in ivanov/ipython September 24, 2013
Paul Ivanov jstest moved to new place, closes #3125 fbc65bf
Brian E. Granger ellisonbg referenced this pull request September 26, 2013
Merged

Notebook javascript test suite using CasperJS #4285

11 of 15 tasks complete
Min RK
Owner

this work will be finished up in #4285

Min RK minrk closed this September 26, 2013
Paul Ivanov ivanov referenced this pull request from a commit in ivanov/ipython September 24, 2013
Paul Ivanov jstest moved to new place, closes #3125 8b549e7
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
This page is out of date. Refresh to see the latest.
13  IPython/frontend/html/notebook/tests/casperjs/README.md
Source Rendered
... ...
@@ -0,0 +1,13 @@
  1
+Regression tests for the web notebook. These tests depend on
  2
+[CasperJS](http://casperjs.org/), which in turn requires
  3
+a recent version of [PhantomJS](http://phantomjs.org/).
  4
+
  5
+Run the tests:
  6
+
  7
+```sh
  8
+/path/to/bin/casperjs test --includes=util.js test_cases
  9
+```
  10
+
  11
+The file `util.js` contains utility functions for tests,
  12
+including a hardcoded path to a running notebook server
  13
+(http://127.0.0.1:8888 by default).
22  IPython/frontend/html/notebook/tests/casperjs/test_cases/empty_nb_arrow_keys.js
... ...
@@ -0,0 +1,22 @@
  1
+//
  2
+// Check for errors with up and down arrow presses in an empty notebook.
  3
+//
  4
+casper.notebookTest(function () {
  5
+    var result = this.evaluate(function() {
  6
+        var ncells = IPython.notebook.ncells(),
  7
+            i;
  8
+        
  9
+        // Delete all cells.
  10
+        for (i = 0; i < ncells; i++) {
  11
+            IPython.notebook.delete_cell();
  12
+        }
  13
+        
  14
+        // Simulate the "up arrow" and "down arrow" keys.
  15
+        var up_press = $.Event('keydown', {which: $.ui.keyCode.UP});
  16
+        $(document).trigger(up_press);
  17
+        var down_press = $.Event('keydown', {which: $.ui.keyCode.DOWN});
  18
+        $(document).trigger(down_press);
  19
+        return true;
  20
+    });
  21
+    this.test.assertTrue(result, 'Up/down arrow okay in empty notebook.');
  22
+});
21  IPython/frontend/html/notebook/tests/casperjs/test_cases/execute_code_cell.js
... ...
@@ -0,0 +1,21 @@
  1
+//
  2
+// Test code cell execution.
  3
+//
  4
+casper.notebookTest(function () {
  5
+    this.evaluate(function () {
  6
+        var cell = IPython.notebook.get_selected_cell();
  7
+        cell.set_text('a=10; print a');
  8
+        cell.execute();
  9
+    });
  10
+
  11
+    this.wait(2000);
  12
+
  13
+    this.then(function () {
  14
+        var result = this.evaluate(function () {
  15
+            var cell = IPython.notebook.get_cell(0);
  16
+            var output = cell.element.find('.output_area').find('pre').html();
  17
+            return output;
  18
+        })
  19
+        this.test.assertEquals(result, '10\n', 'stdout output matches')
  20
+    });
  21
+});
37  IPython/frontend/html/notebook/tests/casperjs/test_cases/merge_cells.js
... ...
@@ -0,0 +1,37 @@
  1
+//
  2
+// Test merging two notebook cells.
  3
+//
  4
+casper.notebookTest(function() {
  5
+    var output = this.evaluate(function () {
  6
+        // Fill in test data.
  7
+        var set_cell_text = function () {
  8
+            var cell_one = IPython.notebook.get_selected_cell();
  9
+            cell_one.set_text('a = 5');
  10
+            
  11
+            IPython.notebook.insert_cell_below('code');
  12
+            var cell_two = IPython.notebook.get_selected_cell();
  13
+            cell_two.set_text('print a');
  14
+        };
  15
+        
  16
+        // merge_cell_above()
  17
+        set_cell_text();
  18
+        IPython.notebook.merge_cell_above();
  19
+        var merged_above = IPython.notebook.get_selected_cell();
  20
+        
  21
+        // merge_cell_below()
  22
+        set_cell_text();
  23
+        IPython.notebook.select(0);
  24
+        IPython.notebook.merge_cell_below();
  25
+        var merged_below = IPython.notebook.get_selected_cell();
  26
+        
  27
+        return {
  28
+            above: merged_above.get_text(),
  29
+            below: merged_below.get_text()
  30
+        };
  31
+    });
  32
+    
  33
+    this.test.assertEquals(output.above, 'a = 5\nprint a',
  34
+                           'Successful insert_cell_above().');
  35
+    this.test.assertEquals(output.below, 'a = 5\nprint a',
  36
+                           'Successful insert_cell_below().');
  37
+});
36  IPython/frontend/html/notebook/tests/casperjs/test_cases/render_markdown.js
... ...
@@ -0,0 +1,36 @@
  1
+//
  2
+// Test that a Markdown cell is rendered to HTML.
  3
+//
  4
+casper.notebookTest(function () {
  5
+    // Test JavaScript models.
  6
+    var output = this.evaluate(function () {
  7
+        IPython.notebook.to_markdown();
  8
+        var cell = IPython.notebook.get_selected_cell();
  9
+        cell.set_text('# Foo');
  10
+        cell.render();
  11
+        return cell.get_rendered();
  12
+    });
  13
+    this.test.assertEquals(output, '<h1>Foo</h1>', 'Markdown JS API works.');
  14
+    
  15
+    // Test menubar entries.
  16
+    output = this.evaluate(function () {
  17
+        $('#to_code').mouseenter().click();
  18
+        $('#to_markdown').mouseenter().click();
  19
+        var cell = IPython.notebook.get_selected_cell();
  20
+        cell.set_text('# Foo');
  21
+        $('#run_cell').mouseenter().click();
  22
+        return cell.get_rendered();
  23
+    });
  24
+    this.test.assertEquals(output, '<h1>Foo</h1>', 'Markdown menubar items work.');
  25
+    
  26
+    // Test toolbar buttons.
  27
+    output = this.evaluate(function () {
  28
+        $('#cell_type').val('code').change();
  29
+        $('#cell_type').val('markdown').change();
  30
+        var cell = IPython.notebook.get_selected_cell();
  31
+        cell.set_text('# Foo');
  32
+        $('#run_b').click();
  33
+        return cell.get_rendered();
  34
+    });
  35
+    this.test.assertEquals(output, '<h1>Foo</h1>', 'Markdown toolbar items work.');
  36
+});
52  IPython/frontend/html/notebook/tests/casperjs/util.js
... ...
@@ -0,0 +1,52 @@
  1
+//
  2
+// Utility functions for the HTML notebook's CasperJS tests.
  3
+//
  4
+
  5
+// Get the URL of a notebook server on which to run tests.
  6
+casper.getNotebookServer = function () {
  7
+    return 'http://127.0.0.1:8888';
  8
+};
  9
+
  10
+// Create and open a new notebook.
  11
+casper.openNewNotebook = function () {
  12
+    var baseUrl = this.getNotebookServer();
  13
+    this.start(baseUrl + '/new');
  14
+};
  15
+
  16
+// Shut down the current notebook's kernel.
  17
+casper.shutdownCurrentKernel = function () {
  18
+    this.thenEvaluate(function() {
  19
+        IPython.notebook.kernel.kill();
  20
+    });
  21
+};
  22
+
  23
+// Delete created notebook.
  24
+casper.deleteCurrentNotebook = function () {
  25
+    this.thenEvaluate(function() {
  26
+        var nbData = $('body').data();
  27
+        var url = nbData.baseProjectUrl + 'notebooks/' + nbData.notebookId;
  28
+        $.ajax(url, {
  29
+            type: 'DELETE',
  30
+        });
  31
+    });
  32
+};
  33
+
  34
+// Wrap a notebook test to reduce boilerplate.
  35
+casper.notebookTest = function(test) {
  36
+    this.openNewNotebook();
  37
+    this.then(test);
  38
+    this.shutdownCurrentKernel();
  39
+    this.deleteCurrentNotebook();
  40
+    
  41
+    // Run the browser automation.
  42
+    this.run(function() {
  43
+        this.test.done();
  44
+    });
  45
+};
  46
+
  47
+// Pass `console.log` calls from page JS to casper.
  48
+casper.printLog = function () {
  49
+    this.on('remote.message', function(msg) {
  50
+        this.echo('Remote message caught: ' + msg);
  51
+    });
  52
+};
Commit_comment_tip

Tip: You can add notes to lines in a file. Hover to the left of a line to make a note

Something went wrong with that request. Please try again.