Closed HaydenMeloche closed 7 years ago
Hi @HaydenMeloche
Tnx for the compliments. Which version of CucumberJS are you using?
When I look at the docs here you are using a parser that only works for version < 0.9.0 of CucumberJS. I would advice using the cucumberMulti
I also used you logging against the parser that should work with versions higher then 0.9.0 and that also doesn't work, so it would be nice to know your version.
A workaround (I'm using this in my current project) is to add a hook like described here. This is only for CucumberJS 1, for CucumberJS 2 you can use this piece of code
var {defineSupportCode} = require('cucumber');
defineSupportCode(function({After}) {
After(function (scenarioResult, callback) {
if (scenarioResult.status === 'failed') {
// Log the spec to the console for protractor-flake to be able to rerun the failed specs
console.log('Specs:', scenarioResult.scenario.uri);
}
callback();
});
});
With this hook you are version independent.
Hope it helps
Grtz
wswebcreation
@wswebcreation Thanks for the response.
I am using "cucumber": "^1.3.3"
.
I tried adding a hook for version 1. mention in the docs but it seems like the parser tries to read it and it errors. LOG: `> protractor-cucumber-hayden@1.0.0 test C:\OBIS\Protractor Testing
protractor-flake --parser cucumberMulti --max-attempts=2 -- protractor.conf.js
[09:21:11] I/launcher - Running 1 instances of WebDriver
[09:21:11] I/hosted - Using the selenium server at http://localhost:4444/wd/hub
[09:21:13] E/launcher - Error: CompositeParserException: Parser errors:
(1:1): expected: #EOF, #Language, #TagLine, #FeatureLine, #Comment, #Empty, got 'var {defineSupportCode} = require('cucumber');'
(3:1): expected: #EOF, #Language, #TagLine, #FeatureLine, #Comment, #Empty, got 'defineSupportCode(function({After}) {'
(4:5): expected: #EOF, #Language, #TagLine, #FeatureLine, #Comment, #Empty, got 'var afterHook = function () {'
(5:9): expected: #EOF, #Language, #TagLine, #FeatureLine, #Comment, #Empty, got 'this.After(function (scenario, callback) {'
(6:15): expected: #EOF, #Language, #TagLine, #FeatureLine, #Comment, #Empty, got 'if (scenario.isFailed()) {'
(7:19): expected: #EOF, #Language, #TagLine, #FeatureLine, #Comment, #Empty, got 'console.log('Specs:', scenario.getUri());'
(8:15): expected: #EOF, #Language, #TagLine, #FeatureLine, #Comment, #Empty, got '}'
(9:15): expected: #EOF, #Language, #TagLine, #FeatureLine, #Comment, #Empty, got 'callback();'
(10:9): expected: #EOF, #Language, #TagLine, #FeatureLine, #Comment, #Empty, got '});'
(11:7): expected: #EOF, #Language, #TagLine, #FeatureLine, #Comment, #Empty, got '};'
(12:7): expected: #EOF, #Language, #TagLine, #FeatureLine, #Comment, #Empty, got 'module.exports = afterHook;'
path: C:\OBIS\Protractor Testing\afterHooks.js
at Function.Errors.CompositeParserException.create (C:\OBIS\Protractor Testing\node_modules\gherkin\lib\gherkin\errors.js:27:13)
at addError (C:\OBIS\Protractor Testing\node_modules\gherkin\lib\gherkin\parser.js:88:45)
at matchTokenAt_0 (C:\OBIS\Protractor Testing\node_modules\gherkin\lib\gherkin\parser.js:261:5)
at matchToken (C:\OBIS\Protractor Testing\node_modules\gherkin\lib\gherkin\parser.js:149:14)
at Parser.parse (C:\OBIS\Protractor Testing\node_modules\gherkin\lib\gherkin\parser.js:72:15)
at C:\OBIS\Protractor Testing\node_modules\cucumber\lib\cucumber\parser.js:18:36
at Array.forEach (native)
at Object.parse (C:\OBIS\Protractor Testing\node_modules\cucumber\lib\cucumber\parser.js:12:22)
at Object.getFeatures (C:\OBIS\Protractor Testing\node_modules\cucumber\lib\cucumber\runtime.js:39:35)
at Object.start (C:\OBIS\Protractor Testing\node_modules\cucumber\lib\cucumber\runtime.js:11:27)
[09:21:13] E/launcher - Process exited with error code 100
Using cucumberMulti to parse output
Re-running tests: test attempt 2
Tests failed but no specs were found. All specs will be run again.
AfterHook.js
var {defineSupportCode} = require('cucumber');
defineSupportCode(function({After}) {
var afterHook = function () {
this.After(function (scenario, callback) {
if (scenario.isFailed()) {
console.log('Specs:', scenario.getUri());
}
callback();
});
};
module.exports = afterHook;
}
protractor.conf.js
exports.config = {
seleniumAddress: 'http://localhost:4444/wd/hub',
framework: 'custom',
frameworkPath: require.resolve('protractor-cucumber-framework'),
specs: [
'afterHooks.js',
'features/*.feature'
],
cucumberOpts: {
require: 'features/steps/*_steps.js',
format: 'pretty'
}
}
Any ideas?
@wswebcreation I must be doing something else wrong. Still getting same error :(
[10:31:09] I/launcher - Running 1 instances of WebDriver
[10:31:09] I/hosted - Using the selenium server at http://localhost:4444/wd/hub
[10:31:35] E/launcher - Error: CompositeParserException: Parser errors:
(1:1): expected: #EOF, #Language, #TagLine, #FeatureLine, #Comment, #Empty, got 'var afterHook = function () {'
(2:5): expected: #EOF, #Language, #TagLine, #FeatureLine, #Comment, #Empty, got 'this.After(function (scenario, callback) {'
(3:11): expected: #EOF, #Language, #TagLine, #FeatureLine, #Comment, #Empty, got 'if (scenario.isFailed()) {'
(4:15): expected: #EOF, #Language, #TagLine, #FeatureLine, #Comment, #Empty, got 'console.log('Specs:', scenario.getUri());'
(5:11): expected: #EOF, #Language, #TagLine, #FeatureLine, #Comment, #Empty, got '}'
(6:11): expected: #EOF, #Language, #TagLine, #FeatureLine, #Comment, #Empty, got 'callback();'
(7:5): expected: #EOF, #Language, #TagLine, #FeatureLine, #Comment, #Empty, got '});'
(8:3): expected: #EOF, #Language, #TagLine, #FeatureLine, #Comment, #Empty, got '};'
(10:3): expected: #EOF, #Language, #TagLine, #FeatureLine, #Comment, #Empty, got 'module.exports = afterHook;'
path: C:\OBIS\Protractor Testing\afterHooks.js
at Function.Errors.CompositeParserException.create (C:\OBIS\Protractor Testing\node_modules\gherkin\lib\gherkin\errors.js:27:13)
at Parser.parse (C:\OBIS\Protractor Testing\node_modules\gherkin\lib\gherkin\parser.js:79:45)
at C:\OBIS\Protractor Testing\node_modules\cucumber\lib\cucumber\parser.js:18:36
at Array.forEach (native)
at Object.parse (C:\OBIS\Protractor Testing\node_modules\cucumber\lib\cucumber\parser.js:12:22)
at Object.getFeatures (C:\OBIS\Protractor Testing\node_modules\cucumber\lib\cucumber\runtime.js:39:35)
at Object.start (C:\OBIS\Protractor Testing\node_modules\cucumber\lib\cucumber\runtime.js:11:27)
at Object.run (C:\OBIS\Protractor Testing\node_modules\cucumber\lib\cucumber\cli.js:75:15)
at C:\OBIS\Protractor Testing\node_modules\protractor-cucumber-framework\index.js:38:36
at Function.promise (C:\OBIS\Protractor Testing\node_modules\q\q.js:682:9)
[10:31:35] E/launcher - Process exited with error code 100
Using cucumberMulti to parse output
Re-running tests: test attempt 2
Tests failed but no specs were found. All specs will be run again.
Can you create a simple git project and give me rights, then I'll fix it for you tonight or tomorrow.
Grtz wswebcreation
@wswebcreation Sorry for wasting your time. I figured out what it was. I had require
in the wrong section in protractor.conf.js
................
Thanks for your help anyway!
@HaydenMeloche glad you figured it out.
@wswebcreation thanks for helping debug! I wonder if we could consolidate the cucumber parsing since cucumberMulti
supports both multi and non multi specs. We could work to deprecate or just drop it and make a major version bump.
@HaydenMeloche
No problem
@NickTomlin
Looks like you can read minds. I first want to check what CucumberJS 3 does, was just released this week. Protractor-cucumber-framework was fixed today. Hope to get my boilerplate up and running this weekend and then will create a PR for protractor-flake to remove the CucumberJS parser so you will need to make a major.
By the way, the hook that logs a line in the console, that's also in the docs, is a more stable way to use to read the logs. Can't we also create something for Jasmine and Mocha, that will save a lot of debugging 🤔😁
Yeah I think that'd be great if we could find a way to insert logging into the frameworks and not have to worry as much about parsing
Hi! First of all, thank you for this plugin. I have the plugin working I'm just having problems parsing cucumber output log so it runs every test case if 1 fails. Any thoughts on what I could do to fix this?
Windows 7 Node version =
6.9.1
Protractor version =5.1.2
Command I am running:
protractor-flake --parser cucumber --max-attempts=2 -- protractor.conf.js
Output I get: