passing variables to Feature statements

3,475 views
Skip to first unread message

Joe Fleck

unread,
May 6, 2013, 12:06:16 PM5/6/13
to cu...@googlegroups.com
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

Rob Park

unread,
May 6, 2013, 1:35:18 PM5/6/13
to cu...@googlegroups.com
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

Joe Fleck

unread,
May 6, 2013, 2:17:58 PM5/6/13
to cu...@googlegroups.com
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

Rob Park

unread,
May 6, 2013, 2:59:52 PM5/6/13
to cu...@googlegroups.com
Fixing rule #2


On Monday, May 6, 2013 1:35:18 PM UTC-4, Rob Park wrote:



On Mon, May 6, 2013 at 12:06 PM, Joe Fleck <joefl...@gmail.com> wrote:
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

For me, I'm not really sure what you're trying to do yet.

Where would the value for state come from?

On Mon, May 6, 2013 at 2:17 PM, Joe Fleck <joefl...@gmail.com> wrote:
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?

#rob



Rob Park

unread,
May 6, 2013, 3:06:22 PM5/6/13
to cu...@googlegroups.com
Guess I'm still wondering why that informations isn't coming from the scenario? 

#rob




Javix

unread,
May 7, 2013, 7:27:53 AM5/7/13
to cu...@googlegroups.com
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 | as...@email.com | 123   |
  | Matt  | ma...@email.com  | 234   |
  | Joe   | j...@email.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      |



Cheers

Kendall Shaw

unread,
May 7, 2013, 10:15:51 AM5/7/13
to cu...@googlegroups.com
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

aslak hellesoy

unread,
May 7, 2013, 10:26:56 AM5/7/13
to Cucumber Users

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

Message has been deleted

Matt Wynne

unread,
May 9, 2013, 5:37:11 AM5/9/13
to cu...@googlegroups.com

On 8 May 2013, at 14:55, Joe Fleck <joefl...@gmail.com> wrote:

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.


Kendall Shaw

unread,
May 9, 2013, 5:50:56 AM5/9/13
to cu...@googlegroups.com
On 5/7/2013 7:26 AM, aslak hellesoy wrote:
On Mon, May 6, 2013 at 11:06 AM, Joe Fleck <joefl...@gmail.com> wrote:
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.



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

Kendall Shaw

unread,
May 9, 2013, 5:54:17 AM5/9/13
to cu...@googlegroups.com
On 5/8/2013 6:55 AM, Joe Fleck wrote:
> 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
Reply all
Reply to author
Forward
0 new messages