UnknownError:连接被拒绝(连接被拒绝)

时间:2017-03-17 06:10:49

标签: selenium gruntjs protractor meanjs

我正在MEAN JS堆栈应用程序中运行一个grunt测试,并发现一个我无法解决其原因的问题。

单独运行webdriver-manager,即webdriver-manager start,工作正常,但通过grunt test任务运行似乎失败了。

我也注意到端口不同(不是4444)。不知道如何改变这一点。

Running "protractor:e2e" (protractor) task
webdriver-manager path: /Users/valdy/Development/MeanJSApp/node_modules/protractor/bin/webdriver-manager
selenium standalone is up to date.
chromedriver is up to date.
Starting selenium standalone server...
[launcher] Running 1 instances of WebDriver
Selenium standalone server started at http://192.168.0.115:64594/wd/hub

/Users/valdy/Development/MeanJSApp/node_modules/selenium-webdriver/lib/atoms/error.js:108
  var template = new Error(this.message);
                 ^
UnknownError: Connection refused (Connection refused)
    at new bot.Error (/Users/valdy/Development/MeanJSApp/node_modules/selenium-webdriver/lib/atoms/error.js:108:18)
    at Object.bot.response.checkResponse (/Users/valdy/Development/MeanJSApp/node_modules/selenium-webdriver/lib/atoms/response.js:109:9)
    at /Users/valdy/Development/MeanJSApp/node_modules/selenium-webdriver/lib/webdriver/webdriver.js:160:24
    at promise.ControlFlow.runInFrame_ (/Users/valdy/Development/MeanJSApp/node_modules/selenium-webdriver/lib/goog/../webdriver/promise.js:1857:20)
    at wrappedCtr.notify (/Users/valdy/Development/MeanJSApp/node_modules/selenium-webdriver/lib/goog/../webdriver/promise.js:2448:25)
    at promise.Promise.notify_ (/Users/valdy/Development/MeanJSApp/node_modules/selenium-webdriver/lib/goog/../webdriver/promise.js:564:12)
    at Array.forEach (native)
    at promise.Promise.notifyAll_ (/Users/valdy/Development/MeanJSApp/node_modules/selenium-webdriver/lib/goog/../webdriver/promise.js:553:15)
    at goog.async.run.processWorkQueue (/Users/valdy/Development/MeanJSApp/node_modules/selenium-webdriver/lib/goog/async/run.js:130:15)
    at process._tickCallback (internal/process/next_tick.js:103:7)
From: Task: WebDriver.createSession()
    at Function.webdriver.WebDriver.acquireSession_ (/Users/valdy/Development/MeanJSApp/node_modules/selenium-webdriver/lib/webdriver/webdriver.js:157:22)
    at Function.webdriver.WebDriver.createSession (/Users/valdy/Development/MeanJSApp/node_modules/selenium-webdriver/lib/webdriver/webdriver.js:131:30)
    at Builder.build (/Users/valdy/Development/MeanJSApp/node_modules/selenium-webdriver/builder.js:445:22)
    at LocalDriverProvider.DriverProvider.getNewDriver (/Users/valdy/Development/MeanJSApp/node_modules/protractor/lib/driverProviders/driverProvider.js:38:7)
    at Runner.createBrowser (/Users/valdy/Development/MeanJSApp/node_modules/protractor/lib/runner.js:182:37)
    at /Users/valdy/Development/MeanJSApp/node_modules/protractor/lib/runner.js:263:21
    at _fulfilled (/Users/valdy/Development/MeanJSApp/node_modules/q/q.js:797:54)
    at self.promiseDispatch.done (/Users/valdy/Development/MeanJSApp/node_modules/q/q.js:826:30)
    at Promise.promise.promiseDispatch (/Users/valdy/Development/MeanJSApp/node_modules/q/q.js:759:13)
    at /Users/valdy/Development/MeanJSApp/node_modules/q/q.js:573:44
[launcher] Process exited with error code 1
>> 
Warning: Tests failed, protractor exited with code: 1 Use --force to continue.

Aborted due to warnings.

这是tests.js(/config/assets/tests.js)的配置:

'use strict';

module.exports = {
  tests: {
    // client: ['modules/*/tests/client/**/*.js'],
    client: ['modules/forum/tests/client/**/*.js'],


    // server: ['modules/*/tests/server/**/*.js'],
    server: ['modules/forum/tests/server/**/*.js'],

    e2e: ['modules/*/tests/e2e/**/*.js']
    // e2e: ['modules/forum/tests/e2e/**/*.js']  

  }
};

我还发现/node_module/protractor/config.json下的量角器的config.json具有以下配置:

{
    "webdriverVersions": {
        "selenium": "2.47.1",
        "chromedriver": "2.19",
        "iedriver": "2.47.0"
    }
}

这是我自己的protractor.config.js,位于网络应用的根目录中:

'use strict';

// Protractor configuration
var config = {
    specs: ['modules/*/tests/e2e/*.js']
};

if (process.env.TRAVIS) {
    config.capabilities = {
        browserName: 'firefox'
    };
}

exports.config = config;

这是量角器的npm描述符(/node_module/protractor/package.json):

