使用 Grunt 启动 Nightwatch 时,网站服务器未启动

When starting Nightwatch with Grunt, the website server is not started

我正在使用 Nightwatch.js 到 运行 网站的系统测试。我想通过 g运行t 运行ning 来自动化测试。我的 G运行t 文件包含这些行:

...
var nightwatch = require('nightwatch');
nightwatch.initGrunt(grunt);
...
nightwatch: {
    options: {
        standalone: true,
        test_settings: {
            "default": {
                "launch_url": "http://localhost",
                "selenium_port": 4444,
                "selenium_host": "localhost",
                "silent": true,
                "screenshots": {
                    "enabled": false,
                    "path": ""
                },
                "desiredCapabilities": {
                    "browserName": "firefox",
                    "javascriptEnabled": true,
                    "acceptSslCerts": true
                }
            }
        },
        "chrome" : {
            "desiredCapabilities": {
                "browserName": "chrome",
                "javascriptEnabled": true,
                "acceptSslCerts": true
            }
        }
    }
},
...
grunt.loadNpmTasks('grunt-nightwatch');

当我在终端 运行 守夜grunt nightwatch 时,它会启动 selenium 服务器并尝试 运行 测试,但网站服务器没有启动。为什么?正在打开浏览器,但它只是说无法建立连接。我用谷歌搜索,但找不到任何东西。我必须添加什么才能使 g运行t 运行 成为服务器?

这是我的 nightwatch.json 文件:

{
"src_folders" : ["nightwatch/tests"],
"output_folder" : "nightwatch/reports",
"custom_commands_path" : "",
"custom_assertions_path" : "",
"page_objects_path" : "",
"globals_path" : "",

"selenium" : {
    "start_process" : false,
    "server_path" : "",
    "log_path" : "",
    "host" : "127.0.0.1",
    "port" : 4444,
    "cli_args" : {
        "webdriver.chrome.driver" : "",
        "webdriver.ie.driver" : ""
    }
},

"test_settings" : {
    "default" : {
        "launch_url" : "http://localhost",
        "selenium_port"  : 4444,
        "selenium_host"  : "localhost",
        "silent": true,
        "screenshots" : {
            "enabled" : false,
            "path" : ""
      },
      "desiredCapabilities": {
          "browserName": "firefox",
          "javascriptEnabled": true,
          "acceptSslCerts": true
      }
},

"chrome" : {
    "desiredCapabilities": {
        "browserName": "chrome",
        "javascriptEnabled": true,
        "acceptSslCerts": true
    }
}
}

您可以尝试 grunt-express-server 并在 运行 测试之前启动服务器,例如:

npm install grunt-express-server --save-dev

并修改 gruntfile:

grunt.loadNpmTasks('grunt-express-server');
grunt.initConfig({
  express: {
    options: {
      // Override defaults here
    },
    dev: {
      options: {
        script: 'app.js'
      }
    }...


// and finally, in the test task, add this in the beginning.     
grunt.registerTask('test', [ 'express:dev', 'nightwatch' ]);