我已经搜索了大约8个小时,并且在这个问题上阅读了几乎所有相关主题,但到目前为止我还没有找到解决方案。 我找到的最接近的是 https://github.com/nightwatchjs/nightwatch/issues/1368 但是,通过更新selenium独立服务器解决了这个问题,我使用了所有最新版本。
我需要使用我已配置并命名为" nightwatch"的特定配置文件启动firefox浏览器。 我的系统首选: 赢得10 64位 java版" 1.8.0_121" npm -version 3.10.10 geckodriver-v0.18.0-Win64平台 Selenium独立3.5.0 Firefox开发人员版56.0b5(64位)
我的nightwatch.json文件是:
{
"src_folders" : ["nw/tests"],
"output_folder" : "nw/reports",
"globals_path" : "nightwatch.globals.js",
"test_workers": {
"enabled": true,
"workers": "auto"
},
"selenium" : {
"start_process" : true,
"server_path" : "./node_modules/selenium-server-standalone-jar/jar/selenium-server-standalone-3.5.0.jar",
"log_path" : "nw/logs",
"host" : "127.0.0.1",
"port" : 4444,
"cli_args" : {
"webdriver.chrome.driver" : "./node_modules/chromedriver/lib/chromedriver/chromedriver.exe",
"webdriver.ie.driver" : "",
"webdriver.gecko.driver": "geckoDriver/geckodriver.exe"
}
},
"test_settings" : {
"default" : {
"launch_url" : "http://google.com",
"selenium_port" : 4444,
"selenium_host" : "localhost",
"silent": true,
"screenshots" : {
"enabled" : true,
"path" : ""
},
"desiredCapabilities": {
"browserName": "firefox",
"javascriptEnabled": true,
"acceptSslCerts": true,
"marionette": false
}
}
}
}
我尝试过添加
"webdriver.firefox.profile": "nightwatch"
在selenium和测试设置中。浏览器以所需的配置文件启动,但我的测试中的URL(例如:某个URL)从未输入,因此我的测试总是失败。
如果我把" marionette":如上面的问题中所描述的那样,那么Firefox并没有开始使用所需的"夜视仪"配置文件,另外我的测试总是在第一行失败.waitForElementVisible(" body",1000)
我一直在搜索和阅读很多关于这个问题,并没有找到对我有帮助的东西。我明白gecko驱动程序有可能接收可以指定firefox配置文件的参数,但是我的知识在这个主题上非常有限(夜视守夜4天),我现在根本无法解决它。 我甚至尝试修改。\ nightwatch \ lib \ runner
中的selenium.js文件以下内容:
this.cliOpts = [
'-Dwebdriver.firefox.profile=nightwatch', //i added this line in the file .\node_modules\nightwatch\lib\runner\selenium.js
'-jar', this.settings.selenium.server_path,
'-port', this.port
];
同样的问题发生了,Firefox浏览器打开了所需的配置文件,但是测试没有执行,并且在等待30秒后完全失败,日志说" java.lang.NullPointerException"
添加内容以反映以下评论 当我把以下代码
"cli_args" : {
"webdriver.ie.driver" : "",
"webdriver.gecko.driver": "geckoDriver/geckodriver.exe",
"webdriver.firefox.profile": "nightwatch"
}
Firefox以所需的配置文件启动,但测试没有执行(甚至没有输入测试URL(如上所述)。由于日志太长而无法包含在原始帖子中,因此可以在google drive {{ 3}}
答案 0 :(得分:1)
更新了我的整个配置,根据需要更改设置和位置。
module.exports = {
"src_folders": [
"scripts/test"// Where you are storing your Nightwatch e2e tests
],
"output_folder": "./reports", // reports (test outcome) output by nightwatch
"selenium": { // downloaded by selenium-download module (see readme)
"start_process": true, // tells nightwatch to start/stop the selenium process
"server_path": "./node_modules/nightwatch/bin/selenium.jar", // the standard alone selenium server jar
"host": "127.0.0.1",
"port": 4444, // standard selenium port
"cli_args": { // chromedriver is downloaded by selenium-download (see readme)
"webdriver.chrome.driver" : "C:/chrome-win32/chromedriver.exe",
"webdriver.gecko.driver" : "geckodriver.exe", //firefox driver location
"webdriver.ie.driver" : "IEDriverServer.exe"
}
},
"test_settings": {
"default": {
"screenshots": {
"enabled": false, // if you want to keep screenshots
"path": "" // save screenshots here
},
"globals": {
"waitForConditionTimeout": 5000 // sometimes internet is slow so wait.
},
"desiredCapabilities": { // use Chrome as the default browser for tests
"browserName": "chrome",
},
},
"chrome": {
"desiredCapabilities": {
"browserName": "chrome",
"javascriptEnabled": true, // turn off to test progressive enhancement
"chromeOptions" :{
// "args": [
// 'headless',
// // Use --disable-gpu to avoid an error from a missing Mesa
// // library, as per
// // https://chromium.googlesource.com/chromium/src/+/lkgr/headless/README.md
// 'disable-gpu',
// ],
"binary": 'C:/chrome-win32/chrome.exe'
},
"selenium": {
"cli_args": {
"webdriver.chrome.driver" : "C:/chrome-win32/chromedriver.exe",
},
},
},
},
"firefox":{
"desiredCapabilities": {
"browserName": 'firefox',
"javascriptEnabled": true,
"marionette": false,
"acceptSslCerts": true,
"acceptInsecureCerts" :true
},
"selenium": {
"cli_args": {
"webdriver.gecko.driver" : "geckodriver.exe" ,
//"webdriver.firefox.bin" : 'C:/tools/firefox_v39/firefox.exe'
},
},
},
"ie" :{
"desiredCapabilities": {
"browserName": 'internet explorer',
"javascriptEnabled": true,
"acceptSslCerts": true
},
}
}
}