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 cookieGiven user visiting the newsroom pageWhen <region> newsroom is selectedThen selection shall be stored in cookie <cookieValue>Feature File2 :Scenario Outline: 03 Filters on newsitem listing in newsroomGiven user visiting the newsroom pageWhen a <tagfilter> is selectedThen only news items marked with this <tagfilter> filter should be displayedWhen user clicks link "View Older News"Then more 25 news items are appended to news listSo 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 cu...@googlegroups.com. To unsubscribe from this group, send email to cukes+un...@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+un...@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.
@Before
public void setUp() throws Exception {
AppSetup.initialize();
myService = new MyService();
@Before
public void setUp() throws Exception {
AppSetup.initialize();
myService = new MyService();
anotherService = new AnotherService();
@Before
public void setUp() throws Exception {
AppSetup.initialize();
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;
}
@RunWith(Cucumber.class)
@CucumberOptions(features = "classpath:features/myTest.feature",
plugin = {"pretty", "html:target/cucumber-html-report", "json:target/cucumber-report.json"})
public class AppRunnerTest {
}
Anna,
On 12/14/15 3:03 AM, Anna wrote:
> 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.
> 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.
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.
>
> @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.
> 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
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.
Thanks. See my response below:
On Monday, December 14, 2015 at 5:16:37 PM UTC+5:30, George Dinwiddie wrote:Anna,
On 12/14/15 3:03 AM, Anna wrote:
> 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
https://cucumber.io/blog/2014/03/03/the-worlds-most-misunderstood-collaboration-tool
helpful.
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.
And this folks, is why relatively new folks feel discouraged from asking questions...
--
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+unsubscribe@googlegroups.com.
And this folks, is why relatively new folks feel discouraged from asking questions...
I deleted that post. Not sure why it shows? I get what you're saying and after reading my original post, I deleted...