timjroberts / cucumber-js-tsflow

Provides 'specflow' like bindings for Cucumber.js in TypeScript 1.7+.
MIT License
133 stars 34 forks source link

generating step definitions #3

Closed tanneerumahesh closed 5 years ago

tanneerumahesh commented 8 years ago

hi, is there any way to generate step definitions in automated way? rather than typing all steps manually.

thanks in advance

timjroberts commented 8 years ago

I think this would have to be done by some other additional tooling. The cucumber-tsflow package is something that simply allows you to bind class and methods to CucumberJS's functional runtime.

derkoe commented 8 years ago

I think this already works - just run the feature without any step definitions. In the log you'll see the generated definitions for you:

Warnings:

1) Scenario: Demo Scenario - src\main.feature:8
   Step: Then the thing should work - src\main.feature:11
   Message:
     Undefined. Implement with the following snippet:
       @then(/^the thing should work$/)
       public ThenXXX (callback): void {
         // Write code here that turns the phrase above into concrete actions
         callback.pending();
       }
samvloeberghs commented 7 years ago

@derkoe indeed, it's standard behavior of cucumber

swaz90 commented 7 years ago

It's normal Cucumber behaviour to output the suggested code snippet for any steps that it can't find a binding for and you can copy and paste them. But out of the box Cucumber will suggest snippets that aren't cucumber-js-tsflow compatible, i.e. they don't have the nice binding syntax. However, I came across cucumber-snippets-tsflow (https://github.com/johngrimsey/cucumber-snippets-tsflow) which will switch the snippet generation over to the cucumber-tsflow way.

For the same undefined step:

cucumber.js

 Undefined. Implement with the following snippet:

   this.Then(/^the result contains "([^"]*)"$/, function (arg1, callback) {
     // Write code here that turns the phrase above into concrete actions
     callback(null, 'pending');
   });

cucumber.js --snippet-syntax ./node_modules/cucumber-snippets-tsflow

 Undefined. Implement with the following snippet:

   @then(/^the result contains "([^"]*)"$/)
   public theResultContains(arg1: string, callback): void {
     // Write code here that turns the phrase above into concrete actions
     callback(null, 'pending');
   }

Not sure why you got the cucumber-tsflow ready output @derkoe. Maybe you already have this installed :)