首页 > 解决方案 > 使用 Protractor 运行并行测试时每个 Chrome 实例的自定义参数

问题描述

在量角器中运行并行测试时,是否可以为每个 Chrome 实例传递自定义参数?我需要知道每个实例的远程调试端口,这样我才能连接到 Dev Tools 协议。

在我看来,有两种选择。将端口设置为每个实例的特定唯一值,或者让它自动设置并在准备测试时以某种方式获取它。这些选项中的任何一个都有可能吗?

exports.config = {
    framework: 'jasmine',
    chromeDriver: chromeDriverPath,
    multiCapabilities: [{
        browserName: 'chrome',
        chromeOptions: {
            args: process.env.HEADLESS && puppeteer ? ['--headless',  `--remote-debugging-port=${DEV_TOOLS_PORT}`] : [`--remote-debugging-port=${DEV_TOOLS_PORT}`],
            binary: puppeteer.executablePath()
        },
        shardTestFiles: true,
        maxInstances: 1
    }]
}

标签: seleniumgoogle-chromeparallel-processingprotractor

解决方案


如果我的问题正确,您可以做的是在启动时将参数作为环境变量传递给量角器。所以你的配置看起来像这样:

exports.config = {

    framework: 'jasmine',
    chromeDriver: chromeDriverPath,

    multiCapabilities: [{
      'browserName': 'chrome',
      'chromeOptions': {
        args: [`--remote-debugging-port=${process.env.PORT_ONE}`]
      }
    }, {
      'browserName': 'chrome',
      'chromeOptions': {
        args: [`--remote-debugging-port=${process.env.PORT_TWO}`]
      }
  }]
}

然后使用 env 变量启动量角器过程,如下所示:

PORT_ONE=90 PORT_TWO=80 protractor protractor.conf.js


推荐阅读