2

I'm running a grunt test within a MEAN JS stack app and found an issue that I can't work out its cause.

Running webdriver-manager on its own, i.e. webdriver-manager start, works fine, but running via the grunt test task seems to fail.

I also noticed that the port is different (not 4444). Not sure how to change this either.

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.

This is the config for 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']  

  }
};

I also found that protractor's config.json, under /node_module/protractor/config.json has this configuration:

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

And this is my own protractor.config.js, in the root of the web app:

'use strict';

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

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

exports.config = config;

And here is protractor's npm descriptor (/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"
}
Eliran Malka
  • 15,821
  • 6
  • 77
  • 100
dcpartners
  • 5,176
  • 13
  • 50
  • 73
  • Please add your configuration file. – cnishina Mar 17 '17 at 07:55
  • @cnishina - I've added the snippet for tests config. Is that the config that you need? – dcpartners Mar 17 '17 at 09:08
  • I'm confused. That's not a protractor config file. Are you using Protractor 5? Are you using something that is wrapping Protractor? – cnishina Mar 17 '17 at 09:14
  • Sorry @cnishina ... I've updated the config. Is that what you want? – dcpartners Mar 17 '17 at 09:53
  • @cnishina I've also found another one in the root level of the webapp. – dcpartners Mar 17 '17 at 10:21
  • @cnishina Added /node_module/protractor/package.json as well – dcpartners Mar 17 '17 at 10:34
  • So it looks like you are using a really old version of Protractor. The latest version of Protractor is 5.1.1. You want to stay with the latest version. Newer versions of browsers require newer versions of W3C WebDriver clients which also might require newer versions of selenium standalone server. Also the address shown when starting up Protractor is because you launched w/ the local driver provider. This is because you did not specify a launch strategy. I prefer using `seleniumAddress: "http://localhost:4444/wd/hub"` or `directConnect: true`. – cnishina Mar 17 '17 at 18:30
  • I'm newbie with this. Which file configuration that we need to change? – dcpartners Mar 19 '17 at 08:29

1 Answers1

2

Here is my best guess at what's going on:

  1. You are launching with the selenium standalone server locally using your ip address and a port that is not 4444. This means that you did not select seleniumAddress: "http://localhost:4444/wd/hub" or directConnect: true. I'll have a code snippet below of what this looks like.

  2. If you are launching locally and not on Travis, then Protractor launches by the Chrome browser by default. This also means that you should have downloaded the ChromeDriver.

  3. You should upgrade from Protractor 2.5 to the latest. Protractor is strongly coupled with the entire stack: selenium-webdriver, the standalone server, browser drivers and browsers. If you are using an up-to-date browser and Protractor 2.5, then probably webdriver-manager downloaded old binaries that may be incompatible with your browser.


Here is the code snippet:

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
}

This file relates to this one where you define your config, set capabilities only for travis and export the config.

'use strict';

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

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

exports.config = config;
Upen
  • 1,388
  • 1
  • 22
  • 49
cnishina
  • 5,016
  • 1
  • 23
  • 40
  • 1
    Edit the protractor.config.js and run 'webdriver-manager start' on different console. It works nicely!!! var config = { seleniumAddress: 'http://localhost:4444/wd/hub', specs: ['modules/*/tests/e2e/*.js'] }; – dcpartners Mar 20 '17 at 01:09
  • Huzzah! Good point noting that you need to run `webdriver-manager start` on a different console. – cnishina Mar 23 '17 at 21:04