尝试连接到端口 4444 上的 Selenium 服务器时超时(使用 Nightwatch.js 进行测试)

Timeout while trying to connect to Selenium Server on port 4444 (Testing with Nightwatch.js)

我正在尝试 运行 使用 nightwatch.js 与多个浏览器并行进行测试,但我一直遇到此错误:

    Timeout while trying to connect to Selenium Server on port 4444.
       at Socket.socketErrorListener (_http_client.js:397:9)
       at emitErrorNT (internal/streams/destroy.js:91:8)
       at emitErrorAndCloseNT (internal/streams/destroy.js:59:3)
       at processTicksAndRejections (internal/process/next_tick.js:76:17)
    11:22:47.036 INFO [GridLauncherV3.parse] - Selenium server version: 
    3.141.59, revision: e82be7d358
    11:22:47.576 INFO [GridLauncherV3.lambda$buildLaunchers] - Launching 
    a standalone Selenium Server on port 4444
    2019-04-30 11:22:47.898:INFO::main: Logging initialized @2109ms to 
    org.seleniumhq.jetty9.util.log.StdErrLog

我的package.json

"name": "react-crud",
  "version": "1.0.0",
  "description": "A simple CRUD application in React JS with PHP as the server-side language, and MySQL Database.",
  "main": "nightwatch.conf.js",
  "directories": {
    "test": "tests"
  },
  "dependencies": {
    "chromedriver": "^2.46.0",
    "geckodriver": "^1.16.2",
    "react": "^15.6.2",
    "selenium-server-standalone-jar": "^3.141.5",
    "selenium-standalone": "^6.16.0",
    "selenium-webdriver": "^4.0.0-alpha.1"
  },
  "devDependencies": {},
  "scripts": {
    "test": "echo \"Error: no test specified\" && exit 1"
  }

问题是,当我尝试使用此 nightwatch.json 仅针对 chrome 进行测试时,它有效:

  "src_folders" : ["tests"],

  "webdriver" : {
    "start_process": true,
    "server_path": "node_modules/.bin/chromedriver",
    "port": 9515
  },

  "test_settings" : {
    "default" : {
      "desiredCapabilities": {
        "browserName": "chrome"
      }
    }
  }
}

但是当我尝试使用 selenium 服务器时,我不断收到刚刚在顶部输入的错误:

{
  "src_folders": [
    "tests"
  ],
  "output_folder": "reports",
  "selenium": {
    "start_process": true,
    "server_path": "selenium-server-standalone-3.141.59.jar",
    "log_path": "",
    "port": 4444,
    "cli_args": {
      "webdriver.chrome.driver": "bin/chromedriver",
      "webdriver.gecko.driver": "bin/geckodriver",
    }
  },
  "test_workers": {
    "enabled": true,
    "workers": "auto"
  },
  "test_settings": {
    "default": {
        "desiredCapabilities": {
          "browserName": "chrome"
        }
      },
    "firefox": {
      "desiredCapabilities": {
        "browserName": "firefox",
        "marionette": true
      }
    }
  }
}

提前致谢!

  • 在终端打开新标签页
  • 运行 $npm 安装 webdriver-manager
  • 运行$webdriver-manager更新
  • 运行 $webdriver-manager 开始
  • 在 Nightwatch 配置中使用 webdriver 而不是 selenium-server,并通过此自定义运行器脚本从新终端选项卡启动 Nightwatch:
// Custom runner.js for Nightwatch
const Nightwatch = require('nightwatch');

// read the CLI arguments
Nightwatch.cli(function(argv) {
  argv._source = argv['_'].slice(0);

  // create the Nightwatch CLI runner
  const runner = Nightwatch.CliRunner(argv);

  // setup and run tests
  runner
    .setup()
    .runTests()
    .catch(err => console.error(err));
});