Discussion:
[Cucumber] [c++][cucumber-cpp] Calling Steps from Step Definitions
Add Reply
Victor Emilio Armengol Fernandez
2018-02-01 22:48:50 UTC
Reply
Permalink
Raw Message
Hi guys, In the ruby documentation you can call a step from a step
definition with this:

Given /^(.*) is logged in$/ do |name|
step "the user #{name} exists"
step "I log in as #{name}"
end


What is the equivalent "*step*" function in *cucumber-cpp* ?

Thanks in advance.
--
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.
Andrew Premdas
2018-02-03 15:21:02 UTC
Reply
Permalink
Raw Message
Though you can do this, I'd advise strongly against it. Instead call helper
methods instead. So with your example

module UserStepHelper
def create_user(name:)
...
end

def log_in(user:
...
end
end
World UserStepHelper

Given 'the user #{name} exists' do |name|
@user = create_user

Given /^(.*) is logged in$/ do |name|
login_user(create_user(name: name)
end

Treat each step definition as a call to a helper method. (solving simply
problem of matching scenario statements to step definitions). Then solve
the problem of having a single method call do alot of stuff in your
programming language (programming languages are designed for this task)

And now your question becomes how do I create helper methods in Cucumber
CPP. A question I hope someone else can answer (I don't use CPP)

All best

Andrew

On 1 February 2018 at 22:48, Victor Emilio Armengol Fernandez <
Post by Victor Emilio Armengol Fernandez
Hi guys, In the ruby documentation you can call a step from a step
Given /^(.*) is logged in$/ do |name|
step "the user #{name} exists"
step "I log in as #{name}"
end
What is the equivalent "*step*" function in *cucumber-cpp* ?
Thanks in advance.
--
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
For more options, visit https://groups.google.com/d/optout.
--
------------------------
Andrew Premdas
blog.andrew.premdas.org
--
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.
Victor Emilio Armengol Fernandez
2018-02-06 16:47:00 UTC
Reply
Permalink
Raw Message
Thanks, this looks a good solution to reuse some code, and seems the only
one, I was looking for a way to have a try-catch step that could handle any
other step, i.e.

GIVEN("^try (.*)$"){
REGEX_PARAM(string, otherStep);
try{
UNKNOWN_CODE_TO_CALL_OTHER_STEP(otherstep);
}catch(Exception e){ ... }
}

but it seems the only way should be to have to versions of each step, one
with try and the other whitout it, and call the helper methods from each
one.
Post by Andrew Premdas
Though you can do this, I'd advise strongly against it. Instead call
helper methods instead. So with your example
module UserStepHelper
def create_user(name:)
...
end
...
end
end
World UserStepHelper
Given 'the user #{name} exists' do |name|
@user = create_user
Given /^(.*) is logged in$/ do |name|
login_user(create_user(name: name)
end
Treat each step definition as a call to a helper method. (solving simply
problem of matching scenario statements to step definitions). Then solve
the problem of having a single method call do alot of stuff in your
programming language (programming languages are designed for this task)
And now your question becomes how do I create helper methods in Cucumber
CPP. A question I hope someone else can answer (I don't use CPP)
All best
Andrew
On 1 February 2018 at 22:48, Victor Emilio Armengol Fernandez <
Post by Victor Emilio Armengol Fernandez
Hi guys, In the ruby documentation you can call a step from a step
Given /^(.*) is logged in$/ do |name|
step "the user #{name} exists"
step "I log in as #{name}"
end
What is the equivalent "*step*" function in *cucumber-cpp* ?
Thanks in advance.
--
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
For more options, visit https://groups.google.com/d/optout.
--
------------------------
Andrew Premdas
blog.andrew.premdas.org
--
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...