Discussion:
[Cucumber] passing variables to Feature statements
(too old to reply)
Joe Fleck
2013-05-06 16:06:16 UTC
Permalink
Hi,

I am new to cucumber and wondered if there is a way to pass a variable to a
feature statement or call a method to get the variable needed.

Ex:
Feature: Retrieve state forrn
As a customer
I want to print a form for this state

In the feature statement above I want 'state' to be the variable. I want
this to display in the Feature header output of the test result in Jenkins.

Joe
--
-- 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 cukes-/JYPxA39Uh5TLH3MbocFF+G/***@public.gmane.org To unsubscribe from this group, send email to cukes+***@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+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/***@public.gmane.org
For more options, visit https://groups.google.com/groups/opt_out.
Rob Park
2013-05-06 17:35:18 UTC
Permalink
Post by Joe Fleck
Hi,
I am new to cucumber and wondered if there is a way to pass a variable to
a feature statement or call a method to get the variable needed.
Feature: Retrieve state forrn
As a customer
I want to print a form for this state
In the feature statement above I want 'state' to be the variable. I want
this to display in the Feature header output of the test result in Jenkins.
Joe
For me, I'm not really sure what you're trying to do yet.
Where would the value for state come from?
What would your scenario look like?

#rob
--
-- 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 cukes-/JYPxA39Uh5TLH3MbocFF+G/***@public.gmane.org To unsubscribe from this group, send email to cukes+***@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+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/***@public.gmane.org
For more options, visit https://groups.google.com/groups/opt_out.
Joe Fleck
2013-05-06 18:17:58 UTC
Permalink
Hi Rob,

Thank you for responding. The state variable could come from a yml file or
a global variable in Jenkins.

We have several customers who we need to run our scripts against. We use
the gem that creates a nice html output with the results.

I want to see which state was executed in the feature statement in Jenkins.

Joe
Post by Rob Park
Post by Joe Fleck
Hi,
I am new to cucumber and wondered if there is a way to pass a variable to
a feature statement or call a method to get the variable needed.
Feature: Retrieve state forrn
As a customer
I want to print a form for this state
In the feature statement above I want 'state' to be the variable. I want
this to display in the Feature header output of the test result in Jenkins.
Joe
For me, I'm not really sure what you're trying to do yet.
Where would the value for state come from?
What would your scenario look like?
#rob
--
-- 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 cukes-/JYPxA39Uh5TLH3MbocFF+G/***@public.gmane.org To unsubscribe from this group, send email to cukes+***@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+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/***@public.gmane.org
For more options, visit https://groups.google.com/groups/opt_out.
Rob Park
2013-05-06 18:59:52 UTC
Permalink
Fixing rule #2
Post by Joe Fleck
Post by Rob Park
Post by Joe Fleck
Hi,
I am new to cucumber and wondered if there is a way to pass a variable
to a feature statement or call a method to get the variable needed.
Feature: Retrieve state forrn
As a customer
I want to print a form for this state
In the feature statement above I want 'state' to be the variable. I
want this to display in the Feature header output of the test result in
Jenkins.
Joe
For me, I'm not really sure what you're trying to do yet.
Where would the value for state come from?
Hi Rob,
Thank you for responding. The state variable could come from a yml file
or a global variable in Jenkins.
We have several customers who we need to run our scripts against. We use
the gem that creates a nice html output with the results.
I want to see which state was executed in the feature statement in Jenkins.
Joe
What would your scenario look like?
Post by Rob Park
#rob
--
-- 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 cukes-/JYPxA39Uh5TLH3MbocFF+G/***@public.gmane.org To unsubscribe from this group, send email to cukes+***@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+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/***@public.gmane.org
For more options, visit https://groups.google.com/groups/opt_out.
Rob Park
2013-05-06 19:06:22 UTC
Permalink
Post by Joe Fleck
Post by Joe Fleck
Post by Rob Park
Post by Joe Fleck
Hi,
I am new to cucumber and wondered if there is a way to pass a variable
to a feature statement or call a method to get the variable needed.
Feature: Retrieve state forrn
As a customer
I want to print a form for this state
In the feature statement above I want 'state' to be the variable. I
want this to display in the Feature header output of the test result in
Jenkins.
Joe
For me, I'm not really sure what you're trying to do yet.
Where would the value for state come from?
Hi Rob,
Post by Joe Fleck
Thank you for responding. The state variable could come from a yml file
or a global variable in Jenkins.
We have several customers who we need to run our scripts against. We use
the gem that creates a nice html output with the results.
I want to see which state was executed in the feature statement in Jenkins.
Joe
What would your scenario look like?
Guess I'm still wondering why that informations isn't coming from the
scenario?
Post by Joe Fleck
Post by Joe Fleck
Post by Rob Park
#rob
--
-- 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 cukes-/JYPxA39Uh5TLH3MbocFF+G/***@public.gmane.org To unsubscribe from this group, send email to cukes+***@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+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/***@public.gmane.org
For more options, visit https://groups.google.com/groups/opt_out.
Javix
2013-05-07 11:27:53 UTC
Permalink
See how to use DataTable, for example:

Data Tables are handy for specifying a larger piece of data:

Given the following users exist: | name | email | phone | | Aslak | aslak-***@public.gmane.org | 123 | | Matt | matt-***@public.gmane.org | 234 | | Joe | joe-***@public.gmane.org | 456 |

Like that you can catch whatever you want. Or you can put the argument to
catch between quotes and get in your step definition:

Scenario: Add two numbers
Given the input "2+2"
When the calculator is run Then the output should be "4"


Or to use scenario outlines:

Scenario Outline: Withdraw fixed amount
Given I have <Balance> in my account
When I choose to withdraw the fixed amount of <Withdrawal> Then I should
receive <Received> cash
And the balance of my account should be <Remaining>

Examples:

| Balance | Withdrawal | Received | Remaining |

| $500 | $50 | $50 | $450 |



More details are here:http://cukes.info/step-definitions.html

Cheers
Post by Rob Park
Post by Joe Fleck
Post by Joe Fleck
Post by Rob Park
Post by Joe Fleck
Hi,
I am new to cucumber and wondered if there is a way to pass a variable
to a feature statement or call a method to get the variable needed.
Feature: Retrieve state forrn
As a customer
I want to print a form for this state
In the feature statement above I want 'state' to be the variable. I
want this to display in the Feature header output of the test result in
Jenkins.
Joe
For me, I'm not really sure what you're trying to do yet.
Where would the value for state come from?
Hi Rob,
Post by Joe Fleck
Thank you for responding. The state variable could come from a yml file
or a global variable in Jenkins.
We have several customers who we need to run our scripts against. We
use the gem that creates a nice html output with the results.
I want to see which state was executed in the feature statement in Jenkins.
Joe
What would your scenario look like?
Guess I'm still wondering why that informations isn't coming from the
scenario?
Post by Joe Fleck
Post by Joe Fleck
Post by Rob Park
#rob
--
-- 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 cukes-/JYPxA39Uh5TLH3MbocFF+G/***@public.gmane.org To unsubscribe from this group, send email to cukes+***@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+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/***@public.gmane.org
For more options, visit https://groups.google.com/groups/opt_out.
Kendall Shaw
2013-05-07 14:15:51 UTC
Permalink
Post by Joe Fleck
Hi,
I am new to cucumber and wondered if there is a way to pass a variable
to a feature statement or call a method to get the variable needed.
Feature: Retrieve state forrn
As a customer
I want to print a form for this state
In the feature statement above I want 'state' to be the variable. I
want this to display in the Feature header output of the test result
in Jenkins.
Joe
JVM because that's what I am using. This would also apply to Ruby, I think.

My impression from other comments on the list is that, people really
want users to run cucumber as a standalone test with static text
features. They want cucumber to be the center of your universe. To get
around that for your practical problem, I would generate the feature at
runtime and replace the state variable.

Kendall
--
-- 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 cukes-/JYPxA39Uh5TLH3MbocFF+G/***@public.gmane.org To unsubscribe from this group, send email to cukes+***@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+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/***@public.gmane.org
For more options, visit https://groups.google.com/groups/opt_out.
aslak hellesoy
2013-05-07 14:26:56 UTC
Permalink
Post by Joe Fleck
Hi,
I am new to cucumber and wondered if there is a way to pass a variable to
a feature statement or call a method to get the variable needed.
Feature: Retrieve state forrn
As a customer
I want to print a form for this state
In the feature statement above I want 'state' to be the variable. I want
this to display in the Feature header output of the test result in Jenkins.
You can use environment variables:
https://github.com/cucumber/cucumber/wiki/Environment-Variables

And you can write information to the report with `puts` in your
hooks/stepdefs.

puts("Hello") or self.puts("Hello") goes to the report.
Kernel.puts("Hello") goes to STDOUT.

HTH
Aslak
Post by Joe Fleck
Joe
--
-- 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
To unsubscribe from this group, send email to
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
For more options, visit https://groups.google.com/groups/opt_out.
--
-- 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 cukes-/JYPxA39Uh5TLH3MbocFF+G/***@public.gmane.org To unsubscribe from this group, send email to cukes+***@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+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/***@public.gmane.org
For more options, visit https://groups.google.com/groups/opt_out.
Kendall Shaw
2013-05-09 09:50:56 UTC
Permalink
Post by Joe Fleck
Feature: Retrieve state forrn
As a customer
I want to print a form for this state
In the feature statement above I want 'state' to be the variable.
I want this to display in the Feature header output of the test
result in Jenkins.
https://github.com/cucumber/cucumber/wiki/Environment-Variables
And you can write information to the report with `puts` in your
hooks/stepdefs.
puts("Hello") or self.puts("Hello") goes to the report.
Kernel.puts("Hello") goes to STDOUT.
I thought the original question was about replacing text in the Feature
header output in the report, not the output of a step definition.

Kendall
--
-- 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 cukes-/JYPxA39Uh5TLH3MbocFF+G/***@public.gmane.org To unsubscribe from this group, send email to cukes+***@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+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/***@public.gmane.org
For more options, visit https://groups.google.com/groups/opt_out.
Joe Fleck
2013-05-08 13:55:46 UTC
Permalink
Yes, I thought of using datatable but I need the test to repeat at a higher
level. I want all of the scripts to run through every state we have not
just a few of them. Using a datatable for each scenario would be high
maintenance.

Kendall, are you saying to use JVM? Can you provide me with an with a site
to reference?

Thank you,
Joe
Post by Joe Fleck
Hi,
I am new to cucumber and wondered if there is a way to pass a variable to
a feature statement or call a method to get the variable needed.
Feature: Retrieve state forrn
As a customer
I want to print a form for this state
In the feature statement above I want 'state' to be the variable. I want
this to display in the Feature header output of the test result in Jenkins.
Joe
--
-- 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 cukes-/JYPxA39Uh5TLH3MbocFF+G/***@public.gmane.org To unsubscribe from this group, send email to cukes+***@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+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/***@public.gmane.org
For more options, visit https://groups.google.com/groups/opt_out.
Matt Wynne
2013-05-09 09:37:11 UTC
Permalink
I want all of the scripts to run through every state we have not just a few of them.
Why? What would be the extra risk if you only ran them for one state? That would help me to understand your context much better.

cheers,
Matt

--
http://mattwynne.net || https://twitter.com/mattwynne || http://the-cucumber-book.com || http://bddkickstart.com || http://www.relishapp.com
--
-- 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 cukes-/JYPxA39Uh5TLH3MbocFF+G/***@public.gmane.org To unsubscribe from this group, send email to cukes+***@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+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/***@public.gmane.org
For more options, visit https://groups.google.com/groups/opt_out.
Kendall Shaw
2013-05-09 09:54:17 UTC
Permalink
Post by Joe Fleck
Kendall, are you saying to use JVM? Can you provide me with an with a
site to reference?
No. Because the list rules ask to prefix the message, I prefixed the
message with the cucumber variant that I am using. If you wanted to, for
whatever reason, you could look for cucumber-jvm.

Kendall
--
-- 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 cukes-/JYPxA39Uh5TLH3MbocFF+G/***@public.gmane.org To unsubscribe from this group, send email to cukes+***@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+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/***@public.gmane.org
For more options, visit https://groups.google.com/groups/opt_out.
Continue reading on narkive:
Loading...