将自定义Firefox配置文件与nightwatch.js selenium gecko驱动程序一起使用
我已经搜索了大约8个小时,几乎阅读了关于这个问题的所有相关主题,但到目前为止我还没有找到解决方案。 我找到的最接近的是 不过,通过更新selenium standalone server解决了这个问题,我使用了所有最新版本 我需要启动firefox浏览器,使用我已经配置并命名为“nightwatch”的特定配置文件 我的系统优先级: 赢10 64位 java版本“1.8.0_121” npm-版本3.10.10 geckodriver-v0.18.0-win64 Selenium standalone 3.5.0 Firefox开发者版56.0b5(64位) 我的nightwatch.json文件是:将自定义Firefox配置文件与nightwatch.js selenium gecko驱动程序一起使用,selenium,marionette,nightwatch.js,geckodriver,firefox-profile,Selenium,Marionette,Nightwatch.js,Geckodriver,Firefox Profile,我已经搜索了大约8个小时,几乎阅读了关于这个问题的所有相关主题,但到目前为止我还没有找到解决方案。 我找到的最接近的是 不过,通过更新selenium standalone server解决了这个问题,我使用了所有最新版本 我需要启动firefox浏览器,使用我已经配置并命名为“nightwatch”的特定配置文件 我的系统优先级: 赢10 64位 java版本“1.8.0_121” npm-版本3.10.10 geckodriver-v0.18.0-win64 Selenium standal
{
"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和test设置中。浏览器以所需的配置文件启动,但从未输入我测试的url(例如:某个url),因此我的测试总是失败
如果我输入“木偶网”:如上述问题中所述,Firefox没有使用所需的“夜视”配置文件启动,而且我的测试在第1行总是失败。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上使用我的整个配置更新日志,如果需要,请更改设置和位置
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
},
}
}
}
你试过了吗?你能粘贴整个错误日志吗?@Raymond因为日志太长,无法包含在内,所以我附加了一个谷歌驱动器的Urlit@smit9234感谢您关注url,我还阅读了有关为自定义配置文件添加代码的内容,有一个人尝试修改浏览器的默认语言,他的代码包含在t中他进行了实际测试,但对他(对我也是如此)来说没有成功。我之所以提到这一点,是因为我不知道在哪里包含该代码,请原谅我对该主题的无知。经过多次选择,我已经降级到Selenium 3.4.0并使用木偶:的确,我能够找到一个有效的解决方案。我尝试了这一点,唯一的区别是我从未放置过“AcceptUnsecureCerts”:到目前为止为true。但是,只要我初始化提线木偶:true,就会发现它还包括“webdriver.firefox.profile”:“nightwatch”firefox浏览器以动态(未配置的界面)启动,另外,我的测试在body标记处总是失败(如上所述)你能把整个nightwatch.json都包括进来吗?我可能遗漏了一些东西。包括现在的配置我试图将你的文件转换成一个有效的json,并将其用作nightwatch.json文件。但是,它从未使用所需的创建配置文件“nightwatch”启动firefox浏览器“即使我添加了必要的代码来执行此操作。此外,使用json,我只能插入URL,并且在body标记处总是失败。也许这会有帮助,但它已经过时(版本方面)它也不可用,必须有一种简单的方法来传递参数,比如chromeOptions的参数,人们会想检查一下:同时将selenium standalone和firefox更新到最新版本