我正在与Chrome无头的硒测试进行问题
我正在使用JavaScript使用“ Selenium-Webdriver”:“ 4.0.0-Alpha.7”。当我尝试运行测试用例时,无头传递。该测试只是与镀铬浏览器一起进行,而不是无头。
我有一个看起来像这样的config.js文件
// filename: lib/config.js
module.exports = {
baseUrl: process.env.BASE_URL || 'https://www.mycompanyURL.com',
host: process.env.HOST || 'headless',
headless: {
"browserName": process.env.BROWSER_NAME || 'chrome'
"chromeOptions": {
"args": ['--headless'],
},
},
localhost: {
"browserName": process.env.BROWSER_NAME || 'chrome'
}
}
,并且我有一个drivefactory.js,看起来像这样的
// filename: DriverFactory.js
const path = require('path')
const { Builder } = require('selenium-webdriver')
class DriverFactory {
constructor(config) {
this.config = config
}
_configure() {
let builder = new Builder()
switch (this.config.host) {
case 'localhost':
builder.withCapabilities(this.config.localhost)
break
case 'headless':
builder.withCapabilities(this.config.headless).
break
}
return builder
}
}
module.exports = DriverFactory
人知道为什么没有在capablitiies中设置无头参数?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
从Selenium 4开始(和IIRC,Selenium 3系列的一些后期版本)供应商特定的参数已被命名为空间,,扩展功能“ rel =“ nofollow noreferrer”>。
现在需要根据
GOOG
名称空间提供参数,例如 goog:chromeoptions 。您的选项
可以 用以下内容替换您的配置:
一个更好的想法
selenium-webdriver
library具有将Chrome(和Chromium)设置为内置的选项无头模式。这样做的方式将意味着您不必跟踪所需的参数值,而IMO有点干净。只需更新您的驱动程序:
As of Selenium 4 (and, IIRC, some of the later versions of the Selenium 3 series) vendor-specific arguments have been namespaced, in accordance with the WebDriver Spec.
Arguments now need to be provided to the driver under the
goog
namespace, eggoog:chromeOptions
.An option
You could replace your config with the following:
A better idea
The
selenium-webdriver
library has built-in options for setting Chrome (and Chromium, for that matter) into headless mode. Doing things this way will mean you don't have to keep track of the argument values needed, and is IMO a bit cleaner.Just update your driverFactory: