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

我使用Nightwatch.js为网站运行系统testing。 我想通过grunt运行它们来自动化testing。 我的Gruntfile包含这些行:

... 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'); 

当我在terminal上运行守夜的时候,它会启动selenium服务器并尝试运行testing,但是网站服务器没有启动。 为什么? 浏览器正在打开,但它只是说,一个连接是不可能的。 我search了一下,但我找不到任何东西。 我需要添加什么来使grunt运行服务器?

这是我的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 ,然后在运行testing之前启动服务器,例如:

 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' ]); 
Interesting Posts