Skip to content

Instantly share code, notes, and snippets.

@rochejul
Created May 31, 2017 08:18
Show Gist options
  • Save rochejul/53036da04052bc1a41ccba254460a44f to your computer and use it in GitHub Desktop.
Save rochejul/53036da04052bc1a41ccba254460a44f to your computer and use it in GitHub Desktop.
Karma custom configuration for PhantomJs (allowing screen size, screenshot, ...)
'use strict';
module.exports = function (config) {
config.set({
// ...
'browsers': ['PhantomJSCustom'],
'customLaunchers': {
'PhantomJSCustom': {
'base': 'PhantomJS',
'options': {
'windowName': 'my-window',
'settings': {
'webSecurityEnabled': false
},
'viewportSize': {
'width': 1920,
'height': 1080
},
'flags': ['--load-images=true'],
'debug': false,
'onCallback': function (data) {
// For screenshot: to use it into the tests: window.top.callPhantom({type: 'render'});
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('./target/screenshot_' + (window.renderId++) + '.png');
}
}
}
}
}
// ...
});
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment