带有PhantomJS的Grunt Nightwatch - “拒绝连接”

时间:2015-12-07 14:06:08

标签: selenium selenium-webdriver gruntjs phantomjs nightwatch.js

首先,我启动Selenium:

nohup java -jar selenium/selenium-server-standalone-2.47.1.jar -role hub -port 4455&

然后添加PhantomJS驱动程序:

nohup phantomjs --webdriver=8080 --webdriver-selenium-grid-hub=http://127.0.0.1:4455&

nohup.out中的输出看起来......成功了吗?:

13:22:52.127 INFO - Launching Selenium Grid hub
2015-12-07 13:22:52.789:INFO:osjs.Server:jetty-7.x.y-SNAPSHOT
2015-12-07 13:22:52.833:INFO:osjsh.ContextHandler:started o.s.j.s.ServletContextHandler{/,null}
2015-12-07 13:22:52.845:INFO:osjs.AbstractConnector:Started SocketConnector@0.0.0.0:4455
13:22:52.846 INFO - Nodes should register to http://192.168.10.67:4455/grid/register/
13:22:52.846 INFO - Selenium Grid hub is up and running
PhantomJS is launching GhostDriver...
[INFO  - 2015-12-07T13:22:56.097Z] GhostDriver - Main - running on port 8080
[INFO  - 2015-12-07T13:22:56.097Z] GhostDriver - Main - registering to Selenium HUB 'http://127.0.0.1:4455' using '127.0.0.1:8080'
13:22:56.177 INFO - Registered a node http://127.0.0.1:8080
[INFO  - 2015-12-07T13:22:56.184Z] HUB Register - register - Registered with grid hub: http://127.0.0.1:4455/ (ok)
package.json中的

版本包括:

"devDependencies": {
    "grunt": "^0.4.5",
    "grunt-nightwatch": "^0.4.8",
    "phantomjs": "^1.9.19"
  },

Nightwatch的My Grunt任务配置如下:

module.exports = {
  options: { // default
    standalone: false,
    globals_path: 'test/globals.js',
    custom_commands_path: 'test/commands',
    custom_assertions_path: 'test/asserts',
    page_objects_path: 'test/pages',
    src_folders: ['test/specs'],
    output_folder: 'test/report',
    test_settings: {
      "default": {
        "desiredCapabilities": {
          "browserName": "firefox"
        }
      },
      "firefox": {
        "desiredCapabilities": {
          "browserName": "firefox"
        }
      },
      "chrome": {
        "desiredCapabilities": {
          "browserName": "chrome"
        }
      },
      "phantomjs": {
        "desiredCapabilities": {
          "browserName": "phantomjs",
          "javascriptEnabled": true,
          "acceptSslCerts": true,
          "phantomjs.binary.path": "node_modules/phantomjs/bin"
        }
      }
    },
    selenium: {
      "start_process": false
    }
  }
};

此时我可以:

grunt nightwatch:phantomjs

这给了我:

  

连接被拒绝了! selenium服务器是否已启动?

怎么了?我该如何调试?它是否与它有关,说节点应该注册到192.168.10.67(我的机器的本地网络IP),但是GhostDriver注册到127.0.0.1?

1 个答案:

答案 0 :(得分:0)

我认为问题在于这一行:

selenium: {
  "start_process": false
}

应改为:

selenium: {
  "start_process": true
}

在Nightwatch的Grunt任务配置中。这将在运行测试时自动启动Selenium进程。如果将其设置为false,则必须手动启动Selenium流程。