{
    "_args": [
        [
            {
                "raw": "Protractor@2.5.1",
                "scope": null,
                "escapedName": "Protractor",
                "name": "Protractor",
                "rawSpec": "2.5.1",
                "spec": "2.5.1",
                "type": "version"
            },
            "/Users/valdy/Development/MeanJSApp"
        ]
    ],
    "_from": "Protractor@2.5.1",
    "_id": "protractor@2.5.1",
    "_inCache": true,
    "_location": "/protractor",
    "_nodeVersion": "0.12.7",
    "_npmUser": {
        "name": "angularcore",
        "email": "angular-core+npm@google.com"
    },
    "_npmVersion": "2.11.3",
    "_phantomChildren": {
        "boom": "2.10.1",
        "chalk": "1.1.3",
        "combined-stream": "1.0.5",
        "core-util-is": "1.0.2",
        "cryptiles": "2.0.5",
        "ctype": "0.5.3",
        "forever-agent": "0.6.1",
        "graceful-readlink": "1.0.1",
        "hoek": "2.16.3",
        "inherits": "2.0.3",
        "is-my-json-valid": "2.16.0",
        "isstream": "0.1.2",
        "json-stringify-safe": "5.0.1",
        "lru-cache": "2.7.3",
        "oauth-sign": "0.8.2",
        "sigmund": "1.0.1",
        "sntp": "1.0.9",
        "string_decoder": "0.10.31",
        "stringstream": "0.0.5",
        "tough-cookie": "2.3.2"
    },
    "_requested": {
        "raw": "Protractor@2.5.1",
        "scope": null,
        "escapedName": "Protractor",
        "name": "Protractor",
        "rawSpec": "2.5.1",
        "spec": "2.5.1",
        "type": "version"
    },
    "_requiredBy": [
        "#USER",
        "/grunt-protractor-runner",
        "/gulp-protractor"
    ],
    "_resolved": "https://registry.npmjs.org/protractor/-/protractor-2.5.1.tgz",
    "_shasum": "03d6c93cd7c268f4250177d55a2fec8a198372cd",
    "_shrinkwrap": null,
    "_spec": "Protractor@2.5.1",
    "_where": "/Users/valdy/Development/MeanJSApp",
    "author": {
        "name": "Julie Ralph",
        "email": "ju.ralph@gmail.com"
    },
    "bin": {
        "protractor": "bin/protractor",
        "webdriver-manager": "bin/webdriver-manager"
    },
    "bugs": {
        "url": "https://github.com/angular/protractor/issues"
    },
    "dependencies": {
        "accessibility-developer-tools": "~2.6.0",
        "adm-zip": "0.4.4",
        "glob": "~3.2",
        "html-entities": "~1.1.1",
        "jasmine": "2.3.2",
        "jasminewd": "1.1.0",
        "jasminewd2": "0.0.6",
        "lodash": "~2.4.1",
        "minijasminenode": "1.1.1",
        "optimist": "~0.6.0",
        "q": "1.0.0",
        "request": "~2.57.0",
        "saucelabs": "~1.0.1",
        "selenium-webdriver": "2.47.0",
        "source-map-support": "~0.2.6"
    },
    "description": "Webdriver E2E test wrapper for Angular.",
    "devDependencies": {
        "chai": "~3.3.0",
        "chai-as-promised": "~5.1.0",
        "cucumber": "~0.6.0",
        "expect.js": "~0.2.0",
        "express": "~3.3.4",
        "jshint": "2.5.0",
        "mocha": "2.3.3",
        "rimraf": "~2.2.6"
    },
    "directories": {},
    "dist": {
        "shasum": "03d6c93cd7c268f4250177d55a2fec8a198372cd",
        "tarball": "https://registry.npmjs.org/protractor/-/protractor-2.5.1.tgz"
    },
    "gitHead": "645133d557f1059d9e885f2566fc4c29ce7c19cc",
    "homepage": "https://github.com/angular/protractor",
    "keywords": [
        "angular",
        "test",
        "testing",
        "webdriver",
        "webdriverjs",
        "selenium"
    ],
    "license": "MIT",
    "main": "lib/protractor.js",
    "maintainers": [
        {
            "name": "juliemr",
            "email": "ju.ralph@gmail.com"
        },
        {
            "name": "angularcore",
            "email": "angular-core+npm@google.com"
        }
    ],
    "name": "protractor",
    "optionalDependencies": {},
    "readme": "ERROR: No README data found!",
    "repository": {
        "type": "git",
        "url": "git://github.com/angular/protractor.git"
    },
    "scripts": {
        "pretest": "jshint lib spec scripts",
        "start": "node testapp/scripts/web-server.js",
        "test": "node scripts/test.js"
    },
    "version": "2.5.1"
}

1 个答案:

答案 0 :(得分:2)

以下是我最好的猜测:

  1. 使用您的IP地址和非4444端口启动selenium独立服务器locally。这意味着您没有选择seleniumAddress: "http://localhost:4444/wd/hub"directConnect: true。我的下面会有一个代码片段。

  2. 如果您是在本地而不是在Travis上发布,那么Protractor将由Chrome browser by default启动。这也意味着您应该已经下载了ChromeDriver。

  3. 您应该从Protractor 2.5升级到最新版本。量角器与整个堆栈紧密结合:selenium-webdriver,独立服务器,浏览器驱动程序和浏览器。如果您使用的是最新的浏览器和Protractor 2.5,那么webdriver-manager可能会下载可能与您的浏览器不兼容的旧二进制文件。

  4. 以下是代码段:

    exports.config = {
      // option 1. launches a selenium standalone server. this is helpful if
      // you launch it with "webdriver-manager start"
      // seleniumAddress: "http://localhost:4444/wd/hub",
      //
      // option 2. launch browser directly using browser binaries
      // directConnect: true,
      //
      // option 3. do not include either seleniumAddress or directConnect
      // and this option will launch the selenium standalone server using
      // your ip address.
      //
      // option 4: launch with saucelabs or browserstack options
    }
    

    此文件与您定义配置,仅为travis设置功能并导出配置的文件有关。

    'use strict';
    
    // Protractor configuration
    var config = {
      specs: ['modules/*/tests/e2e/*.js']
    };
    
    if (process.env.TRAVIS) {
      config.capabilities = {
        browserName: 'firefox'
      };
    }
    
    exports.config = config;