Aristarkh Artemiy
Aristarkh Artemiy

Reputation: 347

Error using Protractor 2.1.0 with CucumberJS

I'm experiencing trouble upgrading to Protractor 2.1 from Protractor 2.0, and suspect it's an issue with the use of Protractor 2.1 and CucumberJS. When I edit the package.json to downgrade to Protractor 2.0.0, and reinstall the node packages, the issue is resolved. What's causing the error in Protractor 2.1.0? How can I rewrite my project to work with Protractor 2.1.0 and Cucumber JS?

My project files and their contents are listed below:

/path/to/myproject/conf.js

exports.config = {
  sauceUser: process.env.SAUCE_USERNAME,
  sauceKey: process.env.SAUCE_ACCESS_KEY,
  specs: [
    'features/*.feature'
  ],
  multiCapabilities: [
    {
      'browserName': 'chrome'
    }
  ],
  framework: 'cucumber',
  cucumberOpts: {
    require: 'features/stepDefinitions.js',
    format: 'summary'
  }
};

/path/to/myproject/features/demo.feature

Feature: Refund item

  Scenario: Jeff returns a faulty microwave
    Given Jeff has bought a microwave for $100
    And he has a receipt
    When he returns the microwave
    Then Jeff should be refunded $100

/path/to/myproject/features/stepDefinitions.js

module.exports = function() {
  this.Given(/^Jeff has bought a microwave for \$(\d+)$/, function (arg1, callback) {
    // Write code here that turns the phrase above into concrete actions
    callback.pending();
  });

  this.Given(/^he has a receipt$/, function (callback) {
    // Write code here that turns the phrase above into concrete actions
    callback.pending();
  });

  this.When(/^he returns the microwave$/, function (callback) {
    // Write code here that turns the phrase above into concrete actions
    callback.pending();
  });

  this.Then(/^Jeff should be refunded \$(\d+)$/, function (arg1, callback) {
    // Write code here that turns the phrase above into concrete actions
    callback.pending();
  });
};

/path/to/myproject/package.json

{
  "name": "strato-remake",
  "version": "1.0.0",
  "description": "",
  "main": "conf.js",
  "dependencies": {
  },
  "devDependencies": {
    "cucumber": "0.4.9",
    "protractor": "2.1.0"
  },
  "scripts": {
    "test": "echo \"Error: no test specified\" && exit 1"
  },
  "author": "",
  "license": "ISC"
}

When the node packages are installed, and Protractor is run:

$ npm install
$ $(npm bin)/protractor conf.js

The following error is printed to the terminal:

Using SauceLabs selenium server at http://ondemand.saucelabs.com:80/wd/hub
[launcher] Running 1 instances of WebDriver
[launcher] Error: TypeError: Cannot read property 'apply' of undefined
  at formatter.handleBeforeFeatureEvent (/path/to/myproject/node_modules/protractor/lib/frameworks/cucumber.js:83:41)
  at /path/to/myproject/node_modules/protractor/lib/frameworks/cucumber.js:153:15
  at Function.promise (/path/to/myproject/node_modules/protractor/node_modules/q/q.js:650:9)
  at /path/to/myproject/node_modules/protractor/lib/frameworks/cucumber.js:147:14
  at _fulfilled (/path/to/myproject/node_modules/protractor/node_modules/q/q.js:797:54)
  at self.promiseDispatch.done (/path/to/myproject/node_modules/protractor/node_modules/q/q.js:826:30)
  at Promise.promise.promiseDispatch (/path/to/myproject/node_modules/protractor/node_modules/q/q.js:759:13)
  at /path/to/myproject/node_modules/protractor/node_modules/q/q.js:525:49
  at flush (/path/to/myproject/node_modules/protractor/node_modules/q/q.js:108:17)
  at process._tickCallback (node.js:355:11)

[launcher] Process exited with error code 100

However, if I edit the package.json to downgrade to Protractor 2.0.0, and install the node packages again:

"devDependencies": {
  "cucumber": "0.4.9",
  "protractor": "2.0.0"
},

It then works when I run Protractor:

$ $(npm bin)/protractor conf.js

Using SauceLabs selenium server at http://ondemand.saucelabs.com:80/wd/hub
[launcher] Running 1 instances of WebDriver
1 scenario (1 pending)
4 steps (1 pending, 3 skipped)
SauceLabs results available at http://saucelabs.com/jobs/8a85b85e7a1c5dd344e694e392ec90c3
[launcher] 0 instance(s) of WebDriver still running
[launcher] chrome #1 passed

How do I rewrite this project for compatibility with Protractor 2.1.0 and Cucumber JS? Thank you!

Upvotes: 1

Views: 548

Answers (1)

Aristarkh Artemiy
Aristarkh Artemiy

Reputation: 347

This was the result of a bug in Protractor, which was fixed by this pull request. To use that particular commit, change your package.json to include:

"devDependencies": {
  "cucumber": "0.4.9",
  "protractor": "git+https://github.com/angular/protractor.git#0262268fa43b9eefac815d986740efa07bb15818"
},

Upvotes: 0

Related Questions