--Brgrds,Christian
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.
On Sun, Oct 19, 2014 at 11:38 AM, Christian <christia...@gmail.com> wrote:Hi all,When trying to extend a class that uses cucumber hooks, Cucumber throws the following error message:cucumber.runtime.CucumberException: You're not allowed to extend classes that define Step Definitions or hooksWhat's the rationale behind stopping us from doing that?Cucumber creates a new instance of all classes defining stepdefs before each scenario.It then invokes stepdef methods on *one* of those instances whenever it needs to run a step.If you defined a stepdef method foo in class A and you have a class B extends A you'd get an a and b instance.The foo method would be available on both instances, and Cucumber would not be able to decide what instance to invoke the method on.
That's why we don't allow it.The solution is to use composition instead of inheritance. You can achieve composition with dependency injection - Cucumber supports several popular DI frameworks.
On Sunday, October 19, 2014 11:51:25 AM UTC+1, Aslak Hellesøy wrote:On Sun, Oct 19, 2014 at 11:38 AM, Christian <christia...@gmail.com> wrote:Hi all,When trying to extend a class that uses cucumber hooks, Cucumber throws the following error message:cucumber.runtime.CucumberException: You're not allowed to extend classes that define Step Definitions or hooksWhat's the rationale behind stopping us from doing that?Cucumber creates a new instance of all classes defining stepdefs before each scenario.It then invokes stepdef methods on *one* of those instances whenever it needs to run a step.If you defined a stepdef method foo in class A and you have a class B extends A you'd get an a and b instance.The foo method would be available on both instances, and Cucumber would not be able to decide what instance to invoke the method on.My A is abstract and only holds Before and After hooks, not step defs, anyway, so there is little chance of invoking foo there. Plus, if you have a C extends B extends A chain, couldn't you just invoke the foo method where it is highest up the chain, i.e. in C?
> Brgrds,
> Christian
>
>>
>> That's why we don't allow it.
>>
>> The solution is to use composition instead of inheritance. You can achieve
>> composition with dependency injection - Cucumber supports several popular DI
>> frameworks.
>
> I'm trying to plug Cucumber into a project that has grown over many years.
> It's hard enough to get management's OK for that. If I now try to introduce
> something anywhere near as complex as Spring, for example, I'll most likely
> not get support for it. Is there a really lightweight DI framework you'd
> recommend?
PicoContainer is a very simple DI framework that requires no configuration.
Consider buying "The Cucumber for Java Book" (in beta at the moment)
that has answers to the most common questions:
https://pragprog.com/book/srjcuc/the-cucumber-for-java-book
This is an excerpt from the chapter on Dependency Injection:
http://media.pragprog.com/titles/srjcuc/simplify.pdf
Paolo
On Sun, Oct 19, 2014 at 7:34 PM, Christian <christia...@gmail.com> wrote:
On Sunday, October 19, 2014 11:51:25 AM UTC+1, Aslak Hellesøy wrote:On Sun, Oct 19, 2014 at 11:38 AM, Christian <christia...@gmail.com> wrote:Hi all,When trying to extend a class that uses cucumber hooks, Cucumber throws the following error message:cucumber.runtime.CucumberException: You're not allowed to extend classes that define Step Definitions or hooksWhat's the rationale behind stopping us from doing that?Cucumber creates a new instance of all classes defining stepdefs before each scenario.It then invokes stepdef methods on *one* of those instances whenever it needs to run a step.If you defined a stepdef method foo in class A and you have a class B extends A you'd get an a and b instance.The foo method would be available on both instances, and Cucumber would not be able to decide what instance to invoke the method on.My A is abstract and only holds Before and After hooks, not step defs, anyway, so there is little chance of invoking foo there. Plus, if you have a C extends B extends A chain, couldn't you just invoke the foo method where it is highest up the chain, i.e. in C?What if your A has two direct descendants, B1 and B2. On what instance would you expect the hooks to be invoked?
Why do you think you need inheritance in the first place?
> Brgrds,
> Christian
>
>>
>> That's why we don't allow it.
>>
>> The solution is to use composition instead of inheritance. You can achieve
>> composition with dependency injection - Cucumber supports several popular DI
>> frameworks.
>
> I'm trying to plug Cucumber into a project that has grown over many years.
> It's hard enough to get management's OK for that. If I now try to introduce
> something anywhere near as complex as Spring, for example, I'll most likely
> not get support for it. Is there a really lightweight DI framework you'd
> recommend?
PicoContainer is a very simple DI framework that requires no configuration.
Consider buying "The Cucumber for Java Book" (in beta at the moment)
that has answers to the most common questions:
https://pragprog.com/book/srjcuc/the-cucumber-for-java-book
This is an excerpt from the chapter on Dependency Injection:
http://media.pragprog.com/titles/srjcuc/simplify.pdf
PaoloThanks, I'll have a look...Brgrds,Christian
--
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.
------------------------Andrew Premdas
Thanks for the reply Andrew!We'd considered that at the start but shied away because the generated reports are then split between 'common' features and 'specific' features ... which makes no sense to the business annalists and PM's for each project (and at the end of the day, they're a big 'customer' of these reports). People at that level shouldn't need to know that we've split tests up like that to make them easier to manage, it's irrelevant to them (our problem, not theirs), they just need the results.
We're also not in a position to influence the dev design on this.Also, steps like "Then my displayed address matches my account address" etc... are steps that we do want to behave differently between sites (in GB and DE we have different fields for address, which doesn't matter for this business case, but does matter behind the scenes when automating).
This isn't a problem for us as each test run only covers one site (it's not switching sights or anything, we just pass a parameter to decide which site when we kick it off).I've only mentioned 2 countries there, but there are potentially dozens as the company expands so keeping that 80% commonality in a single place is going to be increasingly important.All this said, I think our only option here is to split the features between 'common' and 'specific' and have an explanation at the start of the test reports to explain what that means.
To unsubscribe from this group and stop receiving emails from it, send an email to cukes+unsubscribe@googlegroups.com.
I'm facing this same problem. In all my Step Definitions I need to create the @After method and inside it take a screenshot if the scenario fails. The problem is that in all my current scenarios (230 scenarios) I need to add this, and in case I need any future changes I need to rewrite them all. What would be the best solution for this case since no inheritance is possible?
To unsubscribe from this group and stop receiving emails from it, send an email to cukes+un...@googlegroups.com.
Due to the structure of my project I have a run cucumber for each step definitions, both in a folder, if I put a global hook, the cucumber is not able to see.