cucumber-jvm programmatically access current execution context (feature, scenario and step names)

4,725 views
Skip to first unread message

The Trav

unread,
Feb 16, 2012, 12:45:17 AM2/16/12
to Cukes
So, I've got a scenario where, on failure of an assertion, I want to
save a screenshot.

I want this image to reside in something like target/feature/scenario/
step.png so that it's easy to look up

I would also prefer not to have to have the feature, scenario and step
name hard coded into the step files


Is there any way for me to ask cucumber what the currently executing
feature, scenario &/or step is?

aslak hellesoy

unread,
Feb 16, 2012, 3:11:30 AM2/16/12
to cu...@googlegroups.com
On Thu, Feb 16, 2012 at 5:45 AM, The Trav <the....@gmail.com> wrote:
> So, I've got a scenario where, on failure of an assertion, I want to
> save a screenshot.
>

Where would this screenshot be displayed? In a custom report? Something else?

> I want this image to reside in something like target/feature/scenario/
> step.png so that it's easy to look up
>
> I would also prefer not to have to have the feature, scenario and step
> name hard coded into the step files
>
>
> Is there any way for me to ask cucumber what the currently executing
> feature, scenario &/or step is?
>

Not yet. You can add a hook:

@cucumber.annotation.After
public void howDidItGo(ScenarioResult result) {
// currently only has getStatus() and isFailed()
}

We'll add more methods to this object to address needs like this. In
your case I'm considering adding:

void embed(byte[] data, String mimeType)

That would allow you to embed an image. It would end up in the
built-in HTML report. Would this solve your problem?

Aslak

> --
> 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 http://groups.google.com/group/cukes?hl=en.
>

The Trav

unread,
Feb 16, 2012, 5:28:32 PM2/16/12
to Cukes
> Where would this screenshot be displayed? In a custom report? Something else?
A custom report would probably be a superior option, however I'd
settle for just putting it in a filestore somewhere that the test
result consumers can go look at manually.

> Not yet. You can add a hook:
>     @cucumber.annotation.After
Before and After hooks are called between each scenario? I thought
they'd be per feature file or per run of feature files... Also I'm
using the JRuby step definitions, so would I need to find the ruby
hook?

> We'll add more methods to this object to address needs like this. In
> your case I'm considering adding:
>     void embed(byte[] data, String mimeType)
> That would allow you to embed an image. It would end up in the
> built-in HTML report. Would this solve your problem?

I haven't played around with customising the report output at all yet,
so I'm not entirely sure how that method would work...
It seems like I'd just pass in the image bytes and "image/png" and
it'd appear under the normal report data?
If so then yes, that would work quite well

aslak hellesoy

unread,
Feb 16, 2012, 6:06:42 PM2/16/12
to cu...@googlegroups.com
On Thu, Feb 16, 2012 at 10:28 PM, The Trav <the....@gmail.com> wrote:
>> Where would this screenshot be displayed? In a custom report? Something else?
> A custom report would probably be a superior option, however I'd
> settle for just putting it in a filestore somewhere that the test
> result consumers can go look at manually.
>
>> Not yet. You can add a hook:
>>     @cucumber.annotation.After
> Before and After hooks are called between each scenario?

Yes: https://github.com/cucumber/cucumber/wiki/Hooks

> I thought
> they'd be per feature file or per run of feature files...  Also I'm
> using the JRuby step definitions, so would I need to find the ruby
> hook?
>

Then this should do it:

After do |scenarioResult|
puts "ZOMG #{scenarioResult}"
end

>> We'll add more methods to this object to address needs like this. In
>> your case I'm considering adding:
>>     void embed(byte[] data, String mimeType)
>> That would allow you to embed an image. It would end up in the
>> built-in HTML report. Would this solve your problem?
>
> I haven't played around with customising the report output at all yet,
> so I'm not entirely sure how that method would work...
> It seems like I'd just pass in the image bytes and "image/png" and
> it'd appear under the normal report data?
> If so then yes, that would work quite well
>

Good

biswajit panda

unread,
May 28, 2012, 1:32:32 AM5/28/12
to cu...@googlegroups.com
How to get scenario names and steps in step definitions in cucumber jvm???

> To unsubscribe from this group, send email to cukes+unsubscribe@googlegroups.com.

Rakesh

unread,
May 28, 2012, 8:12:24 AM5/28/12
to cu...@googlegroups.com
posting the same question to 5 different threads is not helping your cause.

