Javascript 从selenium服务器检索新会话时出错

Javascript 从selenium服务器检索新会话时出错,javascript,selenium,webdriver,nightwatch.js,Javascript,Selenium,Webdriver,Nightwatch.js,我第一次尝试设置Nightwatch.js。我将遵循以下教程: 不幸的是,我遇到了一个障碍,我需要帮助解决它 从selenium服务器检索新会话时出错。 连接被拒绝!selenium服务器启动了吗 nightwatch.conf.js module.exports = { "src_folders": [ "test"// Where you are storing your Nightwatch e2e/UAT tests ], "output_folder": "./r

我第一次尝试设置Nightwatch.js。我将遵循以下教程:

不幸的是,我遇到了一个障碍,我需要帮助解决它

从selenium服务器检索新会话时出错。 连接被拒绝!selenium服务器启动了吗

nightwatch.conf.js

module.exports = {
  "src_folders": [
    "test"// Where you are storing your Nightwatch e2e/UAT tests
  ],
  "output_folder": "./reports", // reports (test outcome) output by nightwatch
  "selenium": { 
    "start_process": true, // tells nightwatch to start/stop the selenium process
    "server_path": "./node_modules/nightwatch/bin/selenium.jar",
    "host": "127.0.0.1",
    "port": 4444, // standard selenium port
    "cli_args": {  
      "webdriver.chrome.driver" : "./node_modules/nightwatch/bin/chromedriver"
    }
  },
  "test_settings": {
    "default": {
      "screenshots": {
        "enabled": true, // if you want to keep screenshots
        "path": './screenshots' // save screenshots here
      },
      "globals": {
        "waitForConditionTimeout": 5000 // sometimes internet is slow so wait.
      },
      "desiredCapabilities": { // use Chrome as the default browser for tests
        "browserName": "chrome"
      }
    },
    "chrome": {
      "desiredCapabilities": {
        "browserName": "chrome",
        "javascriptEnabled": true // set to false to test progressive enhancement
      }
    }
  }
}
module.exports = { // addapted from: https://git.io/vodU0
  'Guinea Pig Assert Title': function(browser) {
    browser
      .url('https://saucelabs.com/test/guinea-pig')
      .waitForElementVisible('body')
      .assert.title('I am a page title - Sauce Labs')
      .saveScreenshot('ginea-pig-test.png')
      .end();
  }
};
豚鼠.js

module.exports = {
  "src_folders": [
    "test"// Where you are storing your Nightwatch e2e/UAT tests
  ],
  "output_folder": "./reports", // reports (test outcome) output by nightwatch
  "selenium": { 
    "start_process": true, // tells nightwatch to start/stop the selenium process
    "server_path": "./node_modules/nightwatch/bin/selenium.jar",
    "host": "127.0.0.1",
    "port": 4444, // standard selenium port
    "cli_args": {  
      "webdriver.chrome.driver" : "./node_modules/nightwatch/bin/chromedriver"
    }
  },
  "test_settings": {
    "default": {
      "screenshots": {
        "enabled": true, // if you want to keep screenshots
        "path": './screenshots' // save screenshots here
      },
      "globals": {
        "waitForConditionTimeout": 5000 // sometimes internet is slow so wait.
      },
      "desiredCapabilities": { // use Chrome as the default browser for tests
        "browserName": "chrome"
      }
    },
    "chrome": {
      "desiredCapabilities": {
        "browserName": "chrome",
        "javascriptEnabled": true // set to false to test progressive enhancement
      }
    }
  }
}
module.exports = { // addapted from: https://git.io/vodU0
  'Guinea Pig Assert Title': function(browser) {
    browser
      .url('https://saucelabs.com/test/guinea-pig')
      .waitForElementVisible('body')
      .assert.title('I am a page title - Sauce Labs')
      .saveScreenshot('ginea-pig-test.png')
      .end();
  }
};
基于配置设置。我尽可能地保留它。我无法准确指出另一个selenium服务器已启动的来源。有什么想法吗

编辑:超时错误


在“selenium”中的nightwatch.json文件中

确保您的服务器路径正确。 确保您的webdriver.chrome.driver路径正确

这些是特定于您的机器的。如果这些文件没有在正确的位置引用正确的文件,那么启动selenium服务器时就会出现问题

之后,您需要确保您拥有的selenium服务器版本与您拥有的chrome驱动程序版本兼容,并且该版本与您拥有的chrome浏览器版本兼容


但正如所指出的,如果没有完整的错误消息,我们将无法提供更多帮助。

解决方案包括删除我的Chrome实例(尽管它是最新版本),然后重新安装浏览器


我鼓励所有面临相同问题的人首先看看上面QualiT的回答,因为这是更传统的故障排除策略

在我的项目中使用
vue cli init
时,我遇到了同样的问题。在我升级到Java 9之后,这个问题得到了解决。

您的错误相关屏幕截图似乎暗示了Chrome(或者甚至ChromeDriver)的某些方面。但是由于您没有正确地包含完整的错误内容,所以很难说。我建议您首先更仔细地查看错误(或)分享问题中的完整错误内容,以便更容易地找出发生了什么。@KrishnanMahadevan这是我的问题和完整的错误内容,您能帮忙吗?谢谢,事实上,他们的方向是正确的。问题是我需要最新版本的selenium独立服务器。然而,现在当我尝试运行一个测试(guina-pig.js)时,我总是收到一个超时错误。我甚至尝试过只检查页面标题的简单测试,但都失败了……我包括了上面的最新截图,知道为什么会发生这种情况吗?js被设计成一个简单的测试,以确保它正常运行。没有失败的理由!如果安装了新的selenium服务器,可能需要停止并重新启动它。这里有两个选项:重新启动机器,联机并在终端中查找操作方法。在安装新版本之前,我必须这样做,所以这是我的第一个猜测。不幸的是,同样的结果,总是收到超时错误:(chromeDriver的哪个版本?Chrome的哪个版本?还有,你是否看到Chrome打开并加载页面?