Discussion:
[Cucumber] Common scenarios in multiple feature files and multiple steps definition file
(too old to reply)
shivi malviya
2013-11-22 12:04:47 UTC
Permalink
Raw Message
Hi,
We have developed a test framework using Cucumber. We are facing problem
when we have common scenarios in multiple feature files and each feature
file has a separate step definition files.
Please find below the detailed scenario :
Feature File1 :
Scenario Outline: 02 Chosen newsroom stored in cookie
Given user visiting the newsroom page
When <region> newsroom is selected
Then selection shall be stored in cookie <cookieValue>


Feature File2 :
Scenario Outline: 03 Filters on newsitem listing in newsroom
Given user visiting the newsroom page
When a <tagfilter> is selected
Then only news items marked with this <tagfilter> filter should be
displayed
When user clicks link "View Older News"
Then more 25 news items are appended to news list

So the lines highlighted in Yellow are common lines used in both feature
files, now we are creating one step definition file for each feature file.
Now when i am declaring step definition for highlighted step in both step
definition file, it is giving me duplicate step definition error, and when
I am keeping it only in one step definition file, it is giving me Null
Pointer exception.
Another thing which I tried is to extend step definition file , but then I
got error it is not possible to extend the step definition files.

How should i reuse my step definitions in other step definition file when
we some some common scenario lines in multiple feature files ?

Please suggest.

Thanks,
Shivi
--
-- Rules --

1) Please prefix the subject with [Ruby], [JVM] or [JS].
2) Please use interleaved answers http://en.wikipedia.org/wiki/Posting_style#Interleaved_style
3) If you have a question, don't reply to an existing message. Start a new topic instead.

