运行夜班测试时如何加载多个chrome扩展?

问题描述 投票:0回答:1

我已经弄清楚如何通过使用以下方法运行一个chrome扩展:

{
  "src_folders" : ["test"],
  "webdriver" : {
    "start_process": true,
    "server_path": "node_modules/.bin/chromedriver",
    "cli_args": ["--verbose"],
    "port": 9515
  },

  "test_settings" : {
    "default" : {
      "desiredCapabilities": {
        "browserName": "chrome",
        "chromeOptions" : {
          "args": [
            "--load-extension=/pathToFirstExtension",
          ]
        }
      }
    }
  }
}

但是,运行两个扩展程序不起作用。我尝试过以下方法:

  "args": [
            "--load-extension=/pathToFirstExtension, /pathToSecondExtension",
          ]

还有这个:

"args": [
            "--load-extension=/pathToFirstExtension", 
            "--load-extension=/pathToSecondExtension",
        ]

还有这个:

"args": [
            "--load-extension=/pathToFirstExtension /pathToSecondExtension",
        ]

并且base64编码的字符串以逗号分隔在列表中,如下所示:

chromeOptions: {
          extensions: [
            keywords.base64,
            avgPrice.base64
          ]
        }

我在单独的js文件中使用module.exports,其中base64编码的字符串位于具有base64键的对象中

如何为夜班测试加载多个镀铬扩展?

javascript google-chrome-extension nightwatch
1个回答
0
投票

罪魁祸首是逗号分隔的字符串之间的空间!

如果有人发现这个有用 - 这现在适合我:

const chromedriver = require('chromedriver');

module.exports = {
  src_folders : ["test"],
  test_settings: {
    default: {
      webdriver: {
        start_process: true,
        server_path: chromedriver.path,
        port: 4444,
        cli_args: ['--port=4444']
      },
      desiredCapabilities: {
        browserName: 'chrome',
        javascriptEnabled: true,
        acceptSslCerts: true,
        chromeOptions: {
          args: [
            "--load-extension=/pathToExtensionOne,/pathToExtensionTwo",
            "window-position=2560,0",
            "window-size=400,300"
          ]
        }
      }
    },
    chrome: {
      webdriver: {
        server_path: chromedriver.path
      },
      desiredCapabilities: {
        browserName: 'chrome',
        javascriptEnabled: true,
        acceptSslCerts: true,
        chromeOptions: {
          args: []
        }
      }
    }
  }
};

我也可以设置窗口大小/位置。

FWIW,我正在使用nightwatch.conf.js而不是nightwatch.json

在我的package.json中:

  "scripts": {
    "nightwatch": "nightwatch -c ./nightwatch.conf.js"
  }

要运行它,请在终端中执行以下命令:

npm run nightwatch
© www.soinside.com 2019 - 2024. All rights reserved.