首页 > 解决方案 > Nightwatch.js - 无法使用反射定义类

问题描述

这个错误是什么意思?我似乎在这上面找不到任何其他东西......我在chromedriver根目录selenium-server-standalonebin文件夹中。提前致谢

Starting selenium server... started - PID:  33239

[Sample Tests] Test Suite
=============================

Running:  Google Header
INFO Request: POST /wd/hub/session
 - data:  {"desiredCapabilities":{"browserName":"chrome","javascriptEnabled":true,"acceptSslCerts":true,"platform":"ANY","chromeOptions":{"args":["start-maximized"]},"name":"Sample Tests"}}
 - headers:  {"Content-Type":"application/json; charset=utf-8","Content-Length":179}
ERROR Response 500 POST /wd/hub/session (4666ms) { value:
   { message: 'Cannot define class using reflection',
     error: 'unknown error' },
  status: 13 }

Error retrieving a new session from the selenium server

Connection refused! Is selenium server started?
{ value:
   { message: 'Cannot define class using reflection',
     error: 'unknown error' },
  status: 13 }

nightwatch.json:

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

  "selenium" : {
    "start_process" : true,
    "server_path" : "./bin/selenium-server-standalone-3.8.1.jar",
    "log_path" : "",
    "port" : 4444,
    "cli_args" : {
      "webdriver.chrome.driver" : "./bin/chromedriver"
    }
  },

  "test_settings" : {
    "default" : {
      "launch_url" : "http://localhost",
      "selenium_port"  : 4444,
      "selenium_host"  : "localhost",
      "silent": true,
      "screenshots" : {
        "enabled" : false,
        "path" : ""
      },
      "desiredCapabilities": {
        "browserName": "chrome",
        "javascriptEnabled" : true,
        "acceptSslCerts" : true,
        "chromeOptions" : {
          "args" : ["start-maximized"]
        }
      }
    }
  }

sample_tests.js(我配置时的占位符测试)

module.exports = {
  'Google Header'(client) {
    client
      .url('http://www.google.com')
      .waitForElementVisible('.header h1')
      .expect.element('.main').to.not.be.present;
    client.end();
  }
}

标签: selenium-chromedrivernightwatch.js

解决方案


当我刷新我的机器并最终安装 Java 10 时,我遇到了这个问题。我们团队的其他成员仍然使用 Java 9,它对他们来说工作得很好。我没有降级到 Java 9,而是从 selenium-server-standalone-3.8.1 更新到 selenium-server-standalone-3.12.0 和 chromedriver2.38 -> chromedriver2.40。

希望同样的事情对你有用。


推荐阅读