Ask a Question

BDD Step Reuse

SOLVED
loridee
New Contributor

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.

1 ACCEPTED SOLUTION

Accepted Solutions
AlexKaras
Community Hero

Re: BDD Step Reuse

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() {

  // ...

};

 

?

 

Regards,
  /Alex [Community Hero]
____
[Community Heroes] are not employed by SmartBear Software but
are just volunteers who have some experience with the tools by SmartBear Software
and a desire to help others. Posts made by [Community Heroes]
may differ from the official policies of SmartBear Software and should be treated
as the own private opinion of their authors and under no circumstances as an
official answer from SmartBear Software.
The [Community Hero] signature is used with permission by SmartBear Software.
https://community.smartbear.com/t5/custom/page/page-id/hall-of-fame
================================

View solution in original post

5 REPLIES 5
AlexKaras
Community Hero

Re: BDD Step Reuse

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() {

  // ...

};

 

?

 

Regards,
  /Alex [Community Hero]
____
[Community Heroes] are not employed by SmartBear Software but
are just volunteers who have some experience with the tools by SmartBear Software
and a desire to help others. Posts made by [Community Heroes]
may differ from the official policies of SmartBear Software and should be treated
as the own private opinion of their authors and under no circumstances as an
official answer from SmartBear Software.
The [Community Hero] signature is used with permission by SmartBear Software.
https://community.smartbear.com/t5/custom/page/page-id/hall-of-fame
================================

View solution in original post

TanyaYatskovska
Community Manager

Re: BDD Step Reuse

Thanks for your help, Alex.

@loridee, is this what you were looking for?

---------
Tanya Yatskovskaya
SmartBear Community and Education Manager


Did my reply answer your question? Give Kudos or Accept it as a Solution to help others. ⬇️⬇️⬇️
loridee
New Contributor

Re: BDD Step Reuse

 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!

AlexKaras
Community Hero

Re: BDD Step Reuse

Hi,

 

instead of two methods, just the Given and When steps, I now have 3

From the coding point of view I see nothing bad to have a common reusable function...

...however:

as some other BDD frameworks do.

Can you name them? I'm interested to read their documentation and see examples.

 

Regards,
  /Alex [Community Hero]
____
[Community Heroes] are not employed by SmartBear Software but
are just volunteers who have some experience with the tools by SmartBear Software
and a desire to help others. Posts made by [Community Heroes]
may differ from the official policies of SmartBear Software and should be treated
as the own private opinion of their authors and under no circumstances as an
official answer from SmartBear Software.
The [Community Hero] signature is used with permission by SmartBear Software.
https://community.smartbear.com/t5/custom/page/page-id/hall-of-fame
================================
loridee
New Contributor

Re: BDD Step Reuse

Froglogic , according to this blog posting.  See the final section titled 'Use same step definition for different step types'...

 

https://www.froglogic.com/blog/design-good-bdd-steps/

 

 

 

cancel
Showing results for 
Search instead for 
Did you mean: