gpt4 book ai didi

javascript - 使用 grunt 和 Protractor 运行 webdriver-start 和 protractor-start 没有启动,因为 webdriver-start 命令不允许下一个进程启动

转载 作者:行者123 更新时间:2023-11-30 12:43:16 29 4
gpt4 key购买 nike

我正在使用 Grunt 运行 Protractor 端到端测试用例。我有以下三个任务(我使用的是 windows 7 机器)

  1. webdriver-stop
  2. webdriver-start
  3. Protractor 开始

我正在尝试按上述顺序运行这三个任务。然而,问题是咕噜咕噜地卡在#webdriver-start 进程并且不让#protractor-start 进程运行。以下是我的 grunt 配置。请帮忙。

/**
* 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']
);
};

最佳答案

我不再使用 grunt 来运行 Protractor 命令,因为 grunt 吞噬了 Protractor 的大部分有意义的堆栈跟踪。

相反,我建议使用多个 protractor.conf.js 文件,并在您的构建过程(travis、jenkins 等)中执行它们。

例如,我使用 protractor.conf.js 进行 CICD 验证,使用 protractor.e2e.conf.js 进行特定于阶段的测试,以及其他需要的(集成,仅回归)。

您可能应该启动一个 selenium 服务器(selenium-server,如果您是通过 brew 安装的),确保将其输出置于后台。然后,使用 protractor test/proctractor.conf.js 启动 Protractor 测试。这样就简单多了。

关于javascript - 使用 grunt 和 Protractor 运行 webdriver-start 和 protractor-start 没有启动,因为 webdriver-start 命令不允许下一个进程启动,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23582435/

29 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com