Running Gulp-Angular-Protractor without gulp.src

2019-08-26 01:43发布

问题:

Gulp-Protractor and Gulp-Angular-Protractor can pass args and a config file to protractor.

So why do I need to pass a list of files to gulp?

function runProtractor(done) {
var params = process.argv;
var args = params.length > 3 ? [params[3], params[4]] : [];

gutil.log('arguments: ' + args);

gulp.src(paths.e2eFiles)
  .pipe(protractor({
      configFile: 'protractor.local.conf.js',
      args: args,
      'autoStartStopServer': true,
      'debug': true
  }))
  .on('error', function (err) {
      gutil.log(gutil.colors.red("An error occurred in protractor. Did you start the webdriver?"));
      gutil.log(gutil.colors.red("Run cmd 'start gulp webdriver'."));
      gutil.log(gutil.colors.red('error: ' + err));
      // Make sure failed tests cause gulp to exit non-zero
      throw err;
  })
  .on('end', function () {
      // Close browser sync server
      browserSync.exit();
      done();
  });

} The problem is that protractor are not running the suites but the files in src. Is there a way to call protractor direct?

回答1:

You can leave the gulp.src blank and pass the specs or suites as args, the documentation isn't great at explaining it but I have been able to pass any config file argument that I have tried through gulp as an arg (I think i had an issue with direct connect because it's a boolean and not a string).

gulp.task('e2e', function(cb) {
    gulp.src([]).pipe(protractor({
      configFile: './conf/protractor.conf.js',
      args: [
        '--baseUrl', 'http://localhost/',
        '--maxSessions', 1,
        '--suite', './specs/test-spec.js',
        '--params.environment', 'development'
      ]
    })).on('error', function(e) { throw e })
    .on('end', cb)
  });
};