Forum Discussion

loridee's avatar
loridee
New Contributor
6 years ago

BDD Step Reuse

Hi,

 

Anyone have any ideas or suggestions for reusing 2 BDD steps that differ only in their keyword? 

 

Given I log in as John Smith

When I log in as John Smith

 

Would really love this to be either a single step (can I wildcard the Given or When keywords?!) or two steps but one step calls the other:

 

Given ("I log in as John Smith", function () {

     //  login code here

});

 

When ("I log in as John Smith", function () {

     // call the Given here, as it already has the necessary code implemented

});

 

Some BDD libraries also offer a generic 'Step' keyword which matches any step type, but I don't believe TestComplete supports it.

 

Any help/suggestions greatly appreciated! Trying our best to prevent massive code bloat.

  • Hi,

     

    Hm-m-m...

    Is there anything that prevents this:

    Given ("I log in as John Smith", function () {

         login();

    });

     

    When ("I log in as John Smith", function () {

         login();

    });

     

    function login() {

      // ...

    };

     

    ?

     

  • AlexKaras's avatar
    AlexKaras
    Champion Level 3

    Hi,

     

    Hm-m-m...

    Is there anything that prevents this:

    Given ("I log in as John Smith", function () {

         login();

    });

     

    When ("I log in as John Smith", function () {

         login();

    });

     

    function login() {

      // ...

    };

     

    ?

     

      • loridee's avatar
        loridee
        New Contributor

         Thanks Alex,

         

        That solution you proposed is what we are doing already. Yep, it works, so I have accepted as a solution. But it gives us some bloat - instead of two methods, just the Given and When steps, I now have 3 - the Given, the When and the login method. If I have a lot of step reuse that results in a lot of extra methods.

         

        We were just hoping TestComplete BDD had support for one step calling another step, or step binding based on everything but the keywords as some other BDD frameworks do.  

         

        Thanks all!