Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Nicholas Bollweg
committed
Apr 18, 2016
1 parent
d8aab20
commit 462c38d
Showing
4 changed files
with
99 additions
and
146 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -57,3 +57,5 @@ docs/_build/ | |
target/ | ||
.ipynb_checkpoints/ | ||
node_modules/ | ||
screenshots/ | ||
*.xunit.xml |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,154 +1,99 @@ | ||
/* globals require casper Jupyter */ | ||
var system = require('system'); | ||
;(function(){ | ||
"use strict"; | ||
|
||
var root = casper, | ||
_img = 0, | ||
node_modules = system.env.NBPRESENT_TEST_MODULES || "../../../node_modules", | ||
vendor = root.vendor = root.vendor ? root.vendor : (root.vendor = {}), | ||
_ = vendor._ = require(node_modules + "/lodash"), | ||
_shotDir = "_unnamed"; | ||
var system = require('system'); | ||
|
||
function nextId(){ | ||
return ("000" + (_img++)).slice(-4); | ||
} | ||
var root = casper, | ||
_img = 0, | ||
_shotDir = "unnamed"; | ||
|
||
function slug(text){ | ||
return text.replace(/[^a-z0-9]/g, "_"); | ||
} | ||
|
||
|
||
root.screenshot = function(message){ | ||
return this.captureSelector([ | ||
"screenshots/", | ||
_shotDir, | ||
"/", | ||
nextId(), | ||
"_", | ||
slug(message), | ||
".png" | ||
].join(""), | ||
"body" | ||
); | ||
}; | ||
|
||
|
||
root.screenshot.init = function(ns){ | ||
_shotDir = ns; | ||
_img = 0; | ||
return root; | ||
}; | ||
|
||
|
||
root.canSeeAndClick = function(message, visible, click){ | ||
var things = message; | ||
|
||
if(arguments.length !== 1){ | ||
things = [[message, visible, click]]; | ||
function nextId(){ | ||
return ("000" + (_img++)).slice(-4); | ||
} | ||
|
||
var that = this; | ||
function slug(text){ | ||
return text.replace(/[^a-z0-9]/g, "_"); | ||
} | ||
|
||
things.map(function(thing){ | ||
var message = thing[0], | ||
visible = thing[1], | ||
click = thing[2]; | ||
root.screenshot = function(message){ | ||
this.captureSelector([ | ||
"screenshots/", | ||
_shotDir, | ||
"/", | ||
nextId(), | ||
"_", | ||
slug(message), | ||
".png", | ||
].join(""), | ||
"body" | ||
); | ||
}; | ||
|
||
|
||
root.screenshot.init = function(ns){ | ||
_shotDir = ns; | ||
_img = 0; | ||
}; | ||
|
||
root.canSee = function(message, visible){ | ||
return this | ||
.waitUntilVisible(visible) | ||
.then(function(){ | ||
this.test.assertExists(visible, "I can see " + message); | ||
this.screenshot(message); | ||
}); | ||
} | ||
|
||
that = that | ||
root.canSeeAndClick = function(message, visible, click){ | ||
return this | ||
.waitUntilVisible(visible) | ||
.then(function(){ | ||
this.test.assertExists(click || visible, "I can see and click " + message); | ||
this.screenshot(message); | ||
this.click(click || visible); | ||
}); | ||
}); | ||
|
||
return that; | ||
} | ||
|
||
root.hasMeta = function(path, tests){ | ||
var meta; | ||
|
||
this.thenEvaluate(function () { | ||
require(['base/js/events'], function(events) { | ||
Jupyter._save_success = Jupyter._save_failed = false; | ||
events.on('notebook_saved.Notebook', function () { | ||
Jupyter._save_success = true; | ||
}); | ||
events.on('notebook_save_failed.Notebook', | ||
function (event, error) { | ||
Jupyter._save_failed = "save failed with " + error; | ||
}); | ||
Jupyter.notebook.save_notebook(); | ||
}); | ||
}); | ||
|
||
this.waitFor(function () { | ||
return this.evaluate(function(){ | ||
return Jupyter._save_failed || Jupyter._save_success; | ||
}); | ||
}); | ||
} | ||
|
||
return this | ||
.then(function(){ | ||
meta = this.evaluate(function(){ | ||
return Jupyter.notebook.metadata; | ||
root.dragRelease = function(message, selector, opts){ | ||
var it, x, y, x1, y1; | ||
return this.then(function(){ | ||
it = this.getElementBounds(selector); | ||
x = it.left + it.width / 2; | ||
y = it.top + it.height / 2; | ||
x1 = x + (opts.right || -opts.left || 0); | ||
y1 = y + (opts.down || -opts.up || 0); | ||
}) | ||
.then(function(){ | ||
this.mouse.down(x, y); | ||
}) | ||
.then(function(){ | ||
this.screenshot("click " + message); | ||
this.mouse.move(x1, y1); | ||
}) | ||
.then(function(){ | ||
this.screenshot("drag " + message); | ||
this.mouse.up(x1, y1); | ||
}) | ||
.then(function(){ | ||
this.screenshot("release " + message); | ||
}); | ||
}) | ||
.then(function(){ | ||
_.map(tests, function(test, message){ | ||
var results = test(_.get(meta, path)); | ||
this.test.assertEquals(results[0], results[1], | ||
"I remember " + message + " in " + path); | ||
}, this); | ||
}); | ||
}; | ||
|
||
root.dragRelease = function(message, selector, opts){ | ||
var it, x, y, x1, y1; | ||
return this.then(function(){ | ||
it = this.getElementBounds(selector); | ||
x = it.left + it.width / 2; | ||
y = it.top + it.height / 2; | ||
x1 = x + (opts.right || -opts.left || 0); | ||
y1 = y + (opts.down || -opts.up || 0); | ||
}) | ||
.then(function(){ | ||
this.mouse.down(x, y); | ||
}) | ||
.then(function(){ | ||
this.screenshot("click " + message); | ||
this.mouse.move(x1, y1); | ||
}) | ||
.then(function(){ | ||
this.screenshot("drag " + message); | ||
this.mouse.up(x1, y1); | ||
}) | ||
.then(function(){ | ||
this.screenshot("release " + message); | ||
}); | ||
}; | ||
|
||
root.baseline_notebook = function(){ | ||
// the actual test | ||
|
||
this.append_cell(); | ||
this.set_cell_text(1, [ | ||
'from IPython.display import Markdown', | ||
'Markdown("# Hello World!")' | ||
].join("\n")); | ||
this.execute_cell_then(1); | ||
|
||
this.append_cell(); | ||
this.set_cell_text(2, [ | ||
'from ipywidgets import FloatSlider', | ||
'x = FloatSlider()', | ||
'x' | ||
].join("\n")); | ||
this.execute_cell_then(2); | ||
} | ||
}; | ||
|
||
root.baseline_notebook = function(){ | ||
// the actual test | ||
this.set_cell_text(0, [ | ||
'from IPython.display import Markdown', | ||
'Markdown("# Hello World!")' | ||
].join("\n")); | ||
this.execute_cell_then(0); | ||
|
||
this.append_cell(); | ||
}; | ||
|
||
root.runCell = function(idx, lines){ | ||
// the actual test | ||
this.set_cell_text(idx, lines.join("\n")); | ||
this.execute_cell_then(idx); | ||
} | ||
|
||
root.saveNbpresent = function (){ | ||
return this.thenEvaluate(function(){ | ||
window.nbpresent.mode.metadata(true); | ||
}); | ||
} | ||
}).call(this); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,14 +1,18 @@ | ||
/* global casper */ | ||
casper.notebook_test(function(){ | ||
casper.dashboard_test(function(){ | ||
casper.screenshot.init("basic"); | ||
casper.viewport(1440, 900) | ||
.then(basic_test); | ||
}); | ||
|
||
function basic_test(){ | ||
this.baseline_notebook(); | ||
var pysel = '#new-menu li[id*=Python]', | ||
rsel = '#new-menu li[id*=R ]'; | ||
|
||
return this.then(function(){ | ||
this.canSeeAndClick("the body", "body"); | ||
}); | ||
return this.canSeeAndClick( | ||
"the kernel selector", "#new-buttons > .dropdown-toggle" | ||
) | ||
.canSee("a python kernel", pysel) | ||
.canSee("an r kernel", rsel) | ||
.canSeeAndClick("fin", "body"); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters