Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP

Loading…

Notebook CasperJS tests #3125

Closed
wants to merge 8 commits into from

5 participants

@dwyde

[ 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

@ellisonbg
Owner

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

@Carreau
Owner
@dwyde

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.

@ellisonbg
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?

@ellisonbg
Owner

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

@ivanov
Owner

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.

@ellisonbg
Owner

Thanks!

@ivanov ivanov referenced this pull request from a commit
Commit has since been removed from the repository and is no longer available.
@ivanov ivanov referenced this pull request from a commit in ivanov/ipython
@ivanov ivanov jstest moved to new place, closes #3125 fbc65bf
@ellisonbg ellisonbg referenced this pull request
Merged

Notebook javascript test suite using CasperJS #4285

11 of 15 tasks complete
@minrk
Owner

this work will be finished up in #4285

@minrk minrk closed this
@ivanov ivanov referenced this pull request from a commit in ivanov/ipython
@ivanov ivanov jstest moved to new place, closes #3125 8b549e7
@mattvonrocketstein mattvonrocketstein referenced this pull request from a commit in mattvonrocketstein/ipython
@ivanov ivanov jstest moved to new place, closes #3125 6911c8b
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.
View
13 IPython/frontend/html/notebook/tests/casperjs/README.md
@@ -0,0 +1,13 @@
+Regression tests for the web notebook. These tests depend on
+[CasperJS](http://casperjs.org/), which in turn requires
+a recent version of [PhantomJS](http://phantomjs.org/).
+
+Run the tests:
+
+```sh
+/path/to/bin/casperjs test --includes=util.js test_cases
+```
+
+The file `util.js` contains utility functions for tests,
+including a hardcoded path to a running notebook server
+(http://127.0.0.1:8888 by default).
View
22 IPython/frontend/html/notebook/tests/casperjs/test_cases/empty_nb_arrow_keys.js
@@ -0,0 +1,22 @@
+//
+// Check for errors with up and down arrow presses in an empty notebook.
+//
+casper.notebookTest(function () {
+ var result = this.evaluate(function() {
+ var ncells = IPython.notebook.ncells(),
+ i;
+
+ // Delete all cells.
+ for (i = 0; i < ncells; i++) {
+ IPython.notebook.delete_cell();
+ }
+
+ // Simulate the "up arrow" and "down arrow" keys.
+ var up_press = $.Event('keydown', {which: $.ui.keyCode.UP});
+ $(document).trigger(up_press);
+ var down_press = $.Event('keydown', {which: $.ui.keyCode.DOWN});
+ $(document).trigger(down_press);
+ return true;
+ });
+ this.test.assertTrue(result, 'Up/down arrow okay in empty notebook.');
+});
View
21 IPython/frontend/html/notebook/tests/casperjs/test_cases/execute_code_cell.js
@@ -0,0 +1,21 @@
+//
+// Test code cell execution.
+//
+casper.notebookTest(function () {
+ this.evaluate(function () {
+ var cell = IPython.notebook.get_selected_cell();
+ cell.set_text('a=10; print a');
+ cell.execute();
+ });
+
+ this.wait(2000);
+
+ this.then(function () {
+ var result = this.evaluate(function () {
+ var cell = IPython.notebook.get_cell(0);
+ var output = cell.element.find('.output_area').find('pre').html();
+ return output;
+ })
+ this.test.assertEquals(result, '10\n', 'stdout output matches')
+ });
+});
View
37 IPython/frontend/html/notebook/tests/casperjs/test_cases/merge_cells.js
@@ -0,0 +1,37 @@
+//
+// Test merging two notebook cells.
+//
+casper.notebookTest(function() {
+ var output = this.evaluate(function () {
+ // Fill in test data.
+ var set_cell_text = function () {
+ var cell_one = IPython.notebook.get_selected_cell();
+ cell_one.set_text('a = 5');
+
+ IPython.notebook.insert_cell_below('code');
+ var cell_two = IPython.notebook.get_selected_cell();
+ cell_two.set_text('print a');
+ };
+
+ // merge_cell_above()
+ set_cell_text();
+ IPython.notebook.merge_cell_above();
+ var merged_above = IPython.notebook.get_selected_cell();
+
+ // merge_cell_below()
+ set_cell_text();
+ IPython.notebook.select(0);
+ IPython.notebook.merge_cell_below();
+ var merged_below = IPython.notebook.get_selected_cell();
+
+ return {
+ above: merged_above.get_text(),
+ below: merged_below.get_text()
+ };
+ });
+
+ this.test.assertEquals(output.above, 'a = 5\nprint a',
+ 'Successful insert_cell_above().');
+ this.test.assertEquals(output.below, 'a = 5\nprint a',
+ 'Successful insert_cell_below().');
+});
View
36 IPython/frontend/html/notebook/tests/casperjs/test_cases/render_markdown.js
@@ -0,0 +1,36 @@
+//
+// Test that a Markdown cell is rendered to HTML.
+//
+casper.notebookTest(function () {
+ // Test JavaScript models.
+ var output = this.evaluate(function () {
+ IPython.notebook.to_markdown();
+ var cell = IPython.notebook.get_selected_cell();
+ cell.set_text('# Foo');
+ cell.render();
+ return cell.get_rendered();
+ });
+ this.test.assertEquals(output, '<h1>Foo</h1>', 'Markdown JS API works.');
+
+ // Test menubar entries.
+ output = this.evaluate(function () {
+ $('#to_code').mouseenter().click();
+ $('#to_markdown').mouseenter().click();
+ var cell = IPython.notebook.get_selected_cell();
+ cell.set_text('# Foo');
+ $('#run_cell').mouseenter().click();
+ return cell.get_rendered();
+ });
+ this.test.assertEquals(output, '<h1>Foo</h1>', 'Markdown menubar items work.');
+
+ // Test toolbar buttons.
+ output = this.evaluate(function () {
+ $('#cell_type').val('code').change();
+ $('#cell_type').val('markdown').change();
+ var cell = IPython.notebook.get_selected_cell();
+ cell.set_text('# Foo');
+ $('#run_b').click();
+ return cell.get_rendered();
+ });
+ this.test.assertEquals(output, '<h1>Foo</h1>', 'Markdown toolbar items work.');
+});
View
52 IPython/frontend/html/notebook/tests/casperjs/util.js
@@ -0,0 +1,52 @@
+//
+// Utility functions for the HTML notebook's CasperJS tests.
+//
+
+// Get the URL of a notebook server on which to run tests.
+casper.getNotebookServer = function () {
+ return 'http://127.0.0.1:8888';
+};
+
+// Create and open a new notebook.
+casper.openNewNotebook = function () {
+ var baseUrl = this.getNotebookServer();
+ this.start(baseUrl + '/new');
+};
+
+// Shut down the current notebook's kernel.
+casper.shutdownCurrentKernel = function () {
+ this.thenEvaluate(function() {
+ IPython.notebook.kernel.kill();
+ });
+};
+
+// Delete created notebook.
+casper.deleteCurrentNotebook = function () {
+ this.thenEvaluate(function() {
+ var nbData = $('body').data();
+ var url = nbData.baseProjectUrl + 'notebooks/' + nbData.notebookId;
+ $.ajax(url, {
+ type: 'DELETE',
+ });
+ });
+};
+
+// Wrap a notebook test to reduce boilerplate.
+casper.notebookTest = function(test) {
+ this.openNewNotebook();
+ this.then(test);
+ this.shutdownCurrentKernel();
+ this.deleteCurrentNotebook();
+
+ // Run the browser automation.
+ this.run(function() {
+ this.test.done();
+ });
+};
+
+// Pass `console.log` calls from page JS to casper.
+casper.printLog = function () {
+ this.on('remote.message', function(msg) {
+ this.echo('Remote message caught: ' + msg);
+ });
+};
Something went wrong with that request. Please try again.