9

I am using javascript for cucumber javascript for automation.My concern is can i generate .js file for step definitions automatically? as of now am copy pasting them(steps) from command line window so can I skip it and directly generate the step file?

hghgh
  • 91
  • 1
  • 3

2 Answers2

4

Two Suggestions:

1. You can create a new gherkin file, and run it with cucumber.js, it will generate JavaScript stub automatically for you. For example:

"cucumber-js math.feature"

It will output something like:


    1) Scenario: easy maths - math.feature:7
   
    Step: Given a variable set to 1 - math.feature:8
   
    Message:

     Undefined. Implement with the following snippet:

           this.Given(/^a variable set to (\d+)$/, function (arg1, callback) {
             // Write code here that turns the phrase above into concrete actions
             callback(null, 'pending');
           });

It has the parameter automatically generated based on your tests. You can then copy the snippet into your code file.

2. If you are using Windows 10, you can also try a BDD development tool CukeTest, and it provide some convenient features like code generation from step text, or navigate between code and steps etc.

anothernode
  • 5,100
  • 13
  • 43
  • 62
Lean Prop
  • 111
  • 6
-1

You can use 'Live Template'/'Code snippets' in your IDE. It's the best way to improve performace. https://www.jetbrains.com/help/idea/creating-code-constructs-by-live-templates.html

If you use VC Code then you can use extension Cucumber (Gherkin) Syntax and Snippets:

https://marketplace.visualstudio.com/items?itemName=stevejpurves.cucumber

pierozek
  • 27
  • 2