How to run protractor as a script and not as a child process or using a task runner?

前端 未结 3 1781
暗喜
暗喜 2020-12-17 04:42

I am wondering how I can run a protractor test as a script and not as a child process or from a task runner such as grunt and gulp. I am wanting to run the test suits in ord

相关标签:
3条回答
  • 2020-12-17 05:22
    const protractorFlake = require('protractor-flake'),
        baseUrl = process.argv[2],
        maxAttempts = process.argv[3];
    
    if (process.argv.length > 2) {
        console.info('Launching protractor with baseUrl: %s, maxAttempts: %d', baseUrl, maxAttempts);
    
        protractorFlake({
            maxAttempts: maxAttempts,
            parser: 'multi',
            protractorArgs: [
            './protractor.conf.js',
            '--baseUrl',
            baseUrl
        ]
        }, function (status, output) {
            process.exit(status);
    });
    } else {
        console.error(`
            Usage: protractor-wrapper <baseUrl>
        `);
    }
    
    0 讨论(0)
  • 2020-12-17 05:26
    const Launcher = require("protractor/built/launcher");
    Launcher.init('path/to/conf');
    
    0 讨论(0)
  • 2020-12-17 05:27

    It will not be possible. I tried to do that but by reading the protractor source code there is no way to perform this.

    https://github.com/angular/protractor/blob/master/lib/launcher.js#L107

    This function is called with your config as a json object, but as you can see it calls a bunch of process.exit, according to this it will not be possible to run this without at least forking your process.

    My solution for programmatically call protractor is the following:

    var npm = require('npm');
    var childProcess = require('child_process');
    var address = ...some address object
    var args = ['--baseUrl', url.format(address)];
    
    npm.load({}, function() {
      var child = childProcess
      .fork(path.join(npm.root, 'protractor/lib/cli'), args)
      .on('close', function(errorCode) {
        console.log('error code: ', errorCode);
      });
      process.on('SIGINT', child.kill);
    });
    
    0 讨论(0)
提交回复
热议问题