Closed jludvice closed 7 years ago
Adding following npm dev dependencies
"devDependencies": {
"@types/cucumber": "^0.0.37",
"cucumber": "^1.3.1",
"cucumber-tsflow": "^1.1.2",
"protractor-cucumber-framework": "^0.6.0",
}
protractor-cucumber-framework
configuration - protractor.conf.js
specs: [
// specs are feature files
'./features/**/*.feature'
],
// switch jasmine to custom (cucumber is not supported framework)
framework: 'custom',
frameworkPath: require.resolve('protractor-cucumber-framework'),
cucumberOpts: {
require: [
// load steps definitions
'features/**/*.steps.ts'
],
format: 'pretty'
},
include cucumber-tsflow
to specify cucumber feautre <=> step binding with typescript annotations
Example
Scenario: Adding two numbers
Given I enter '2' and '8'
@given(/^I enter '(\d+)' and '(\d+)'$/)
public givenTwoNumbers(num1: string, num2: string, callback: CallbackStepDefinition): void {
Add chai
and chai-as-promised
for assert/expectations on promise objects
https://github.com/domenic/chai-as-promised
Added https://www.npmjs.com/package/cucumber-html-reporter to generate html report.
I needed to create env.js
file where are some cucumber configurations, like
After
stepworking example of env.js
(note it must be included in protractor.conf.js
)
module.exports = function () {
this.setDefaultTimeout(400 * 1000);
/**
* create screenshot after each cucumber scenario
*/
this.After(function (scenario, next) {
browser.takeScreenshot().then(function (png) {
var decodedImage = new Buffer(png, 'base64');
scenario.attach(decodedImage, 'image/png', next);
}, function (err) {
next(err);
});
});
};
Lot of comments suggest this snipped for attaching screenshots,
but it didn't work for me because data was encoded incorrectly - needed to remove .toString('binary');
browser.takeScreenshot().then(function (png) {
var fs = require('fs');
//var base64Image = new Buffer(png, 'binary').toString('base64');
var decodedImage = new Buffer(png, 'base64').toString('binary');
scenario.attach(decodedImage, 'image/png');
});
Completed w/ https://github.com/redhat-ipaas/ipaas-ui/pull/308
Consider https://github.com/samvloeberghs/protractor-gherkin-cucumberjs-angular2 EDIT this is just template project.