在下面的代码中,我注册了一个任务“myprotractor”,任务之后作为参数的任何内容都将作为参数进入匿名函数:
咕哝我的量角器:开发:密码
module.exports = function(grunt) {
grunt.registerTask('myprotractor', function(user, pwd) {
console.log(user + pwd);
grunt.config('protractor', {
options: {
keepAlive: true,
configFile: "test/config.js",
args: {
params: {
user: user,
password: pwd
}
}
}
});
//here I am running the task
grunt.task.run([
'protractor'
]);
});
};
如果您需要,您可以为量角器配置 2 个目标,具有一些通用配置,并且根据您希望从 cmd 还是从 config 设置 args。
咕哝着我的量角器:cmd:dev:pwd
module.exports = function(grunt) {
grunt.registerTask('myprotractor', function(target, user, pwd) {
console.log(user + pwd);
grunt.config('protractor', {
options: {
keepAlive: true,
configFile: "test/config.js"
},
cmd: {
options: {
args: {
params: {
user: user,
password: pwd
}
}
}
},
config: {}
});
//here I am running the task with a target
grunt.task.run([
'protractor:' + target
]);
});
};