Validation
Validation is crucial to creating a proper test in Cycle. Validation means checking the accuracy of an action done by a user or system. In Cycle, you add steps to a Scenario to add validation. Keywords can be used meaningfully to set up a structure for validation.
Review of keywords
The keywords Given, When, Then, And, and But can aid the readability of the steps in a Feature File. They can also provide a solid structure that supports 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
# Validation Steps start
Then I expect to see this outcome
And I expect to see this outcome too
But I don't expect to see this outcome
# Validation Steps end
Go to the Keywords page for more information on using keywords for the purpose of validation.
Why is validation important?
Without adding validation steps to a Feature File, you can run into false positives or misleading results. Validation means checking that when Cycle did what you asked, the result is what you expected.
Imagine you are testing a website, and you need to know that a given URL is valid, and that it opens the page in the format you are expecting. The following Feature File would lead to "all green" (successful) results in the Output pane in Cycle:
Feature: Test Features Page
Scenario: Features page
Given I open "Chrome" web browser
When I navigate to "http://www.cycleautomation.com" in web browser within 30 seconds
And I hover mouse over element "text:Overview" in web browser
And I click "FEATURES" link in web browser within 500 ms
While the above Feature File would execute successfully, what is it really testing? It is testing that Cycle opened the web browser, navigated to the CycleAutomation webpage, hovered over an element, and clicked it. It is not testing anything about the results of those clicks, such as what text is on the page that loads. The above script would not catch an error with the URL being mapped to the wrong page, for example.
To test something appropriately, consider what you are testing, and then validate actual results against expected results. In the Feature File below, steps validate the results of the clicks. The test checks that the appropriate page loads with the expected text.
Feature: Test Features Page
Scenario: Features page
Given I open "Chrome" web browser
When I navigate to "http://www.cycleautomation.com" in web browser within 30 seconds
And I hover mouse over element "text:Overview" in web browser
And I click "FEATURES" link in web browser within 500 ms
Then I see title "Features | Cycle" in web browser within 2 seconds
And I see "SEE WHAT CYCLE CAN DO" in web browser within 2 seconds
The validation example above is simple, but the concept can be generalized to all forms of testing. Imagine you are using Cycle to add a new user to a database. If you only executed the steps to add a new user, Cycle could show that 100% of the steps passed. However, perhaps there was a database issue and the user was not actually created. Without validating that the user was actually created in the database, you cannot be sure that the test truly passed. You would only know that Cycle successfully executed the steps.
Validation steps
Validation can be done by checking that something exists in a database, verifying that text, images, or elements exist on a webpage, verifying cursor positions in a terminal, checking images in a desktop application, and more. One of the most common types of steps used for validation is the "I see" group of steps. Steps that begin with "I see" check that the user is able to "see" something on the screen, typically after a certain action was taken in the system or process. Similarly, steps that begin with "I verify" check whether something the user cannot view on the screen is true.
[^1:] Cucumber Open Source Repository, Github, s.v. “Given When Then,” (accessed August 14, 2017), https://github.com/cucumber/cucumber/wiki/Given-When-Then.