I'm using the Karma Test Runner and I've configured it to use Chrome and PhantomJS like this:
browsers = ['Chrome', 'PhantomJS'];
How can I configure Karma to open these browsers with certain command line arguments, like --diable-web-security in the case of Chrome, and --web-security=no in the case of PhantomJS?
I suppose one option would be to write a custom browser script, but that seems like overkill if there is some feature in Karma I don't know about that handles this case.
In order to serve you well, Karma needs to know about your project in order to test it and this is done via a configuration file. The easiest way to generate an initial configuration file is by using the karma init command. This page lists all of the available configuration options.
Correct - Karma requires a browser to run. BUT - you can run Chrome in Headless mode, which means although you do need the browser installed, it will not open it's UI, and you can therefore run the tests purely through an SSH session for example.
Most of the framework adapters, reporters, preprocessors and launchers needs to be loaded as plugins. The Karma configuration file can be written in JavaScript or CoffeeScript and is loaded as a regular Node. js module. Within the configuration file, the configuration code is put together by setting module.
Setting singleRun: false assumes that you are explicitly start the karma-client manually. This means that you start karma (technically the karma-server), then go to another terminal and type karma run . Setting singleRun: true in your karma configuration will call karma run for you.
Something like this should work:
// karma.conf.js
module.exports = function(config) {
config.set({
browsers: ['Chrome_without_security','PhantomJS_without_security'],
// you can define custom flags
customLaunchers: {
Chrome_without_security: {
base: 'Chrome',
flags: ['--disable-web-security']
},
PhantomJS_without_security: {
base: 'PhantomJS',
flags: ['--web-security=no']
}
}
});
};
More information here: https://github.com/karma-runner/karma-chrome-launcher#configuration
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With