如何在 Nightwatch 中配置远程网络驱动程序?
How to configure a remote webdriver in Nightwatch?
我正在开始使用 Nightwatch 并尝试使用 Selenoid 远程启动浏览器。
但是官方文档中好像没有远程Webdriver配置的例子。
例如,在 Java 中,我正在创建一个 RemoteWebdriver 对象,将集线器 url 传递给它,例如:
WebDriver wd = new RemoteWebDriver(URI.create('http://hub-master:4444/wd/hub').toURL(), capabilities)
但是当我设置文档中建议的参数时 (https://nightwatchjs.org/gettingstarted/configuration/#webdriver-settings):
webdriver: {
"host": "http://hub-master",
"port": 4444,
"default_path_prefix": "/wd/hub",
"log_path": 'selenium_logs',
},
我遇到错误:
An error occurred while retrieving a new session: "getaddrinfo ENOTFOUND http://simulia-master"
那么有人可以提供一个在 Nightwatch conf.js 中为 Selenoid 或 Selenium Grid 配置的远程网络驱动程序的示例吗?
通过以下配置解决。
似乎可以在 default
中设置基本 selenium
设置以用于多个本地环境,而且它的特定字段(如主机和端口)可以在 selenoid
环境中被覆盖:
test_settings: {
default: {
disable_error_log: false,
launch_url: 'https://my-url.com',
selenium: {
host: "localhost",
port: 4444,
start_process: true,
server_path: "node_modules/selenium-server/lib/runner/selenium-server-standalone-3.141.59.jar",
start_session: true,
log_path: "out/selenium_log",
cli_args: {
"webdriver.chrome.driver": "node_modules/chromedriver/lib/chromedriver/chromedriver.exe",
"webdriver.gecko.driver": "node_modules/geckodriver/geckodriver.exe"
}
},
desiredCapabilities: {
"browserName": "chrome", /* default browser for local run */
},
},
chrome: {
silent: true,
screenshots: {
enabled: true,
path: './screenshots/chrome/',
on_failure: true,
on_error: true,
},
desiredCapabilities: {
browserName: "chrome",
chromeOptions: {
args: [
"disable-web-security",
"ignore-certificate-errors",
"--test-type"
],
"prefs": {
"protocol_handler": {
"allowed_origin_protocol_pairs": allowedProtocols
},
},
"w3c": false,
}
}
},
firefox: {
screenshots: {
enabled: true,
path: './screenshots/firefox/',
on_failure: true,
on_error: true,
},
desiredCapabilities: {
browserName: "firefox",
alwaysMatch: {
"moz:firefoxOptions": {
args: [
"--headless",
"--width=1920",
"--height=1080"
],
}
}
}
},
selenoidChrome: {
selenium: {
start_process: false,
host: "selenoid-host",
port: 4444,
live_output: true,
},
screenshots: {
enabled: true,
path: './screenshots/selenoidChrome',
on_failure: true,
on_error: true,
},
desiredCapabilities: {
"enableVNC": true,
"browserName": "chrome",
"enableLog": true,
"enableVideo": true,
},
},
selenoidFirefox: {
extends: 'selenoidChrome',
screenshots: {
path: './screenshots/selenoidFirefox',
},
desiredCapabilities: {
"browserName": "firefox",
}
},
},
我正在开始使用 Nightwatch 并尝试使用 Selenoid 远程启动浏览器。
但是官方文档中好像没有远程Webdriver配置的例子。 例如,在 Java 中,我正在创建一个 RemoteWebdriver 对象,将集线器 url 传递给它,例如:
WebDriver wd = new RemoteWebDriver(URI.create('http://hub-master:4444/wd/hub').toURL(), capabilities)
但是当我设置文档中建议的参数时 (https://nightwatchjs.org/gettingstarted/configuration/#webdriver-settings):
webdriver: {
"host": "http://hub-master",
"port": 4444,
"default_path_prefix": "/wd/hub",
"log_path": 'selenium_logs',
},
我遇到错误:
An error occurred while retrieving a new session: "getaddrinfo ENOTFOUND http://simulia-master"
那么有人可以提供一个在 Nightwatch conf.js 中为 Selenoid 或 Selenium Grid 配置的远程网络驱动程序的示例吗?
通过以下配置解决。
似乎可以在 default
中设置基本 selenium
设置以用于多个本地环境,而且它的特定字段(如主机和端口)可以在 selenoid
环境中被覆盖:
test_settings: {
default: {
disable_error_log: false,
launch_url: 'https://my-url.com',
selenium: {
host: "localhost",
port: 4444,
start_process: true,
server_path: "node_modules/selenium-server/lib/runner/selenium-server-standalone-3.141.59.jar",
start_session: true,
log_path: "out/selenium_log",
cli_args: {
"webdriver.chrome.driver": "node_modules/chromedriver/lib/chromedriver/chromedriver.exe",
"webdriver.gecko.driver": "node_modules/geckodriver/geckodriver.exe"
}
},
desiredCapabilities: {
"browserName": "chrome", /* default browser for local run */
},
},
chrome: {
silent: true,
screenshots: {
enabled: true,
path: './screenshots/chrome/',
on_failure: true,
on_error: true,
},
desiredCapabilities: {
browserName: "chrome",
chromeOptions: {
args: [
"disable-web-security",
"ignore-certificate-errors",
"--test-type"
],
"prefs": {
"protocol_handler": {
"allowed_origin_protocol_pairs": allowedProtocols
},
},
"w3c": false,
}
}
},
firefox: {
screenshots: {
enabled: true,
path: './screenshots/firefox/',
on_failure: true,
on_error: true,
},
desiredCapabilities: {
browserName: "firefox",
alwaysMatch: {
"moz:firefoxOptions": {
args: [
"--headless",
"--width=1920",
"--height=1080"
],
}
}
}
},
selenoidChrome: {
selenium: {
start_process: false,
host: "selenoid-host",
port: 4444,
live_output: true,
},
screenshots: {
enabled: true,
path: './screenshots/selenoidChrome',
on_failure: true,
on_error: true,
},
desiredCapabilities: {
"enableVNC": true,
"browserName": "chrome",
"enableLog": true,
"enableVideo": true,
},
},
selenoidFirefox: {
extends: 'selenoidChrome',
screenshots: {
path: './screenshots/selenoidFirefox',
},
desiredCapabilities: {
"browserName": "firefox",
}
},
},