SOLVED: Protractor-Cucumber-Framework Error: expected #EOF, #Language, #TagLine, #FeatureLi...

Datetime:2016-08-23 01:13:36          Topic:          Share

I seriously love using protractor-cucumber-framework, but it can be quite annoying trying to configure it perfectly, especially when you're doing it for the first time. I was having some trouble setting it up with my recent project, and decided to write a post about this specific error that I seem to run into often (hopefully that'll change soon! hehe) when adding this to my projects.

The Error

This is the error I was getting: 

​[launcher] Error: CompositeParserException: Parser errors:

(1:1): expected: #EOF, #Language, #TagLine, #FeatureLine, #Comment, #Empty, got '//http://chaijs.com/'

(2:1): expected: #EOF, #Language, #TagLine, #FeatureLine, #Comment, #Empty, got 'var chai = require('chai');'

(4:1): expected: #EOF, #Language, #TagLine, #FeatureLine, #Comment, #Empty, got '//https://github.com/domenic/chai-as-promised/'

(5:1): expected: #EOF, #Language, #TagLine, #FeatureLine, #Comment, #Empty, got 'var chaiAsPromised = require('chai-as-promised');'

(6:1): expected: #EOF, #Language, #TagLine, #FeatureLine, #Comment, #Empty, got 'chai.use(chaiAsPromised);'

(8:1): expected: #EOF, #Language, #TagLine, #FeatureLine, #Comment, #Empty, got 'var expect = chai.expect;'

(10:1): expected: #EOF, #Language, #TagLine, #FeatureLine, #Comment, #Empty, got 'module.exports = function() {'

(12:3): expected: #EOF, #Language, #TagLine, #FeatureLine, #Comment, #Empty, got '//var ptor = protractor.getInstance();'

The Problem

the problem here for me was that I was adding the step definitions files in the section where you add feature files. This was causing the Gherkin interpreter to freak out and spit out this error message. In the "specs" section of the config file I was actually putting both the glob path to the features files and the step definition files!

The Solution

As I alluded to in the  Problem section above, I was putting the step definition files in the files  parameter of the protractor config file. The  files attribute should only be for files that end in a .feature extension. For your step definition files, add these in the  cucumberOpts - require parameter. "cucumberOpts" is a parameter that is set to an object, and a parameter on that object is  require.  This parameter takes a array with file glob patters, and here you would include a glob to your step definition files. 

Back to Business

After fixing that error my tests ran and it was smooth sailing! Now that all the troubleshooting is over, it's time to get down to the real work of collaborating with other stakeholders to formulate the feature scenarios and then implementing all the step definitions! Have fun! :)