Skip to main content

Keywords

Each Step in a Cycle Feature must begin with a keyword. There are a few different types of keywords. Some keywords perform a function, such as Once, If, Else, Elsif, Endif, While, and EndWhile. These are explained elsewhere in the manual. Other keywords, such as Given, When, Then, And, and But, do not execute a function or perform an action in Cycle, but they still serve an important purpose.

The keywords Given, When, Then, And, and But not only aid with the readability of the Steps in a Feature, but they can also be used meaningfully to support a standard approach to Business Process Validation.1

    # Example of using keywords for a purpose
# Note that these are not valid Steps, but are created to illustrate the concept

Given my system is in this expected state
When I perform this specific action
Then I expect to see this outcome
And I expect to see this outcome too
But I don't expect to see this outcome

The purpose of each keyword is explained in further detail below.

Given

Given should be used to describe the current state of the system or process, before a key interaction is performed by the user or system. For example, you might use Given to describe a current database connection that needs to be in place before executing a test. Another example would be to use Given to open a browser and navigate to a certain page that you plan to test. Given can also be used in conjunction with Activity Steps to document non-software assumptions that would be a precondition for running a test.

    # Describe a database connection
Given I connect to Mysql database "customers" at "localhost" port 3306 logged in as "USERNAME" with password "PASSWORD"

# Open a browser and navigate to a webpage that you plan to test
Given I open "Chrome" web browser
And I navigate to "https://www.cycleautomation.com" in web browser

# Document non-software or process assumptions
Given I "received no verbal reports of issues with the website"

When

When is ideal for describing interactions being performed by the user or system. You might use When to describe clicking a button in a piece of software or a webpage, for example. When should be used to describe the key interactions that you want to test or validate.

    # Describe a web interaction
When I click the "Feedback" link in web browser

# Describe a desktop interaction
When I click "Image:OKbutton.png" within 2 seconds

Then

The purpose of Then is to describe the expected result of an interaction for purposes of validation. For instance, when you click a button in a software application, then you expect a new screen to load. Then pairs well with validation Steps that begin with "I see", for example.

    # Validate the outcome of a web interaction
Then I see text "Accounts" in title in web browser

# Validate the outcome of a desktop interaction
Then I see "Image:SplashScreen.png"

And

And is used to join together a group of Givens, Whens, or Thens. Instead of having a group of Steps with the same keyword listed in a row, And can be used to make it clear there are multiple related Steps of a certain type, without sacrificing readability. And is also useful for inserting waiting Steps.

    # Join together a group of Whens
When I type "my username" in the "Login" field in web browser
And I type "my password" in the "Password" field in web browser
And I click element "id:submitbutton" in web browser

# Insert waiting Steps
When I click "Image:OKbutton.png"
And I wait 2 seconds

But

Similar to And, But can be used in conjunction with Given, When, and Then to describe a caveat or negative validation. For example, when you click a link in a web page, then you expect one screen to load, but not another screen to load.

    # Describe a negative validation
Then I see "Welcome" in web browser
But I do not see "Error" in web browser

Pulling it all together

Below is an example of a short Scenario that utilizes the keywords for their intended purpose.

    Given I open the "Chrome" web browser
And I navigate to "https://www.cycleautomation.com" in web browser
When I click the "Overview" link in web browser
Then I see "What is Cycle" in web browser within 3 seconds
But I do not see "404" in web browser within 3 seconds

Footnotes

  1. Cucumber Open Source Repository, Github, s.v. "Given When Then", (accessed August 14, 2017), https://docs.cucumber.io/gherkin/reference/#steps.