I need a way to take a screenshot during a test which uses QUnit and Karma to run inside PhantomJS 2.0.1
I\'ve found this command:
window.top.callPhantom
My Karma entry for a customized phantomjs that takes snapshots looked like this:
module.exports = function (config) {
config.set({
..
browsers: [ 'PhantomJSCustom'],
customLaunchers: {
'PhantomJSCustom': {
base: 'PhantomJS',
options: {
onCallback: function(data){
if (data.type === "render") {
// this function will not have the scope of karma.conf.js so we must define any global variable inside it
if (window.renderId === undefined) { window.renderId = 0; }
page.render(data.fname || ("screenshot_" + (window.renderId++) + ".png"));
}
}
}
}
},
phantomjsLauncher: {
// Have phantomjs exit if a ResourceError is encountered (useful if karma exits without killing // phantom)
exitOnResourceError: true
},
..
})