cucumber.decorators
TypeScript icon, indicating that this package has built-in type declarations

2.0.0 • Public • Published

Cucumber.Decorators

Typescript Decorators for Cucumber Tests

Cucumber Example

Feature File

Feature: Local server test
    As a developer
    I want check the web site
 
    Background:
        Given I open the url "http://www.google.com"
 
    Scenario: Google
        Then I expect that the title is "Google"

Typescript Step File

import { cucumber, given, when } from '../decorator/decorator'
import action from '../helpers/action';
import check from '../helpers/check';
 
@cucumber
class checkSite {
    @given(/^I open the (url|site) "([^"]*)?"$/)
    public openWebsite() {
        return action.Open;
    };
 
    @when(/^I expect that the title is( not)* "([^"]*)?"$/)
    public title() {
        return check.Title
    };
};
 
let CheckSite = new checkSite();

Development Prerequisites

  • Typescript
  • JAVA
  • Chromedriver

Run Example

To run the example you will need to clone the repo as the npm package was designed to be as small as possible.

git clone https://github.com/FlippieCoetser/Cucumber.Decorators
npm install
npm run build
npm run demo

Note: When node-gyp produces an error, first install windows-build-tools globally and set the config to the correct version.
npm install --global --production windows-build-tools
npm config set msvs_version 2015 --global

Explanation

The cucumber Decorator updates the class constuctor to ensure each method within the class is executed during instantiation.

export function cucumber(target: Function){
    for (var member in target.prototype) {
        target.prototype[member]();
    }
}
 

The given Decorator wraps the provided method and passes the expression into the required cucumber function.

export function given(expression: any) {
    return function(target: Object, propertyKey: string, descriptor: TypedPropertyDescriptor<any>){
        let assertion = descriptor.value();
 
        descriptor.value = () => Given(expression,assertion);
        
        return descriptor;
    }
}
 

Note: the when and then Decorator operates in a similar fashion as the given Decorator.

Package Sidebar

Install

npm i cucumber.decorators

Weekly Downloads

1

Version

2.0.0

License

MIT

Unpacked Size

6.43 kB

Total Files

5

Last publish

Collaborators

  • flippie.coetser