Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Automatic Step Generation in cucumber javascript using javascript

Tags:

cucumberjs

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?

like image 954
hghgh Avatar asked Mar 06 '14 21:03

hghgh


People also ask

Can we use Cucumber with JavaScript?

Cucumber. js is available as an npm module. It works with both Node. js and browsers.

What is BDD in JavaScript?

BDD stands for behavior-driven development. It's a software development methodology whose goal is to foster collaboration between developers and nontechnical people in a software project.

How do you do multiple step definitions on cucumbers?

You can have all of your step definitions in one file, or in multiple files. When you start with your project, all your step definitions will probably be in one file. As your project grows, you should split your step definitions into meaningful groups in different files.


1 Answers

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.

like image 115
Lean Prop Avatar answered Oct 13 '22 00:10

Lean Prop