[Cucumber JVM] how to extract feature and scenario name at run time

6,227 views
Skip to first unread message

satish gowda

unread,
Jun 16, 2015, 2:49:10 AM6/16/15
to cu...@googlegroups.com
I am trying extract the feature and scenario at run time


import gherkin.formatter.model.Scenario;
import cucumber.api.java.Before;

@Before
public void before(Scenario s) {
System.out.println("currently executig scenario " + s.getName());
}

getting error "cucumber.runtime.CucumberException: When a hook declares an argument it must be of type cucumber.api.Scenario. "
could some one tell how to  extract the feature and scenario at run time

Paolo Ambrosio

unread,
Jun 16, 2015, 3:44:48 AM6/16/15
to cu...@googlegroups.com
On Tue, Jun 16, 2015 at 5:10 AM, satish gowda <satish...@gmail.com> wrote:
> I am trying extract the feature and scenario at run time
>
>
> import gherkin.formatter.model.Scenario;
> import cucumber.api.java.Before;
>
> @Before
> public void before(Scenario s) {
> System.out.println("currently executig scenario " + s.getName());
> }
>
> getting error "cucumber.runtime.CucumberException: When a hook declares an
> argument it must be of type cucumber.api.Scenario. "

You are importing gherkin.formatter.model.Scenario and not
cucumber.api.Scenario.

> could some one tell how to extract the feature and scenario at run time

Hooks haven't been designed with reporting in mind; for that you
should define your own formatter. From the hook's point of view the
feature is irrelevant.

What are you trying to do in the hook?


Paolo

satish gowda

unread,
Jun 16, 2015, 11:31:44 PM6/16/15
to cu...@googlegroups.com
even i tried with cucumber.api.Scenario. 
but in that i can not find getName() function 

is there any way  to fetch the Scenario and Feature name??




 

Paolo Ambrosio

unread,
Jun 17, 2015, 1:47:16 AM6/17/15
to cu...@googlegroups.com
You must use cucumber >1.1.6

> is there any way to fetch the Scenario

Yes.

> and Feature name??

No.


Might give you an alternative approach if you answer the question in
my previous mail.

Doug Harter

unread,
Aug 29, 2015, 8:37:27 AM8/29/15
to Cukes
Paolo,

I'm integrating Applitools Eyes  with my Cucumber tests.   I would like to get the Feature name in the Before Hook to set the BatchInfo object in Eyes object.  It would then group all comparisons by Feature.
Im using TestNG and thinking about just explicitly implementing AbstractTestNgRunner so I can use the @BeforeClass hook ....

Doug Harter Sr Software in Test @ Ancestry.com 

Rafaela Souza

unread,
Sep 30, 2015, 6:35:22 AM9/30/15
to Cukes
I am trying to do the same, the Scenario is working for me, but the feature name it is impossible to get. I couldn't find anything at all.

Paolo Ambrosio

unread,
Sep 30, 2015, 2:18:08 PM9/30/15
to cu...@googlegroups.com

On 30 Sep 2015 11:35, "Rafaela Souza" <rafaela.az...@gmail.com> wrote:
>
> I am trying to do the same, the Scenario is working for me, but the feature name it is impossible to get. I couldn't find anything at all.

You have replied to at least a thread that where it is mentioned that to get the feature name you need a custom formatter and not a hook.

In hooks that information is not available as it's an antipattern. If you need it good chances are that you are misusing hooks for something they were not designed for.

What is your use case?

> On Tuesday, June 16, 2015 at 7:49:10 AM UTC+1, satish gowda wrote:
>>
>> I am trying extract the feature and scenario at run time
>>
>>
>> import gherkin.formatter.model.Scenario;
>> import cucumber.api.java.Before;
>>
>> @Before
>> public void before(Scenario s) {
>> System.out.println("currently executig scenario " + s.getName());
>> }
>>
>> getting error "cucumber.runtime.CucumberException: When a hook declares an argument it must be of type cucumber.api.Scenario. "
>> could some one tell how to  extract the feature and scenario at run time
>

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

Reply all
Reply to author
Forward
0 new messages