如何配置Karma以使用命令行参数打开浏览器? [英] How can I configure Karma to open a browser with command line arguments?
问题描述
我正在使用Karma Test Runner,并且已将其配置为使用Chrome和PhantomJS,如下所示:
I'm using the Karma Test Runner and I've configured it to use Chrome and PhantomJS like this:
浏览器= ['Chrome','PhantomJS'];
browsers = ['Chrome', 'PhantomJS'];
如何配置Karma以使用某些命令行参数打开这些浏览器,例如在Chrome中使用--diable-web-security,在PhantomJS中使用--web-security = no?
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?
我想一个选择是编写一个自定义浏览器脚本,但是如果Karma中有某些我不知道的功能可以处理这种情况,那似乎就太过分了.
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.
推荐答案
类似的方法应该起作用:
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']
}
}
});
};
此处的更多信息: https://github.com/karma-runner/karma-chrome-launcher #configuration
这篇关于如何配置Karma以使用命令行参数打开浏览器?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!