Cucumber keywords



Gherkin Keywords
Feature
Background
Scenario
Given
When
Then
And
But
Scenario Outline
Examples

The Question Mark Modifier
Given I have 1 cucumber in my basket
Given I have 256 cucumbers in my basket
...
Given /I have (\d+) cucumbers? in my basket/ do |number|
  # TODO: code goes here
End

Noncapturing Groups
When I visit the homepage
When I go to the homepage
...
When /I (?:visit|go to) the homepage/ do
  # TODO: code goes here
End

Scenario Outline
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 | $450        |


Examples: Attempt to withdraw too much
| Balance | Withdrawal | Outcome                   | Remaining |
| $100     | $200          | see an error message | $100        |

Nested Steps
Given /^a (\w+) widget with the following details:$/ do |color, details_table|
  step "I create a #{color} widget with the following details:", details_table
  steps %{
    And I register the #{color} widget
    And I activate the #{color} widget
  }
end
Command Line Options
Formatters
pretty : Prints the feature as is - in colours. Used by default.
progress : Prints one character per scenario.
html : Generates HTML report.
json : Prints the feature as JSON
junit : Generates a report similar to Ant+JUnit (can be useful for CI).
usage : Lists all of the step definitions in your project, as well as the steps that are using it. It shows you unused step definitions, and it sorts the step definitions by their average execution time.
stepdefs : Prints All step definitions with their locations. Same as the usage formatter, except that steps are not printed.
rerun : Prints failing files with line numbers.
Examples:
cucumber --format progress
..U--..F..
Each character represents the status of each step:
  • . means passing.
  • U means undefined.
  • - means skipped (or a Scenario Outline step).
  • F means failing.
cucumber -f pretty -f html --out cukes.html -f rerun --out rerun.txt
This tells Cucumber to write the HTML report to the file cukes.html, then rerun output to rerun.txt, and finally display the pretty formatter’s output in the console.
Useful Options
-b, --backtrace
Prints a full backtrace for each failure instead of a shortened one.
-v, --verbose
Outputs places where Cucumber is looking for code.
-r, --require
Tells Cucumber explicitly where to load code from.
-w, --wip
Fail if there are any passing scenarios.
-S, --strict
Fail if there are any undefined or pending steps.
-d, --dry-run
Invokes formatters without executing the steps. This also omits the loading of your support/env.rb file if it exists.
Filtering
Filltering with Tag Expressions
$ cucumber --tags @focus,@email
@focus OR @email
$ cucumber --tags @fast --tags @focus,@email
@fast AND (@focus OR @email)
$ cucumber --tags ~@slow --tags @focus,@email
NOT @slow AND (@focus OR @email)
$ cucumber --tags @javascript:10
Execute all scenarios tagged with @javascript, failing if more than ten are found.
Filtering on Lines
$ cucumber features/something.feature --line 45
$ cucumber features/something.feature:45
$ cucumber features/something.feature:45:89:107
Filtering on Names
$ cucumber --name logout
Runs scenarios that have logout in their name.
$ cucumber --exclude logout
Runs all scenarios except those with logout in their name.
Hooks
Scenario hooks
Before, After, Around.
Step hooks
AfterStep.
Global hooks
AfterConfiguration.
Tagged hooks
Before('@cucumis, @sativus', '~@aqua') do
  # This will only run before scenarios tagged
  # with (@cucumis OR @sativus) AND NOT @aqua
end


Junit Runner
package Annotation; 

import org.junit.runner.RunWith; 
import cucumber.junit.Cucumber; 

@RunWith(Cucumber.class) 
@Cucumber.Options(format = {"pretty", "html:target/cucumber"}) 

public class runTest { }
 

Cucumber Book

 
Link

No comments:

Post a Comment

Different Types of Keyboard Inputs : Type, SendKeys & Device Replay

1. Most objects support the TYPE method.  Type will enter the specified string into an object or perform a certain keyboard combinat...