cucumber-js
Cucumber for JavaScript
JavaScript·Cucumber
IntelliJ has a plugin for Cucumber.js. This suppose to enable running and debugging inside the IDE. The run configuration for cucumber.js works, but the debug mode is deactivated (Debug button can not be clicked). Does anybody else has the same problem and managed to solve it? Debugging is very essential to me. Thanks!
Source: (StackOverflow)
I am just struggeling if there is solution to do a code coverage analysis of the tested code which was executed in javascript cucumber?
Also the code coverage should be provided in the cobertura file format to embed it in our existing analysis of the backend code.
Can anyone help me on this issue?
Source: (StackOverflow)
I am using Protractor with Cucumber (js). I would like to generate report files just like with the Cucumber-JVM version. I have seen examples when using Protractor with Jasmine, but practically nothing with Cucumber.
How do you generate reports when using this configuration?
The final goal is to publish this report in Jenkins, or anywhere else if they are directly generated in HTML.
Thanks!
Source: (StackOverflow)
I am implementing BeforeFeature hook and I want to know which feature I am in
var hooks = function () {
this.registerHandler('BeforeFeature', function (event, callback) {
console.log(event.feature ????)
});
};
When I debug, on the console, event.feature is undefined. I can do event.getName(), then obviously I get "BeforeFeature" as result. Anyone knows how I can get the feature that it's going to evaluate? Thanks.
Source: (StackOverflow)
I have multiple feature files and I would really love to run just one file or just one scenario or just one tag.
I know I could just provide one file in my specs in my cucumberConf.js, but I would like to run it once without fiddling with my cucumberConf.js.
Which arguments do I need to type in when running protractor?
Source: (StackOverflow)
As of 0.20.1 Cucumber is now fully supported in Protractor but I'm battling to find any documentation on how to configure it properly. Any idea how you would setup world.js?
I have found this example at https://github.com/whyvez/angular-cucumber-example/blob/master/features/support/world.coffee but I'm not sure if you would still need to specify all the require modules and configuration as the protractor config file (referenceConf.js) would have all this info already.
assert = require 'assert'
path = require 'path'
protractor = require 'protractor'
webdriver = require 'selenium-webdriver'
driver = new webdriver.Builder().
usingServer('http://localhost:4444/wd/hub').
withCapabilities(webdriver.Capabilities.chrome()).
build()
driver.manage().timeouts().setScriptTimeout(100000)
ptor = protractor.wrapDriver driver
class World
constructor: (callback) ->
@browser = ptor
@By = protractor.By
@assert = assert
callback()
module.exports.World = World
Source: (StackOverflow)
How can i get current Feature, Scenario and Step in World?
I tried this way but I only have the Scenario name and description :
module.exports = function () {
/**
* Before each scenario
*/
this.Before(function (scenario, callback) {
console.log(scenario);
callback();
});
};
Thanks for your help.
Source: (StackOverflow)
I am wondering if it is possible to use cucumber(js) for BDD unit testing?
Cucumber is known to be runable as a acceptance testing framework. But I have never seen examples if and how cucumber may be used as a BDD unit testing.
Is cucumber able to provide unit tests?
Is it uncommon to use cucumber for unit testing?
Source: (StackOverflow)
I have an AfterFeatures hook that I'm using to try to gracefully shut down an expressjs web server that is used for testing only. In this hook, I need to call the visit method, which has been added to World, but I apparently don't have access to World from within this hook. What can I do to gain access to things in World inside this and other hooks?
// features/support/after_hooks.js
var myAfterHooks = function () {
this.registerHandler('AfterFeatures', function (event, callback) {
this.visit('/quit', callback);
});
};
module.exports = myAfterHooks;
Source: (StackOverflow)
I'm currently trying to instantiate a variable with the contents of the getText method using webdriverio.
a = String(browser.getText('.field_notice'));
When I attempt to print the variable this is the output:
[object Object]
Thanks for the help!
Source: (StackOverflow)
(I have seen this SO discussion, but was not sure how to apply it to my case, so I’m asking a new question. Hope it’s not a duplicate)
I am testing a form written in Angular using Protractor with Cucumber.js.
So what I would like to do is to tell Protractor to go click on the title of a field (which is a link) then, when that field appears, enter some text in it, then move on to the title of the next field, and so on.
Here is my step in Cucumber:
When I fill the form with the following data
| field | content |
| First Name | John |
| Last Name | Doe |
| Address | Some test address |
# and so forth
Here’s a half-hearted attempt at step definition:
this.When(/^I fill the form with the following data$/, function (table, callback) {
data = table.hashes();
# that gives me an array of objects such as this one:
# [ { field: 'First Name', content: 'John' },...]
for (var i = 0; i < data.length; i++){
var el = element(by.cssContainingText('#my-form a', data[i].field));
el.click().then(function(){
var fieldEl = el.element(by.xpath("../.."))
.element(by.css('textarea'));
fieldEl.sendKeys(data[i].content);
});
}
};
callback();
});
But of course, this isn't working, because even before Protractor has time to click on a field name and enter the necessary data into the field, the callback function is called, and Cucumber moves to the next step.
So my question is, how can I, using Protractor with Cucumber.js, write the step to insert data defined in the Cucumber table into the form fields? Is this feasible using a for loop?
Source: (StackOverflow)
My world.js looks like this:
var protractor = require('protractor');
var webdriver = require('selenium-webdriver');
var driver = new webdriver.Builder().usingServer('xxxxx').
withCapabilities(webdriver.Capabilities.firefox()).build();
driver.manage().timeouts().setScriptTimeout(100000);
module.exports.World = function World(callback) {
this.browser = protractor.wrapDriver(driver);
this.by = protractor.by;
callback();
};
then in steps.js:
{
element(by.id('username')).sendKeys("admin");
}
When I ran it using cucumber.js, the error is:
TypeError: Cannot call method 'id' of undefined
but if I remove world.js and run it using protractor, it works.
How can I fix this?
Source: (StackOverflow)
I'm trying to use the following gulpfile.js in order to watch for changes, restart my server, and re-run my tests (cucumber.js). Changing a cucumber spec, or a file in my application both successfully trigger the process. However, the updated content of the specs is ignored! It's like the spec is cached. How can I ensure the latest specs are executed?
File content:
"use strict";
var gulp = require( "gulp" );
var cucumber = require( "gulp-cucumber" );
var watch = require( "gulp-watch" );
var server = require( 'gulp-develop-server' );
gulp.task( "cukes", function( done ) {
return gulp.src( "specs/**/*.feature" ).pipe( cucumber( {
"steps" : "specs/steps/**/*.js,support/*_hooks.js",
"format" : "pretty"
} ) );
} );
gulp.task( "test", [ "server:start", "cukes" ] );
gulp.task( "server:start", function() {
server.listen( { path: "./index.js" } );
} );
gulp.task( "watch", [ "server:start" ], function() {
watch( [ "lib/**/*", "specs/**/*" ], function() {
server.restart( function() {
setTimeout( function() { gulp.start( "cukes" ); }, 500 );
} );
} );
} );
Source: (StackOverflow)
Trying out some BDD with AngularJS so I'm having a go at automating scenarios with Protractor and CucumberJS. Strangely, It been the devils job trying to get step defintions to fail intelligently.
Features.feature
Feature: Calculator
As a user
I want to perform arithmetic operations
So that I don't have to think too hard
Scenario: Addition
Given I have opened the calculator application
When I add 2 and 2
Then the result 4 should be displayed
Steps.js
module.exports = function() {
this.Given(/^I have opened the calculator application$/, function (callback) {
//load protractor config baseurl
browser.get('').then(
callback());
});
this.When(/^I add (\d+) and (\d+)$/, function (arg1, arg2, callback) {
//enter numbers to be added
element(by.model('firstNumber')).sendKeys(arg1);
element(by.model('secondNumber')).sendKeys(arg2);
//select mathematical operator from dropdown list
element(by.css('select')).click();
element(by.css('select option[value="0"]')).click();
//hit the calculate button
element(by.buttonText('=')).click();
callback();
});
this.Then(/^the result (\d+) should be displayed$/, function (arg1, callback) {
element(by.binding('result')).getText()
.then(function(result){
result === arg1 ? callback() : callback.fail();
});
});
};
Index.html
<!doctype html>
<html class="no-js">
<head>
<meta charset="utf-8">
<title></title>
</head>
<body ng-app="calculator" ng-controller="MainCtrl">
<input ng-model="firstNumber">
<select ng-model="selectedOperation" ng-options="op as op.value for op in operations"></select>
<input ng-model="secondNumber">
<button ng-click="Calculate()">=</button>
<span ng-bind="result"></span>
<script src="bower_components/angular/angular.js"></script>
<script src="scripts/app.js"></script>
</body>
</html>
App.js
angular
.module('calculator', [])
.controller('MainCtrl', function ($scope) {
$scope.operations = [
{ label: 'Add', value: '+' },
{ label: 'Subtract', value: '-' }
];
$scope.selectedOperation = $scope.operations[0];
$scope.Calculate = function(){
switch($scope.selectedOperation.label) {
case 'Add':
var result = Number($scope.firstNumber) + Number($scope.secondNumber);
break;
case 'Subtract':
var result = Number($scope.firstNumber) - Number($scope.secondNumber);
break;
};
$scope.result = result !== NaN || result === 0 ? result : 'Boo! bad input!';
};
});
Protractor output:
1 scenario (1 passed)
3 steps (3 passed)
The setup above works fine. Protractor gives the correct output and I can fail the scenario by evaluating incorrect outcomes in the Then() step. Seems nice.
First problem I see is when I try to make the When step fail. For example using the same setup above but attempting to locate a nonexistent element.
this.When(/^I add (\d+) and (\d+)$/, function (arg1, arg2, callback) {
//enter numbers to be added. Sabotage edition!
element(by.model('AintNoGood')).sendKeys(arg1);
element(by.model('secondNumber')).sendKeys(arg2);
//select mathematical operator from dropdown list
element(by.css('select')).click();
element(by.css('select option[value="0"]')).click();
//hit the calculate button
element(by.buttonText('=')).click();
callback();
});
Protractor output:
NoSuchElementError: No element found using locator: by.model("AintNoGood")
...
1 scenario (1 failed)
3 steps (1 failed, 2 passed)
The 2nd step fails correctly. I'm under the impression that when a step fail all subsequent steps are skipped, but protractor continues on to the 3rd step which passes anyway.
Stranger still...I empty the HTML. BDD test-first and all.
Inmdex.html
<!doctype html>
<html class="no-js">
<head>
<meta charset="utf-8">
<title></title>
</head>
<body ng-app="calculator" ng-controller="MainCtrl">
<!--Ghost town here-->
<script src="bower_components/angular/angular.js"></script>
<script src="scripts/app.js"></script>
</body>
</html>
Assuming I was going through the scenario one step at a time, I write the defintion for the 2nd step assuming it will fail.
module.exports = function() {
this.Given(/^I have opened the calculator application$/, function (callback) {
//load protractor config baseurl
browser.get('').then(
callback());
});
this.When(/^I add (\d+) and (\d+)$/, function (arg1, arg2, callback) {
//enter numbers to be added
element(by.model('firstNumber')).sendKeys(arg1);
element(by.model('secondNumber')).sendKeys(arg2);
//select mathematical operator from dropdown list
element(by.css('select')).click();
element(by.css('select option[value="0"]')).click();
//hit the calculate button
element(by.buttonText('=')).click();
callback();
});
this.Then(/^the result (\d+) should be displayed$/, function (arg1, callback) {
callback.pending();
});
};
Protractor output:
1 scenario (1 pending)
3 steps (1 pending, 2 passed)
So the 2nd step passes. Clearly it should not when there are none of the elements it it supposed to be locating in the html.
Questions:
Any idea what's going on here?
If not, before I spend more time trying to make sense of it, I'm wondering if anyone has had success using Protractor with CucumberJS?
Source: (StackOverflow)