Nightwatch.js配置文件

时间:2017-04-28 15:46:32

标签: nightwatch.js

我是Nightwatch的新手,我正在尝试运行此命令

  

$ nightwatch --env gecko /tests/test1/sample1.js

我试图找出如何通过命令行从nightwatch.json文件中选择浏览器。

这是我的conf文件。我正在阅读关于Nightwatch.js的教程,我似乎无法找到这个设置。

{
"src_folders": [
    "tests"
],
"selenium": {
    "start_process": false,
    "server_path": "bin/selenium-server-standalone-2.53.1.jar",
    "log_path": "",
    "host": "127.0.0.1",
    "port": 4444,
    "cli_args": {
        "webdriver.chrome.driver": "bin/chromedriver",
        "webdriver.gecko.driver" : "bin/geckodriver"
    }
},
"test_settings": {
    "default": {
        "launch_url": "http://127.0.0.1/",
        "selenium_port": 4444,
        "selenium_host": "localhost",
        "silent": true,
        "screenshots": {
            "enabled": false,
            "path": ""
        },
        "desiredCapabilities": {
            "browserName": "chrome",
            "javascriptEnabled": true,
            "acceptSslCerts": true
        }
    }
    "gecko": {
    "launch_url": "http://127.0.0.1/",
    "selenium_port": 4444,
    "selenium_host": "localhost",
    "silent": true,
    "screenshots": {
        "enabled": false,
        "path": ""
    },
    "desiredCapabilities": {
        "browserName": "gecko",
        "javascriptEnabled": true,
        "acceptSslCerts": true
        }
    }
}
}

我收到的错误消息是

Error: No testing environment specified.
    at CliRunner.parseTestSettings (/usr/local/lib/node_modules/nightwatch/lib/runner/cli/clirunner.js:515:13)
    at CliRunner.setup (/usr/local/lib/node_modules/nightwatch/lib/runner/cli/clirunner.js:49:8)
    at Object.exports.runner (/usr/local/lib/node_modules/nightwatch/lib/index.js:551:17)
    at /usr/local/lib/node_modules/nightwatch/bin/runner.js:10:16
    at Object.exports.cli (/usr/local/lib/node_modules/nightwatch/lib/index.js:545:5)
    at Object.<anonymous> (/usr/local/lib/node_modules/nightwatch/bin/runner.js:8:14)
    at Module._compile (module.js:571:32)
    at Object.Module._extensions..js (module.js:580:10)
    at Module.load (module.js:488:32)
    at tryModuleLoad (module.js:447:12)

2 个答案:

答案 0 :(得分:0)

不确定是不是这样,但你至少需要一个逗号:

},
    "gecko"

答案 1 :(得分:0)

也许尝试使用以下代码:

  {
  "src_folders": [
    "tests"
  ],
  "output_folder": "reports",
  "custom_commands_path": "",
  "custom_assertions_path": "",
  "page_objects_path": "pages",
  "globals_path": "",
  "selenium": {
    "start_process": false,
    "server_path": "bin/selenium-server-standalone-2.53.1.jar",
    "start_session": true,
    "log_path": "",
    "host": "127.0.0.1",
    "port": 4444,
    "cli_args": {
      "webdriver.chrome.driver": "bin/chromedriver",
      "webdriver.gecko.driver" : "bin/geckodriver"
    }
  },
  "test_settings": {
    "default": {
      "launch_url" : "http://localhost",
      "selenium_port": 4444,
      "selenium_host": "localhost",
      "silent": true,
      "desiredCapabilities": {
        "browserName": "chrome",
        "javascriptEnabled": true,
        "acceptSslCerts": true
      }
    },
    "gecko": {
      "desiredCapabilities": {
        "browserName": "firefox",
        "javascriptEnabled": true,
        "acceptSslCerts": true
      }
    }
  }
}