You received this message because you are subscribed to the Google Groups Cukes group. To post to this group, send email to cukes-/JYPxA39Uh5TLH3MbocFF+G/***@public.gmane.org To unsubscribe from this group, send email to cukes+***@googlegroups.com. For more options, visit this group at https://groups.google.com/d/forum/cukes?hl=en
---
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+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/***@public.gmane.org
For more options, visit https://groups.google.com/groups/opt_out.
aslak hellesoy
2013-11-22 12:06:47 UTC
Permalink
Raw Message
Post by shivi malviya
Hi,
We have developed a test framework using Cucumber. We are facing problem
when we have common scenarios in multiple feature files and each feature
file has a separate step definition files.
Scenario Outline: 02 Chosen newsroom stored in cookie
Given user visiting the newsroom page
When <region> newsroom is selected
Then selection shall be stored in cookie <cookieValue>
Scenario Outline: 03 Filters on newsitem listing in newsroom
Given user visiting the newsroom page
When a <tagfilter> is selected
Then only news items marked with this <tagfilter> filter should be
displayed
When user clicks link "View Older News"
Then more 25 news items are appended to news list
So the lines highlighted in Yellow are common lines used in both feature
files, now we are creating one step definition file for each feature file.
Don't do that. Step definitions are global.
Post by shivi malviya
Now when i am declaring step definition for highlighted step in both step
definition file, it is giving me duplicate step definition error, and when
I am keeping it only in one step definition file, it is giving me Null
Pointer exception.
Another thing which I tried is to extend step definition file , but then I
got error it is not possible to extend the step definition files.
How should i reuse my step definitions in other step definition file when
we some some common scenario lines in multiple feature files ?
Please suggest.
Thanks,
Shivi
--
-- Rules --
1) Please prefix the subject with [Ruby], [JVM] or [JS].
2) Please use interleaved answers
http://en.wikipedia.org/wiki/Posting_style#Interleaved_style
3) If you have a question, don't reply to an existing message. Start a new topic instead.
You received this message because you are subscribed to the Google Groups
To unsubscribe from this group, send email to
https://groups.google.com/d/forum/cukes?hl=en
---
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
For more options, visit https://groups.google.com/groups/opt_out.
--
-- Rules --

1) Please prefix the subject with [Ruby], [JVM] or [JS].
2) Please use interleaved answers http://en.wikipedia.org/wiki/Posting_style#Interleaved_style
3) If you have a question, don't reply to an existing message. Start a new topic instead.

You received this message because you are subscribed to the Google Groups Cukes group. To post to this group, send email to cukes-/JYPxA39Uh5TLH3MbocFF+G/***@public.gmane.org To unsubscribe from this group, send email to cukes+***@googlegroups.com. For more options, visit this group at https://groups.google.com/d/forum/cukes?hl=en
---
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+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/***@public.gmane.org
For more options, visit https://groups.google.com/groups/opt_out.
Anna
2015-12-09 07:24:03 UTC
Permalink
Raw Message
I have been looking around to understand if Cucumber with Java has any
support / way to REUSE common step definitions across multiple feature
files / scenarios. The only way I can handle right now is changing the
wording of step definition file which is NOT good and no solution.

But its strange that I haven't got any link/reference on this after
googling a lot. This should be the basic requirement when we design
cucumber scenarios as there ought to be common sequence of steps that one
would call across scenarios/ across feature files.

For ex,
- A user logs in (every scenario would need that and we do not want a new
user to created with each scenario so can't put it in Background)
- Creating some prerequisite objects for a scenario to work.

Let me know if anybody has suggestions on this.

Somehow I feel cucumber documentation needs to be more structured and
improved as I do not see good documentation on cucumber site. These are
some basic design/guidelines/ that each cucumber user would like to know !
Post by aslak hellesoy
Post by shivi malviya
Hi,
We have developed a test framework using Cucumber. We are facing problem
when we have common scenarios in multiple feature files and each feature
file has a separate step definition files.
Scenario Outline: 02 Chosen newsroom stored in cookie
Given user visiting the newsroom page
When <region> newsroom is selected
Then selection shall be stored in cookie <cookieValue>
Scenario Outline: 03 Filters on newsitem listing in newsroom
Given user visiting the newsroom page
When a <tagfilter> is selected
Then only news items marked with this <tagfilter> filter should be
displayed
When user clicks link "View Older News"
Then more 25 news items are appended to news list
So the lines highlighted in Yellow are common lines used in both feature
files, now we are creating one step definition file for each feature file.
Don't do that. Step definitions are global.
Post by shivi malviya
Now when i am declaring step definition for highlighted step in both step
definition file, it is giving me duplicate step definition error, and when
I am keeping it only in one step definition file, it is giving me Null
Pointer exception.
Another thing which I tried is to extend step definition file , but then
I got error it is not possible to extend the step definition files.
How should i reuse my step definitions in other step definition file when
we some some common scenario lines in multiple feature files ?
Please suggest.
Thanks,
Shivi
--
-- Rules --
1) Please prefix the subject with [Ruby], [JVM] or [JS].
2) Please use interleaved answers
http://en.wikipedia.org/wiki/Posting_style#Interleaved_style
3) If you have a question, don't reply to an existing message. Start a new topic instead.
You received this message because you are subscribed to the Google Groups
<javascript:>. To unsubscribe from this group, send email to
group at https://groups.google.com/d/forum/cukes?hl=en
---
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
For more options, visit https://groups.google.com/groups/opt_out.
--
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+***@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
Anna
2015-12-13 18:33:49 UTC
Permalink
Raw Message
Did you get answer to your question, I have been looking around on this,
but unfortunately no answers on this yet even after googling a lot, weird,
as this is the most basic thing one would like to have using any framework!

Cucumber users, anybody any suggestion on this?

Also wherein we have multiple feature files, how do we work on the
initialization/setup code ?

There is some data initialization that one want to do before running a
feature file and that can goe into @before method. But the issue is that
there is no order in which feature files are picked, so thats very very
frustrating, all initialization code across all feature files runs and that
too without any specific order...which is not desired.
In other words, I am looking at what options or best strategy to do
initialization wherein I have multiple feature files/multiple test classes
(java classes) running scenarios of the corresponding feature. The issue is
I can't extend a class that contains step defintions so I cannot reuse
initilaization code across multiple test classes.

Any help,appreciate in advance!
Post by shivi malviya
Hi,
We have developed a test framework using Cucumber. We are facing problem
when we have common scenarios in multiple feature files and each feature
file has a separate step definition files.
Scenario Outline: 02 Chosen newsroom stored in cookie
Given user visiting the newsroom page
When <region> newsroom is selected
Then selection shall be stored in cookie <cookieValue>
Scenario Outline: 03 Filters on newsitem listing in newsroom
Given user visiting the newsroom page
When a <tagfilter> is selected
Then only news items marked with this <tagfilter> filter should be
displayed
When user clicks link "View Older News"
Then more 25 news items are appended to news list
So the lines highlighted in Yellow are common lines used in both feature
files, now we are creating one step definition file for each feature file.
Now when i am declaring step definition for highlighted step in both step
definition file, it is giving me duplicate step definition error, and when
I am keeping it only in one step definition file, it is giving me Null
Pointer exception.
Another thing which I tried is to extend step definition file , but then I
got error it is not possible to extend the step definition files.
How should i reuse my step definitions in other step definition file when
we some some common scenario lines in multiple feature files ?
Please suggest.
Thanks,
Shivi
--
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+***@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
George Dinwiddie
2015-12-13 19:39:55 UTC
Permalink
Raw Message
Anna,

Any feature file can call any step definition.

It's not advisable to have one feature file dependent on another one (or
even one scenario dependent on another one). I get the feeling you're
trying to use cucumber as a test automation tool, and not as a
collaboration and functional specification too.

Perhaps if you give us some examples of what you're trying to
accomplish, we can help you start in a more productive direction.

- George
Post by Anna
Did you get answer to your question, I have been looking around on this,
but unfortunately no answers on this yet even after googling a lot,
weird, as this is the most basic thing one would like to have using any
framework!
Cucumber users, anybody any suggestion on this?
Also wherein we have multiple feature files, how do we work on the
initialization/setup code ?
There is some data initialization that one want to do before running a
that there is no order in which feature files are picked, so thats very
very frustrating, all initialization code across all feature files runs
and that too without any specific order...which is not desired.
In other words, I am looking at what options or best strategy to do
initialization wherein I have multiple feature files/multiple test
classes (java classes) running scenarios of the corresponding feature.
The issue is I can't extend a class that contains step defintions so I
cannot reuse initilaization code across multiple test classes.
Any help,appreciate in advance!
Hi,
We have developed a test framework using Cucumber. We are facing
problem when we have common scenarios in multiple feature files and
each feature file has a separate step definition files.
Scenario Outline: 02 Chosen newsroom stored in cookie
Given user visiting the newsroom page
When <region> newsroom is selected
Then selection shall be stored in cookie <cookieValue>
Scenario Outline: 03 Filters on newsitem listing in newsroom
Given user visiting the newsroom page
When a <tagfilter> is selected
Then only news items marked with this <tagfilter> filter should
be displayed
When user clicks link "View Older News"
Then more 25 news items are appended to news list
So the lines highlighted in Yellow are common lines used in both
feature files, now we are creating one step definition file for each
feature file.
Now when i am declaring step definition for highlighted step in both
step definition file, it is giving me duplicate step definition
error, and when I am keeping it only in one step definition file, it
is giving me Null Pointer exception.
Another thing which I tried is to extend step definition file , but
then I got error it is not possible to extend the step definition files.
How should i reuse my step definitions in other step definition file
when we some some common scenario lines in multiple feature files ?
Please suggest.
Thanks,
Shivi
--
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
For more options, visit https://groups.google.com/d/optout.
--
----------------------------------------------------------------------
* George Dinwiddie * http://blog.gdinwiddie.com
Software Development http://www.idiacomputing.com
Consultant and Coach http://www.agilemaryland.org
----------------------------------------------------------------------
--
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+***@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
Anna
2015-12-14 08:03:05 UTC
Permalink
Raw Message
Hey George.

Thanks for response.
You hit it right.. we are using Cucumber to write automation tests. The
project has multiple feature files and as part of any automation process,
we need some initialization and tear down code which needs to be run once,
before any feature/scenarios run.

Initially I put the initialization code in each of my test class (which has
its feature file) under @Before method . However I realized that when you
run the feature file through Runner it executes all feature file present in
the features folder (despite me providing a specific feature file in the
annotation like below which is another issue/bottleneck).
and so initialization code gets run multiple times per feature/test class.

I am thinking to have a separate class SetupUtil that has static initialize
method with a static flag isInitalizedOnce . I am using encapsulation now
(as i can't use inheritance with step definitions) and calling
SetupUtil.initialize with each of the test class @ before method.

AppTest1 - This has a corresponding feature file apptest_1.feature
=============================

@Before

public void setUp() throws Exception {

AppSetup.initialize();

myService = new MyService();
}

AppTest2 This has a corresponding feature file apptest_2.feature
=============================

@Before

public void setUp() throws Exception {

AppSetup.initialize();

myService = new MyService();

anotherService = new AnotherService();

}


AppTest3 - This has a corresponding feature file apptest_3.feature
=============================

@Before

public void setUp() throws Exception {

AppSetup.initialize();

myService = new MyService();
}
============================

AppSetup {

static User;

static boolean isInitializedOnceForAllFeatures = false;

public static void initialize() throws Exception {

if(isInitializedOnceForAllFeatures) return;

//authentication, user creation and other configuration initialization code

intializeConfiguration():

createUsers();

isInitializedOnceForAllFeatures = true;

}

Let me know if this approach is correct or if there is any better design
approach to handle this. Quick response is appreciated as I have to wrap
this up quickly !! Also let me know if there is any good reference of
things to keep in mind while designing automation tests using cucumber.

II ) Another Issue I am getting is despite I refer a specific feature file
in runner, it still invokes all feature file related step definitiaons and
runs everthing. This is whats not expected. If I run a feature file , then
it should ONLY run scenarios that are pertaining to that feature and NO
other feature files should be picked. I am running via Eclipse. Right click
on Runner class and run as Junit test.

@RunWith(Cucumber.class)

@CucumberOptions(features = "classpath:features/myTest.feature",

plugin = {"pretty", "html:target/cucumber-html-report",
"json:target/cucumber-report.json"})

public class AppRunnerTest {

}

III) Obviously, across multiple feature files there ought to be same step
definitions being used. How do we handle such cases? As there is no
inheritance possible I cant have a common base class defining those step
defintions. As order is not guaranteed its also not clear where to keep
definitions ?

IV) Sometimes a step definition that we use in a scenario can be put in as
@Given but in some other scenario that step definition falls under @When or
@And. How do we handle such cases. There seems to be a high need for me
while writing automated tests. Same step definition method cannot have
multiple tags also like @Given, @And

I appreciate if I can get quick answers on these so that I can identify if
cucumber is the right choice for automation tests. I believe so , but
looking forward for some quick response.

thanks
Anna
Post by George Dinwiddie
Anna,
Any feature file can call any step definition.
It's not advisable to have one feature file dependent on another one (or
even one scenario dependent on another one). I get the feeling you're
trying to use cucumber as a test automation tool, and not as a
collaboration and functional specification too.
Perhaps if you give us some examples of what you're trying to
accomplish, we can help you start in a more productive direction.
- George
Post by Anna
Did you get answer to your question, I have been looking around on this,
but unfortunately no answers on this yet even after googling a lot,
weird, as this is the most basic thing one would like to have using any
framework!
Cucumber users, anybody any suggestion on this?
Also wherein we have multiple feature files, how do we work on the
initialization/setup code ?
There is some data initialization that one want to do before running a
that there is no order in which feature files are picked, so thats very
very frustrating, all initialization code across all feature files runs
and that too without any specific order...which is not desired.
In other words, I am looking at what options or best strategy to do
initialization wherein I have multiple feature files/multiple test
classes (java classes) running scenarios of the corresponding feature.
The issue is I can't extend a class that contains step defintions so I
cannot reuse initilaization code across multiple test classes.
Any help,appreciate in advance!
On Friday, November 22, 2013 at 5:34:47 PM UTC+5:30, shivi malviya
Hi,
We have developed a test framework using Cucumber. We are facing
problem when we have common scenarios in multiple feature files and
each feature file has a separate step definition files.
Scenario Outline: 02 Chosen newsroom stored in cookie
Given user visiting the newsroom page
When <region> newsroom is selected
Then selection shall be stored in cookie <cookieValue>
Scenario Outline: 03 Filters on newsitem listing in newsroom
Given user visiting the newsroom page
When a <tagfilter> is selected
Then only news items marked with this <tagfilter> filter should
be displayed
When user clicks link "View Older News"
Then more 25 news items are appended to news list
So the lines highlighted in Yellow are common lines used in both
feature files, now we are creating one step definition file for each
feature file.
Now when i am declaring step definition for highlighted step in both
step definition file, it is giving me duplicate step definition
error, and when I am keeping it only in one step definition file, it
is giving me Null Pointer exception.
Another thing which I tried is to extend step definition file , but
then I got error it is not possible to extend the step definition
files.
Post by Anna
How should i reuse my step definitions in other step definition file
when we some some common scenario lines in multiple feature files ?
Please suggest.
Thanks,
Shivi
--
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
For more options, visit https://groups.google.com/d/optout.
--
----------------------------------------------------------------------
* George Dinwiddie * http://blog.gdinwiddie.com
Software Development http://www.idiacomputing.com
Consultant and Coach http://www.agilemaryland.org
----------------------------------------------------------------------
--
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+***@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
George Dinwiddie
2015-12-14 11:46:25 UTC
Permalink
Raw Message
Anna,
Post by Anna
Hey George.
Thanks for response.
You hit it right.. we are using Cucumber to write automation tests.
Who reads your cucumber scenarios?

You might find
https://cucumber.io/blog/2014/03/03/the-worlds-most-misunderstood-collaboration-tool
helpful.
Post by Anna
The
project has multiple feature files and as part of any automation
process, we need some initialization and tear down code which needs to
be run once, before any feature/scenarios run.
Initially I put the initialization code in each of my test class (which
when you run the feature file through Runner it executes all feature
file present in the features folder (despite me providing a specific
feature file in the annotation like below which is another
issue/bottleneck).
and so initialization code gets run multiple times per feature/test class.
Cucumber will run only the feature file you specify, but it will load
all the step definitions. Step definitions do not match feature files.
All of your @Before methods will get run before each scenario.

See http://zsoltfabok.com/blog/2012/09/cucumber-jvm-hooks/ for more info
on how hooks work.
Post by Anna
I am thinking to have a separate class SetupUtil that has static
initialize method with a static flag isInitalizedOnce . I am using
encapsulation now (as i can't use inheritance with step definitions) and
You don't need or want inheritance of step definitions, as that would
define them all multiple times.
Post by Anna
AppTest1 - This has a corresponding feature file apptest_1.feature
Organize your step definitions around the cohesiveness of the steps they
define, not what features use them.
Post by Anna
=============================
@Before
public void setUp() throws Exception {
AppSetup.initialize();
myService = new MyService();
}
AppTest2 This has a corresponding feature file apptest_2.feature
=============================
@Before
public void setUp() throws Exception {
AppSetup.initialize();
myService = new MyService();
anotherService = new AnotherService();
}
AppTest3 - This has a corresponding feature file apptest_3.feature
=============================
@Before
public void setUp() throws Exception {
AppSetup.initialize();
myService = new MyService();
}
============================
AppSetup {
static User;
staticbooleanisInitializedOnceForAllFeatures= false;
public static void initialize() throws Exception {
if(isInitializedOnceForAllFeatures) return;
//authentication, user creation and other configuration initialization code
createUsers();
isInitializedOnceForAllFeatures= true;
}
Let me know if this approach is correct or if there is any better design
approach to handle this. Quick response is appreciated as I have to wrap
this up quickly !! Also let me know if there is any good reference of
things to keep in mind while designing automation tests using cucumber.
II ) Another Issue I am getting is despite I refer a specific feature
file in runner, it still invokes all feature file related step
definitiaons and runs everthing. This is whats not expected. If I run a
feature file , then it should ONLY run scenarios that are pertaining to
that feature and NO other feature files should be picked. I am running
via Eclipse. Right click on Runner class and run as Junit test.
Cucumber should run only the scenarios in the feature file you specify,
but will load all the step definition files.
Post by Anna
@RunWith(Cucumber.class)
@CucumberOptions(features = "classpath:features/myTest.feature",
plugin = {"pretty", "html:target/cucumber-html-report",
"json:target/cucumber-report.json"})
public class AppRunnerTest {
}
III) Obviously, across multiple feature files there ought to be same
step definitions being used. How do we handle such cases? As there is no
inheritance possible I cant have a common base class defining those step
defintions. As order is not guaranteed its also not clear where to keep
definitions ?
Step definitions are global. The meaning of "When I foo the bar" should
not change from scenario to scenario.
Post by Anna
IV) Sometimes a step definition that we use in a scenario can be put in
@When or @And. How do we handle such cases. There seems to be a high
need for me while writing automated tests. Same step definition method
Cucumber doesn't really care whether you use @Given or @When. That's for
human communication. The step definition will still run, even if it's
introduced differently in the scenario.
Post by Anna
I appreciate if I can get quick answers on these so that I can identify
if cucumber is the right choice for automation tests. I believe so , but
looking forward for some quick response.
thanks
Anna
Anna,
Any feature file can call any step definition.
It's not advisable to have one feature file dependent on another one (or
even one scenario dependent on another one). I get the feeling you're
trying to use cucumber as a test automation tool, and not as a
collaboration and functional specification too.
Perhaps if you give us some examples of what you're trying to
accomplish, we can help you start in a more productive direction.
- George
Post by Anna
Did you get answer to your question, I have been looking around
on this,
Post by Anna
but unfortunately no answers on this yet even after googling a lot,
weird, as this is the most basic thing one would like to have
using any
Post by Anna
framework!
Cucumber users, anybody any suggestion on this?
Also wherein we have multiple feature files, how do we work on the
initialization/setup code ?
There is some data initialization that one want to do before
running a
Post by Anna
that there is no order in which feature files are picked, so
thats very
Post by Anna
very frustrating, all initialization code across all feature
files runs
Post by Anna
and that too without any specific order...which is not desired.
In other words, I am looking at what options or best strategy to do
initialization wherein I have multiple feature files/multiple test
classes (java classes) running scenarios of the corresponding
feature.
Post by Anna
The issue is I can't extend a class that contains step defintions
so I
Post by Anna
cannot reuse initilaization code across multiple test classes.
Any help,appreciate in advance!
On Friday, November 22, 2013 at 5:34:47 PM UTC+5:30, shivi
Hi,
We have developed a test framework using Cucumber. We are facing
problem when we have common scenarios in multiple feature
files and
Post by Anna
each feature file has a separate step definition files.
Scenario Outline: 02 Chosen newsroom stored in cookie
Given user visiting the newsroom page
When <region> newsroom is selected
Then selection shall be stored in cookie <cookieValue>
Scenario Outline: 03 Filters on newsitem listing in newsroom
Given user visiting the newsroom page
When a <tagfilter> is selected
Then only news items marked with this <tagfilter> filter
should
Post by Anna
be displayed
When user clicks link "View Older News"
Then more 25 news items are appended to news list
So the lines highlighted in Yellow are common lines used in both
feature files, now we are creating one step definition file
for each
Post by Anna
feature file.
Now when i am declaring step definition for highlighted step
in both
Post by Anna
step definition file, it is giving me duplicate step definition
error, and when I am keeping it only in one step definition
file, it
Post by Anna
is giving me Null Pointer exception.
Another thing which I tried is to extend step definition file
, but
Post by Anna
then I got error it is not possible to extend the step
definition files.
Post by Anna
How should i reuse my step definitions in other step
definition file
Post by Anna
when we some some common scenario lines in multiple feature
files ?
Post by Anna
Please suggest.
Thanks,
Shivi
--
- George
--
----------------------------------------------------------------------
* George Dinwiddie * http://blog.gdinwiddie.com
Software Development http://www.idiacomputing.com
Consultant and Coach http://www.agilemaryland.org
----------------------------------------------------------------------
--
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+***@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
Anna
2015-12-14 12:10:46 UTC
Permalink
Raw Message
Post by George Dinwiddie
Anna,
Post by Anna
Hey George.
Thanks for response.
You hit it right.. we are using Cucumber to write automation tests.
Who reads your cucumber scenarios?
Anna - Well the scenarios are provided/read/reviewed by PM/Dev so idea
is that requirements can be easily provided in human readable format.

You might find
Post by George Dinwiddie
https://cucumber.io/blog/2014/03/03/the-worlds-most-misunderstood-collaboration-tool
helpful.
Post by Anna
The
project has multiple feature files and as part of any automation
process, we need some initialization and tear down code which needs to
be run once, before any feature/scenarios run.
Initially I put the initialization code in each of my test class (which
when you run the feature file through Runner it executes all feature
file present in the features folder (despite me providing a specific
feature file in the annotation like below which is another
issue/bottleneck).
and so initialization code gets run multiple times per feature/test
class.
Cucumber will run only the feature file you specify, but it will load
all the step definitions. Step definitions do not match feature files.
See http://zsoltfabok.com/blog/2012/09/cucumber-jvm-hooks/ for more info
on how hooks work.
Anna- Thanks George. I did look
at http://zsoltfabok.com/blog/2012/09/cucumber-jvm-hooks/ this , probably I
am actually following kind of similar approach by putting common setup code
in a Setup class with static fields. Each test class then encapsulates the
Setup class and calls the initialize method from @Before annotation.
However, I was thinking if we could have some tags at feature level, this
could have saved lot of effort and would have been cleaner.
Post by George Dinwiddie
Post by Anna
I am thinking to have a separate class SetupUtil that has static
initialize method with a static flag isInitalizedOnce . I am using
encapsulation now (as i can't use inheritance with step definitions) and
method.
You don't need or want inheritance of step definitions, as that would
define them all multiple times.
Post by Anna
AppTest1 - This has a corresponding feature file apptest_1.feature
Organize your step definitions around the cohesiveness of the steps they
define, not what features use them.
Post by Anna
=============================
@Before
public void setUp() throws Exception {
AppSetup.initialize();
myService = new MyService();
}
AppTest2 This has a corresponding feature file apptest_2.feature
=============================
@Before
public void setUp() throws Exception {
AppSetup.initialize();
myService = new MyService();
anotherService = new AnotherService();
}
AppTest3 - This has a corresponding feature file apptest_3.feature
=============================
@Before
public void setUp() throws Exception {
AppSetup.initialize();
myService = new MyService();
}
============================
AppSetup {
static User;
staticbooleanisInitializedOnceForAllFeatures= false;
public static void initialize() throws Exception {
if(isInitializedOnceForAllFeatures) return;
//authentication, user creation and other configuration initialization
code
Post by Anna
createUsers();
isInitializedOnceForAllFeatures= true;
}
Let me know if this approach is correct or if there is any better design
approach to handle this. Quick response is appreciated as I have to wrap
this up quickly !! Also let me know if there is any good reference of
things to keep in mind while designing automation tests using cucumber.
II ) Another Issue I am getting is despite I refer a specific feature
file in runner, it still invokes all feature file related step
definitiaons and runs everthing. This is whats not expected. If I run a
feature file , then it should ONLY run scenarios that are pertaining to
that feature and NO other feature files should be picked. I am running
via Eclipse. Right click on Runner class and run as Junit test.
Cucumber should run only the scenarios in the feature file you specify,
but will load all the step definition files.
Anna - I think concern is ONLY wherein you do not want to run common data
seed/setup code with each test class. Loading step definitions is fine.
What I have done is I have put in the common step definitions in Setup
class (for ex, user logs in) and because the Setup class is encapsulated
in each of the test class, i can easily refer it in test class.
Post by George Dinwiddie
Post by Anna
@RunWith(Cucumber.class)
@CucumberOptions(features = "classpath:features/myTest.feature",
plugin = {"pretty", "html:target/cucumber-html-report",
"json:target/cucumber-report.json"})
public class AppRunnerTest {
}
III) Obviously, across multiple feature files there ought to be same
step definitions being used. How do we handle such cases? As there is no
inheritance possible I cant have a common base class defining those step
defintions. As order is not guaranteed its also not clear where to keep
definitions ?
Step definitions are global. The meaning of "When I foo the bar" should
not change from scenario to scenario.
Post by Anna
IV) Sometimes a step definition that we use in a scenario can be put in
@When or @And. How do we handle such cases. There seems to be a high
need for me while writing automated tests. Same step definition method
human communication. The step definition will still run, even if it's
introduced differently in the scenario.
Anna - That sounds good. So this means I can have same step definition
with different tags ? I did try this out but it gave me issues. I will
check that again and will let u know in case it doesnt work for me
Post by George Dinwiddie
Post by Anna
I appreciate if I can get quick answers on these so that I can identify
if cucumber is the right choice for automation tests. I believe so , but
looking forward for some quick response.
thanks
Anna
On Monday, December 14, 2015 at 1:10:01 AM UTC+5:30, George Dinwiddie
Anna,
Any feature file can call any step definition.
It's not advisable to have one feature file dependent on another one (or
even one scenario dependent on another one). I get the feeling
you're
Post by Anna
trying to use cucumber as a test automation tool, and not as a
collaboration and functional specification too.
Perhaps if you give us some examples of what you're trying to
accomplish, we can help you start in a more productive direction.
- George
Post by Anna
Did you get answer to your question, I have been looking around
on this,
Post by Anna
but unfortunately no answers on this yet even after googling a
lot,
Post by Anna
Post by Anna
weird, as this is the most basic thing one would like to have
using any
Post by Anna
framework!
Cucumber users, anybody any suggestion on this?
Also wherein we have multiple feature files, how do we work on
the
Post by Anna
Post by Anna
initialization/setup code ?
There is some data initialization that one want to do before
running a
is
Post by Anna
Post by Anna
that there is no order in which feature files are picked, so
thats very
Post by Anna
very frustrating, all initialization code across all feature
files runs
Post by Anna
and that too without any specific order...which is not desired.
In other words, I am looking at what options or best strategy to
do
Post by Anna
Post by Anna
initialization wherein I have multiple feature files/multiple
test
Post by Anna
Post by Anna
classes (java classes) running scenarios of the corresponding
feature.
Post by Anna
The issue is I can't extend a class that contains step defintions
so I
Post by Anna
cannot reuse initilaization code across multiple test classes.
Any help,appreciate in advance!
On Friday, November 22, 2013 at 5:34:47 PM UTC+5:30, shivi
Hi,
We have developed a test framework using Cucumber. We are
facing
Post by Anna
Post by Anna
problem when we have common scenarios in multiple feature
files and
Post by Anna
each feature file has a separate step definition files.
Scenario Outline: 02 Chosen newsroom stored in cookie
Given user visiting the newsroom page
When <region> newsroom is selected
Then selection shall be stored in cookie <cookieValue>
Scenario Outline: 03 Filters on newsitem listing in newsroom
Given user visiting the newsroom page
When a <tagfilter> is selected
Then only news items marked with this <tagfilter> filter
should
Post by Anna
be displayed
When user clicks link "View Older News"
Then more 25 news items are appended to news list
So the lines highlighted in Yellow are common lines used in
both
Post by Anna
Post by Anna
feature files, now we are creating one step definition file
for each
Post by Anna
feature file.
Now when i am declaring step definition for highlighted step
in both
Post by Anna
step definition file, it is giving me duplicate step
definition
Post by Anna
Post by Anna
error, and when I am keeping it only in one step definition
file, it
Post by Anna
is giving me Null Pointer exception.
Another thing which I tried is to extend step definition file
, but
Post by Anna
then I got error it is not possible to extend the step
definition files.
Post by Anna
How should i reuse my step definitions in other step
definition file
Post by Anna
when we some some common scenario lines in multiple feature
files ?
Post by Anna
Please suggest.
Thanks,
Shivi
--
- George
--
----------------------------------------------------------------------
* George Dinwiddie * http://blog.gdinwiddie.com
Software Development http://www.idiacomputing.com
Consultant and Coach http://www.agilemaryland.org
----------------------------------------------------------------------
--
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+***@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
Roberto Lo Giacco
2015-12-15 13:25:50 UTC
Permalink
Raw Message
Post by Anna
Post by George Dinwiddie
Anna,
Post by Anna
Hey George.
Thanks for response.
You hit it right.. we are using Cucumber to write automation tests.
Who reads your cucumber scenarios?
Anna - Well the scenarios are provided/read/reviewed by PM/Dev so idea
is that requirements can be easily provided in human readable format.
You might find
Post by George Dinwiddie
https://cucumber.io/blog/2014/03/03/the-worlds-most-misunderstood-collaboration-tool
helpful.
I believe you should really spend a few minutes reading this blog post a
couple of times: it will be illuminating to highlight where and what you
are misusing. That's a lot more important than the hooks link, trust us.
Cucumber is not a test automation tool and using it as such is a waste of
time for your developers. It took me quite a while to understand the
difference, but once I did it was illuminating and I started to really get
the benefit of cucumber and gherkin.
--
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+***@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
Priyam Ghosh
2017-11-01 12:11:10 UTC
Permalink
Raw Message
Hi Shivi - I know it is quite a long you have posted it, but I would like
to know if you resolved the problem stated above? I'm facing the same issue
here.
--
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+***@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
Chuck van der Linden
2017-11-02 16:57:52 UTC
Permalink
Raw Message
Post by Priyam Ghosh
Hi Shivi - I know it is quite a long you have posted it, but I would like
to know if you resolved the problem stated above? I'm facing the same issue
here.
1) please don't play necromancer and raise two year old threads from the
dead.

2) the same advice given to Anna in the thread above would be the first
thing I would recommend to you.

3) the 'problem' if there is one is a misunderstanding of how to use the
tool properly, not an issue with the tool, it is resolved via educating
yourself, not with some magic code trick.
--
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+***@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
Loading...