我正在使用Grunt运行量角器端到端测试用例。我有以下三个任务(我使用的是Windows 7机器)
我正在尝试按照上面提到的顺序运行这三个任务。然而问题是在#webdriver-start进程中咕噜咕噜,并且不让#protractor-start进程运行。以下是我的咕噜配置。请帮忙。
/**
* New node file
*/
module.exports = function(grunt){
//globalConfig and paths which will used in the grunt script
var config={
srcFolderName: 'src',
distFolderName: 'dist',
appFileName: 'server.js',
nodeModuleFolderName: 'node_modules',
testSourceFolderName: 'src-test',
testDestFolderName: 'Test',
//change this command based on project requirement
apiDocCommand:'apidoc -i src/server -o apidoc',
npmInstallCommand: 'npm install --prefix ./dist/<%= pkg.name %>/node_modules',
protractorPath:'./node_modules/protractor'
}
//init
grunt.initConfig({
config:config,
pkg: grunt.file.readJSON('package.json'),
copy: {
//copy all source files to distribution folder
sourceFiles: {
cwd: '<%= config.srcFolderName %>',
src: [ '**' ],
dest: '<%= config.distFolderName %>/<%= pkg.name %>',
expand: true
},
//copy main app file to dist folder
mainAppFile: {
src: '<%= config.appFileName %>',
dest: '<%= config.distFolderName %>/<%= pkg.name %>/<%= config.appFileName %>'
},
copyPackage:{
src: 'package.json',
dest: '<%= config.distFolderName %>/<%= pkg.name %>/package.json'
},
//copy all source test files to distribution folder
testFiles: {
cwd: '<%= config.testSourceFolderName %>',
src: [ '**' ],
dest: '<%= config.distFolderName %>/<%= config.testDestFolderName %>',
expand: true
}
},
clean : {
build : {
src : [ '<%=config.distFolderName%>/','apidoc/' ]
},
pkgJson : {
src : ['<%= config.distFolderName %>/<%= pkg.name %>/package.json']
}
},
uglify: {
serverCode:{
files: [{
expand:true,
cwd:'<%= config.distFolderName %>/<%= pkg.name %>/server',
src:'**/*.js',
dest:'<%= config.distFolderName %>/<%= pkg.name %>/server'
}]
},
clientCode:{
files: [{
expand:true,
cwd:'<%= config.distFolderName %>/<%= pkg.name %>/client/js/application',
src:'**/*.js',
dest:'<%= config.distFolderName %>/<%= pkg.name %>/client/js/application'
}]
},
mainAppFile: {
files: {
'<%= config.distFolderName %>/<%= pkg.name %>/<%= config.appFileName %>':['<%= config.distFolderName %>/<%= pkg.name %>/<%= config.appFileName %>']
}
}
},
jshint:{
serverCode:{
files:[{
expand:true,
cwd:'<%= config.distFolderName %>/<%= pkg.name %>/server',
src:'**/*.js'
}]
},
clientCode:{
files: [{
expand:true,
cwd:'<%= config.distFolderName %>/<%= pkg.name %>/client/js/application',
src:'**/*.js'
}]
},
clientTestCode:{
files: [{
expand:true,
cwd:'<%= config.distFolderName %>/<%= config.testDestFolderName %>/unit/client/js',
src:'**/*.js'
}]
},
serverTestCode:{
files: [{
expand:true,
cwd:'<%= config.distFolderName %>/<%= config.testDestFolderName %>/server',
src:'**/*.js'
}]
}
},
//mocha is used to automate unit testing of server side nodejs/express code.
simplemocha: {
options: {
globals: ['expect'],
timeout: 3000,
ignoreLeaks: false,
ui: 'bdd',
reporter: 'tap'
},
all: { src: ['dist/Test/unit/server/**/*.js'] }
},
//karma is used to automate unit testing of client side angular/javascript test cases writtin in jasmine.
karma: {
unit: {
configFile: 'dist/Test/unit/client/config/karma.conf.js',
background: false
}
},
protractor: {
options: {
configFile: "protractor-config.js", //your protractor config file
keepAlive: true, // If false, the grunt process stops when the test fails.
noColor: false, // If true, protractor will not use colors in its output.
args: {
// Arguments passed to the command
}
},
chrome: {
options: {
args: {
browser: "chrome"
}
}
},
safari: {
options: {
args: {
browser: "safari"
}
}
},
firefox: {
options: {
args: {
browser: "firefox"
}
}
}
},
exec: {
generateAPIDoc : {
command: '<%= config.apiDocCommand %>'
},
buildDependencies :{
command: '<%= config.npmInstallCommand %>'
},
webdriverStart :{
command: 'node <%= config.protractorPath %>/bin/webdriver-manager start &'
},
webdriverSop :{
command: 'start http://localhost:4444/selenium-server/driver/?cmd=shutDownSeleniumServer'
},
protractorStart :{
command: 'node <%= config.protractorPath %>/bin/protractor ./dist/Test/integration/config/protractor-config.js'
}
}
});
// load our tasks
grunt.loadNpmTasks('grunt-contrib-copy');
grunt.loadNpmTasks('grunt-contrib-clean');
grunt.loadNpmTasks('grunt-contrib-uglify');
grunt.loadNpmTasks('grunt-contrib-jshint');
grunt.loadNpmTasks('grunt-simple-mocha');
grunt.loadNpmTasks('grunt-karma');
grunt.loadNpmTasks('grunt-protractor-runner');
//for running executables
grunt.loadNpmTasks('grunt-exec');
grunt.registerTask('start-server', 'Start a custom web server', function() {
grunt.log.writeln('Started web server on port 3000');
require('./dist/ThemeLibrary/server.js');
});
// the tasks
grunt.registerTask('build',
'Compiles all of the assets and copies the files to the build directory for Dev',
[ 'clean:build', 'clean:pkgJson','copy','exec:buildDependencies','jshint','exec:generateAPIDoc','uglify:serverCode','uglify:clientCode','uglify:mainAppFile','simplemocha','start-server', 'karma:unit']
);
grunt.registerTask('build-dev',
'Only copies the source files for Dev',
[ 'copy:sourceFiles','copy:mainAppFile', 'copy:testFiles', 'jshint', 'simplemocha','start-server','karma:unit','exec:webdriverSop','exec:webdriverStart', 'exec:protractorStart']
);
};
答案 0 :(得分:3)
我停止使用grunt来运行量角器命令,因为grunt从量角器中吞下了大部分有意义的堆栈跟踪。
相反,我建议使用多个protractor.conf.js
文件,并在构建过程中执行它们(travis,jenkins等)。
例如,我将protractor.conf.js
用于我们的CICD验证,protractor.e2e.conf.js
用于我们的特定于阶段的测试,其他用于需要(集成,仅回归)。
如果您通过selenium-server
安装,则应该启动selenium服务器(brew
),确保后台输出。然后,用protractor test/proctractor.conf.js
开始你的量角器测试。这样简单得多。