-- There are two rules:
 
1) Please prefix the subject with [Ruby], [JVM] or [JS]. This allows people to filter messages.
2) Please use interleaved answers http://en.wikipedia.org/wiki/Posting_style#Interleaved_style
 
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

biswajit panda

unread,
May 28, 2012, 8:17:10 AM5/28/12
to cu...@googlegroups.com
I am not able to figure out how to do that . Plz help me in this matter..
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+unsubscribe@googlegroups.com. For more options, visit this group at https://groups.google.com/d/forum/cukes?hl=en

Madhuri Sanap

unread,
Apr 3, 2013, 1:37:32 AM4/3/13
to cu...@googlegroups.com
Was any body success to get this in cucumber jvm (Java)?


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



--
Regards,
Madhuri S.

Aslak Hellesøy

unread,
Apr 3, 2013, 1:57:26 AM4/3/13
to cu...@googlegroups.com

On Wednesday, 3 April 2013 at 06:37, Madhuri Sanap wrote:

Was any body success to get this in cucumber jvm (Java)?

I have deliberately made it impossible. It creates a bidirectional coupling between gherkin and glue code (step definitions) which I consider harmful.

Most people asking for this seem to think it's needed for screenshots. It's not.

A Before hook can receive a Scenario object. Scenario provides a method to embed screenshots in the HTML report, without supplying a name.


Does this help you achieve what you want or do you have a different reason for wanting to access the feature and scenario name (which, by the way, are not guaranteed to be unique).

Aslak
--
-- Rules --

 
1) Please prefix the subject with [Ruby], [JVM] or [JS].
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.
 
 

Madhuri Sanap

unread,
Apr 3, 2013, 2:01:39 AM4/3/13
to cu...@googlegroups.com
We wanted this because during run time, we would be able to view Which Step/Sceanrio is getting executed. 
Thus it would be good to have this.
--
Regards,
Madhuri S.

Paolo Ambrosio

unread,
Apr 3, 2013, 2:28:19 AM4/3/13
to cu...@googlegroups.com
On Wed, Apr 3, 2013 at 7:01 AM, Madhuri Sanap <madhur...@gmail.com> wrote:

> We wanted this because during run time, we would be able to view Which
> Step/Sceanrio is getting executed.

Why don't you use a formatter then?


Paolo

Madhuri Sanap

unread,
Apr 3, 2013, 2:37:04 AM4/3/13
to cu...@googlegroups.com
can you please give an example


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





--
Regards,
Madhuri S.

Aslak Hellesøy

unread,
Apr 3, 2013, 3:08:30 AM4/3/13
to cu...@googlegroups.com

On Wednesday, 3 April 2013 at 07:37, Madhuri Sanap wrote:

can you please give an example

--format pretty 

Madhuri Sanap

unread,
Apr 3, 2013, 3:12:00 AM4/3/13
to cu...@googlegroups.com
i have defined following in build.xml, but when it execute the Scenario and steps are printed after all the test cases are exexuted on Console. 
In Previous version cucumber used to print each step once the execution of each step is completed.
        <arg value="--format"/>
            <arg value="pretty"/>

Madhuri Sanap

unread,
Apr 4, 2013, 3:45:59 AM4/4/13
to cu...@googlegroups.com
Any update on this?
--
Regards,
Madhuri S.

aslak hellesoy

unread,
Apr 4, 2013, 3:48:00 AM4/4/13
to Cucumber Users



On Thu, Apr 4, 2013 at 8:45 AM, Madhuri Sanap <madhur...@gmail.com> wrote:
Any update on this?



See rule 3)

Madhuri Sanap

unread,
Apr 4, 2013, 4:11:10 AM4/4/13
to cu...@googlegroups.com
Sorry I am not sure about the rules, can you please share the link.

Pankaj Nakhat

unread,
Apr 4, 2013, 4:18:53 AM4/4/13
to Madhuri Sanap, cu...@googlegroups.com
1) Please prefix the subject with [Ruby], [JVM] or [JS].

3) If you have a question, don't reply to an existing message. Start a new topic instead


Sent from my iPhone

Aslak Hellesøy

unread,
Apr 4, 2013, 8:25:47 AM4/4/13
to cu...@googlegroups.com

On Thursday, 4 April 2013 at 09:11, Madhuri Sanap wrote:

Sorry I am not sure about the rules, can you please share the link.

Scroll down in this window 
Reply all
Reply to author
Forward
0 new messages