2.0.0 • Published 6 years ago

cucumber.decorators v2.0.0

Weekly downloads
3
License
MIT
Repository
github
Last release
6 years ago

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.

2.0.0

6 years ago

1.6.0

6 years ago

1.5.0

7 years ago

1.4.0

7 years ago

1.3.0

7 years ago

1.2.0

7 years ago

1.1.0

7 years ago

1.0.0

7 years ago