运行webdriver-start和量角器 - 使用grunt和量角器启动不会开始,因为webdriver-start命令不会让下一个进程启动 [英] Running webdriver-start and protractor-start using grunt and protractor is not starting as webdriver-start command doesn't let next process to start

查看:104
本文介绍了运行webdriver-start和量角器 - 使用grunt和量角器启动不会开始,因为webdriver-start命令不会让下一个进程启动的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用Grunt来运行量角器端到端测试用例。我有以下三项任务(我正在使用Windows 7计算机)
$ b $ ol

  • webdriver-stop

  • webdriver - 开始

  • 量角器启动

  • 我正在尝试运行上述三项任务订购。然而,问题是在#webdriver-start进程中咕噜,并且不让#量角器启动进程运行。以下是我的grunt配置。请帮助。

      / ** 
    *新节点文件
    * /
    模块。 exports =函数(grunt){

    // globalConfig和将用于grunt脚本的路径

    var config = {

    srcFolderName:' src',
    distFolderName:'dist',
    appFileName:'server.js',
    nodeModuleFolderName:'node_modules',
    testSourceFolderName:'src-test',
    testDestFolderName:'Test',
    //根据项目需求更改此命令
    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(
    复制:{

    //将所有源文件复制到分发文件夹
    sourceFiles:{
    cwd:'<%= config。 srcFolderName%>',
    src:['**'],
    dest:'<%= config.distFolderName%> /<%= pkg.name%>',
    展开:true
    },
    //将主应用程序文件复制到dist文件夹
    mainAppFile:{
    src:'<%= config.appFileName%>' ,
    dest:'<%= config.distFolderName%> /<%= pkg.name%> /<%= config.appFileName%>'
    },
    copyPackage:{
    src:'package.json',
    dest:'<%= config.distFolderName%> /<%= pkg.name%> /package.json'
    },
    //将所有源测试文件复制到分发文件夹
    testFiles:{
    cwd: '<%= config.testSourceFolderName%>',
    src:['**'],
    dest:'<%= config.distFolderName%> /<%= config。 testDestFolderName%>',
    expand:true
    }
    },
    clean:{
    build:{
    src:['<%= config.distFolderName%> /','apidoc /']
    },
    pkgJson:{'b $ b 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:{
    个文件:[{
    expand:true,
    cwd:'<%= config.distFolderN ame%> /<%= 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用于自动执行单元测试的服务器端nodejs / express代码。
    simplemocha:{
    options:{
    globals:['expect'],
    timeout:3000,
    ignoreLeaks:false,
    ui:'bdd ',
    记者:'tap'
    },
    all:{src:['dist / Test / unit / server / ** / *。js']}
    } ,
    // karma用于在jasmine中自动执行客户端角/ javascript测试用例的单元测试。
    karma:{
    unit:{
    configFile:'dist / Test / unit / client / config / karma.conf.js',
    background:false
    }
    },
    量角器:{
    options:{
    configFile:protractor-config.js,//您的量角器配置文件
    keepAlive:true,//如果为false,则当测试失败时,咕噜声进程停止。
    noColor:false,//如果为true,量角器不会在其输出中使用颜色。
    args:{
    //传递给命令的参数
    }
    },
    chrome:{
    options:{
    args:{
    browser:chrome
    }
    }
    },
    safari:{
    options:{
    args:{
    浏览器:safari
    }
    }
    },
    firefox:{
    options:{
    args:{
    browser:firefox
    }
    }
    }
    } ,
    exec:{
    generateAPIDoc:{
    command:'<%= config.apiDocCommand%>'
    },
    buildDependencies:{
    命令:'<%= config.npmInstallCommand%>'
    },
    webdriverStart:{
    command:'node<%= config.protractorPath%> / bin / webdriver-管理员启动&'
    },
    webdriverSop:{
    命令:'启动http:// localhost:4444 / selenium-server / driver /?cmd = shutDownSeleniumServer'
    } ,

    protractorStart:{
    command:'node<%= config.protractorPath%> / bin / protractor ./dist/Test/integration/config/protractor-config.js'
    }

    }
    });

    //载入我们的任务
    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');
    //用于运行可执行文件
    grunt.loadNpmTasks('grunt-exec');

    grunt.registerTask('start-server','启动一个自定义web服务器',function(){
    grunt.log.writeln('端口3000上启动的web服务器');
    require('./ dist / ThemeLibrary / server.js');
    });

    //任务
    grunt.registerTask('build',
    '编译所有资产并将这些文件复制到Dev'的构建目录,
    ['clean:build','clean:pkgJson','copy','exec:buildDependencies','jshint','exec:generateAPIDoc','uglify:serverCode','uglify:clientCode','ugli fy:mainAppFile','simplemocha','start-server','karma:unit']
    );
    grunt.registerTask('build-dev',
    '只复制Dev'的源文件,
    ['copy:sourceFiles','copy:mainAppFile','copy:testFiles' ,'jshint','simplemocha','start-server','karma:unit','exec:webdriverSop','exec:webdriverStart','exec:protractorStart']
    );
    };


    解决方案

    我停止使用grunt来运行量角器命令,吞下量角器中大部分有意义的堆栈跟踪。



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

    例如,我使用 protractor.conf.js 用于我们的CICD验证, protractor.e2e.conf.js 用于我们的分段特定测试,还有一些是需要的(集成,仅回归)。 p>

    如果您是通过 brew>安装的,您应该启动一个硒服务器( selenium-server / code>),确保后台输出。然后,使用量角器test / proctractor.conf.js 来触发量角器测试。这样更简单。


    I am using Grunt to run protractor end to end test cases. I have following three tasks (I am using windows 7 machine)

    1. webdriver-stop
    2. webdriver-start
    3. protractor-start

    I am trying to run these three tasks as mentioned above order. However problem is grunt stuck at #webdriver-start process and doesn't let #protractor-start process to run. Following is my grunt config. Please help.

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

    解决方案

    I stopped using grunt to run protractor commands, since grunt swallows most of the meaningful stacktraces from protractor.

    Instead, I recommend using multiple protractor.conf.js files, and executing them in your build processes (travis, jenkins, etc.).

    For instance, I use protractor.conf.js for our CICD validation, protractor.e2e.conf.js for our staging-specific tests, and others as neeeded (integration, regression-only).

    You should probably kick off a selenium server (selenium-server if you installed via brew), making sure to background its output. Then, fire off your protractor tests with protractor test/proctractor.conf.js. It's much simpler that way.

    这篇关于运行webdriver-start和量角器 - 使用grunt和量角器启动不会开始,因为webdriver-start命令不会让下一个进程启动的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

    查看全文
    登录 关闭
    扫码关注1秒登录
    发送“验证码”获取 | 15天全站免登陆