Discussion:
[Cucumber:8514] Get current step within step
(too old to reply)
Marc Divins Castellvi
2011-07-29 18:11:51 UTC
Permalink
Hi all,

Is there any way to get the current step name within a step definition? I've
tried to hack with @current_scenario and @__cucumber_step_mother without any
luck :(

Cheers,

Marc.
--
You received this message because you are subscribed to the Google Groups "Cukes" group.
To view this discussion on the web visit https://groups.google.com/d/msg/cukes/-/_5KMnxBkBKoJ.
To post to this group, send email to cukes-/JYPxA39Uh5TLH3MbocFF+G/***@public.gmane.org
To unsubscribe from this group, send email to cukes+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/***@public.gmane.org
For more options, visit this group at http://groups.google.com/group/cukes?hl=en.
Matt Wynne
2011-07-29 20:19:13 UTC
Permalink
Post by Marc Divins Castellvi
Hi all,
The most stable way is to cache it from a Before block:

Before do |scenario|
@current_scenario_name = scenario.name
end

Given /chalk/ do
if @current_scenario_name =~ /cheese/
fail "I can't be used in a cheese scenario!"
end
end

Does that help?

cheers,
Matt

--
Freelance programmer & coach
Author, http://pragprog.com/book/hwcuc/the-cucumber-book (with Aslak Hellesøy)
Founder, http://relishapp.com
+44(0)7974430184 | http://twitter.com/mattwynne
--
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 http://groups.google.com/group/cukes?hl=en.
Marc Divins Castellvi
2011-07-30 14:57:56 UTC
Permalink
Well, what we really need is the name of the Step we are running, not
current scenario (sorry if @current_scenario confused my words).
Any idea about it? There is no 'before_step' or step.name, so we don't know
how to get it :(
--
You received this message because you are subscribed to the Google Groups "Cukes" group.
To view this discussion on the web visit https://groups.google.com/d/msg/cukes/-/ojirGpGS3_IJ.
To post to this group, send email to cukes-/JYPxA39Uh5TLH3MbocFF+G/***@public.gmane.org
To unsubscribe from this group, send email to cukes+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/***@public.gmane.org
For more options, visit this group at http://groups.google.com/group/cukes?hl=en.
Matt Wynne
2011-07-30 19:41:03 UTC
Permalink
Any idea about it? There is no 'before_step' or step.name, so we don't know how to get it :(
You'll need to write a custom formatter for this. See here for details:
https://github.com/cucumber/cucumber/wiki/Custom-Formatters

cheers,
Matt

--
Freelance programmer & coach
Author, http://pragprog.com/book/hwcuc/the-cucumber-book (with Aslak Hellesøy)
Founder, http://relishapp.com
+44(0)7974430184 | http://twitter.com/mattwynne
--
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 http://groups.google.com/group/cukes?hl=en.
Marc Divins Castellvi
2011-08-02 07:58:20 UTC
Permalink
Ok! Thanks for all, we'll try this way.

Marc
--
You received this message because you are subscribed to the Google Groups "Cukes" group.
To view this discussion on the web visit https://groups.google.com/d/msg/cukes/-/r4U9syn0aJoJ.
To post to this group, send email to cukes-/JYPxA39Uh5TLH3MbocFF+G/***@public.gmane.org
To unsubscribe from this group, send email to cukes+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/***@public.gmane.org
For more options, visit this group at http://groups.google.com/group/cukes?hl=en.
l***@gmail.com
2018-01-04 06:01:52 UTC
Permalink
Hi, Marc, I suppose You must have solved the problem . I would like to get
the current step name too. and I have tried to use AfterStep hook to get
it.but it cannot work. besides, I have tried the suggestion from Matt
Wynne of writing a custom formatter. again, problem still unsolved.
Do you have any ideas ? Thanks in advance.
Post by Marc Divins Castellvi
Ok! Thanks for all, we'll try this way.
Marc
--
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.
l***@gmail.com
2018-01-04 08:39:14 UTC
Permalink
Hi, Marc, I have solved the problem.This is my solution:
how-can-i-access-a-cucumber-step-name-in-the-step-definition
<https://stackoverflow.com/questions/29952911/how-can-i-access-a-cucumber-step-name-in-the-step-definition/48090836#48090836>
I post it on stack overflow, hope it can do some help for you.
Post by l***@gmail.com
Hi, Marc, I suppose You must have solved the problem . I would like to get
the current step name too. and I have tried to use AfterStep hook to get
it.but it cannot work. besides, I have tried the suggestion from Matt
Wynne of writing a custom formatter. again, problem still unsolved.
Do you have any ideas ? Thanks in advance.
Post by Marc Divins Castellvi
Ok! Thanks for all, we'll try this way.
Marc
--
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...