cancel
Showing results for 
Search instead for 
Did you mean: 

BDD Step Reuse

SOLVED
Highlighted
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.

Tags (1)
1 ACCEPTED SOLUTION

Accepted Solutions
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 Expert Group]
____
[Community Expert Group] members 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. Postings made by [Community Expert Group] members
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.
[Community Expert Group] signature is used with permission by SmartBear Software.
http://smartbear.com/forums/f83/t86934/community-experts/
================================
5 REPLIES 5
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 Expert Group]
____
[Community Expert Group] members 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. Postings made by [Community Expert Group] members
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.
[Community Expert Group] signature is used with permission by SmartBear Software.
http://smartbear.com/forums/f83/t86934/community-experts/
================================
Community Manager

Re: BDD Step Reuse

Thanks for your help, Alex.

@loridee, is this what you were looking for?

---------
Tanya Gorbunova
SmartBear Community Manager

Did my reply answer your question? Give Kudos or Accept it as a Solution to help others.↓↓↓↓↓
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!

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 Expert Group]
____
[Community Expert Group] members 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. Postings made by [Community Expert Group] members
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.
[Community Expert Group] signature is used with permission by SmartBear Software.
http://smartbear.com/forums/f83/t86934/community-experts/
================================
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/

 

 

 

New Here?
Join us and watch the welcome video:
6 / 7 API Testing Mistakes Video
Top Kudoed Authors