1

我已经搜索了大约 8 个小时,并阅读了几乎所有与此相关的主题,但到目前为止我还没有找到解决方案。我找到的最接近的是 https://github.com/nightwatchjs/nightwatch/issues/1368 但是通过更新 selenium 独立服务器解决了这个问题,我使用了所有最新版本。

我需要使用我已经配置并命名为“nightwatch”的特定配置文件启动 Firefox 浏览器 我的系统首选项:win 10 64bit java version "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"

在硒和测试设置中。浏览器以所需的配置文件启动,但我的测试中的 url(例如:某些 URL)从未输入,因此我的测试总是失败。

如果我按照上面问题中的描述放置“marionette”:true Firefox 没有使用所需的“nightwatch”配置文件启动,另外我的测试总是在第一行失败 .waitForElementVisible("body", 1000)

我一直在搜索和阅读很多关于这个问题的内容,但没有找到对我有帮助的东西。我知道壁虎驱动程序有可能接收可以指定 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 https://drive .google.com/open?id=0Bz4bu5Fo5Vq_NEhEZFlnSDBjWm8

4

1 回答 1

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
      },  
    }
  }
}
于 2017-08-24T03:01:47.383 回答