selenium - 使用 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
}]
}
解决方案
如果我的问题正确,您可以做的是在启动时将参数作为环境变量传递给量角器。所以你的配置看起来像这样:
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
推荐阅读
- javascript - 在画布面料js上添加图像(按路径)
- docker - 我怎样才能让赛普拉斯在 CI 中访问除 root 之外的其他路由?
- json - 在 JQ 中递归生成对象
- c - 'a' 被打印了多少次?(包括循环中的分叉)
- angular - 如何使用真正的后端 API 在角度材料表中进行内联行编辑
- web-scraping - Newspaper3k、用户代理和抓取
- ios - Swift youtube ios helper podfile 'sharedApplication' 不可用:在 iOS 上不可用(应用程序扩展)
- c# - 在 MS Visual Studio 中使用 C# 在 ASP.NET 中注册页面
- project - 如何让门铃在 MP3 文件之间切换?
- javascript - 如何添加窗口事件以关闭打开的导航下拉菜单,但在导航项目上保持切换打开/关闭导航下拉菜单的行为?