[Cucumber-JVM] Can we call scenario from another feature file in a sceanio??

3,060 views
Skip to first unread message

Mahesh Kumar Somaraju

unread,
Jan 8, 2016, 11:35:21 PM1/8/16
to Cukes
Hi All,

I did search for this topic in Google and understand the current Cucumber doesn't support calling scenario in a different feature file from a scenario. However I just wanted to give a check in the forum if there is any alternative solution to call other Scenarios.

The reason for this is the scenarios so huge and its tedious job to maintain them all in one single feature file and most of the times we need to reuse the existing scenario part of other scenarios. I don't want to create a duplicate of same steps in all feature files.

Please help me here.


Thanks,
Mahesh



Thomas Sundberg

unread,
Jan 9, 2016, 2:25:21 AM1/9/16
to cu...@googlegroups.com
On 8 January 2016 at 23:33, Mahesh Kumar Somaraju
<mahesh...@gmail.com> wrote:
> Hi All,
>
> I did search for this topic in Google and understand the current Cucumber
> doesn't support calling scenario in a different feature file from a
> scenario. However I just wanted to give a check in the forum if there is any
> alternative solution to call other Scenarios.
>

If you mean that you would like to use a scenario from another
scenario like this

In one feature file:

Given I want to calll login scenario


In another feature file

.
.
.
Scenario: login
Given ...
When ...
Then ...




Then it is not possible. There is no way to call a scenarion from
another scenario like the attempt above.

>
> The reason for this is the scenarios so huge and its tedious job to maintain
> them all in one single feature file and most of the times we need to reuse
> the existing scenario part of other scenarios. I don't want to create a
> duplicate of same steps in all feature files.
>

Steps are global. Meaning that as long as they are in the same
classpath as the feature, all steps in all step files will be found
and the unique step that matches will be executed.

This means that you are able to divide your step definition classes in
logical chunks.

All steps can reach and use support classes. These support classes is
one way to push complexity from the step definitions and make the
steps small.

By your description, I get the feeling that you need to find common
abstractions and use them instead of trying to use an other scenario
from a scenario.

HTH
Thomas


>
> Please help me here.
>
>
> Thanks,
> Mahesh
>
>
>
> --
> Posting rules: http://cukes.info/posting-rules.html
> ---
> You received this message because you are subscribed to the Google Groups
> "Cukes" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to cukes+un...@googlegroups.com.
> For more options, visit https://groups.google.com/d/optout.



--
Thomas Sundberg
M. Sc. in Computer Science

Mobile: +46 70 767 33 15
Blog: http://thomassundberg.wordpress.com/
Twitter: @thomassundberg

Better software through faster feedback

Roberto Lo Giacco

unread,
Jan 9, 2016, 2:24:01 PM1/9/16
to Cukes
If a scenario is longer than 5/8 lines that's a very good indicator you are not using Cucumber properly and they describe the how rather than the what.

If you keep repeating the same steps over and over than you are describing the how, like:

Given the user is on the profile picture page
And the user has selected a picture from the file system
When the user clicks on button "Load"
Then the "please wait" message is displayed
And a spinner is shown
And the profile page is reloaded
And the new picture is displayed

That is the HOW, and it tells practically NOTHING about the WHAT, it just describes the user interface implementation. You should use Cucumber to describe what your application does. A correct scenario would sound like:

Given I want to change my profile picture
When I select a profile picture
Then the picture is uploaded
And the picture is displayed in my profile

Stop thinking about what the application does to achieve a result step by step and describe only the feature as you would do to a friend of yours, or to some non technical people.

This means your request for "calling scenarios from other scenarios" doesn't make sense in Cucumber, it is not a programming language of any sort and as such there is no `calling` facility whatsoever.... There is no callability because there is nothing to call. This is basically the same concept Thomas described already, possibly in simpler terms.

Ranjit Singh

unread,
Jun 21, 2017, 4:06:38 AM6/21/17
to Cukes
Calling a scenario from another is not possible. But you can do one thing is that  either you can create a background which will be executed before each scenarios that you have put up in that feature file or you can use gobal hooks to execute some code before or after some particular scenarios 

Thanks,
Ranjit Bhangu
Reply all
Reply to author
Forward
0 new messages