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 <Outcome>
And the balance of my account should be <Remaining>
Examples: Successful withdrawal
| Balance | Withdrawal | Outcome | Remaining |
| $500 | $50 | receive $50 cash | $450 |
| $500 | $100 | receive $100 cash | $400 |
Examples: Attempt to withdraw too much
| Balance | Withdrawal | Outcome | Remaining |
| $100 | $200 | see an error message | $100 |
| $0 | $50 | see an error message | $0 |
Nesting Steps
Feature:login
Scenario:success login
Given I am on main page
When I input right user and pass
And I press login
Then I login successful
Given /I am on main page/ do
print "go to main page"
end
When /I input right user and pass/ do
print "input user and pass"
end
And /I press login/ do
print "press login"
end
Then /I login successful/ do
end
Feature:clazz management
Scenario:view clazz page
Given I have already login
When I press clazz button
Then I will go to clazz page
In 2rd Scenario,we can nesting the login step :
Given /I have already login/ do
steps %{
And I am on main page
And I input right user and pass
And I press login
}
end
When /I press clazz button/ do
#pending
end
Then /I will go to clazz page/ do
#pending
end
When Cucumber runs this high-level step, it will delegate to each of the lower-level steps.
The %{ ... } construct is just a way to tell Ruby that you have a string going across multiple lines.
1 step to nesting:
…… do
steps "And I am on main page"
end
Arguments and Nested Steps:
If the low-level steps you are nesting within a new high-level step take arguments,you’ll want to be able to capture those arguments in the high-level step and pass them to the low-level steps. Since the steps method just takes a string, you can use Ruby’s string interpolation to pass in the arguments:
Given /^an activated customer (\w+) exists$/ do |name|
steps %{
Given I create a customer with login #{name}
And I register the customer with login #{name}
And I activate the customer with login #{name}
}
end
But,passing a data table won't work!
Tags
If you want to tag all the scenarios in a feature at once, just tag the Feature
element at the top, and all the scenarios will inherit the tag. You can still tag
individual scenarios as well.
@nightly @slow
Feature: Nightly Reports
@widgets
Scenario: Generate overnight widgets report
to run a Scenario with tag:
$ cucumber --tags @tag1,@tag2