Skip to main content

And/Or Statements

It is possible that some scripts may require a while or If condition that requires multiple values to be evaluated. This situation can normally be handled by nesting If or while statements within each other, but this approach can be hard to follow and often leads to duplicating Steps to handle all the situations.

There are two Features in CycleScript to assist with complex decisions: And statements and Executing Scenarios.

And statement

Cycle allows many Steps to be used as a conditional Step. The Steps within a multi-Step conditional Step must be separated by an AND. When evaluating a multi-Step conditional Step, Cycle will run the Steps one at a time. If any Step fails, Cycle does not run subsequent Steps within the conditional Step. If all the Steps pass, the Steps within the if or while statements are run.

The Scenario below shows Cycle prompting the user for two pieces of information. The script will look at the two values entered and scan the screen for an image to determine if the user is or is not a Carolina Panthers fan. If all three Steps pass, then the Step in the if statement is executed; otherwise, the conditional Step fails and the Step in the else statement is run.

Feature: NFL Team test

Scenario: Panthers fan check
Given I prompt "What state do you live in? (Abbr.)" and assign user response to variable "State"
Given I prompt "Do you like football? (Y/N)" and assign user response to variable "Football"
If I verify text $State is equal to "NC" ignoring case
And I verify text $Football is equal to "Y" ignoring case
And I see image "Image:images\Panthers_logo.png" within 3 seconds
Then I echo "Panthers fan"
Else I echo "Not a Panthers fan"
Endif

Or statement

There are situations in which you may need an if/while decision to look at multiple conditions and pass if any of the conditions are true. In a classic programming language, this logic would be addressed with an or statement. Cycle does not support the use of an or statement, however the same functionality can be achieved by calling another Scenario in the conditional Step using the I execute scenario Step. In the snippet below, the Feature calls Scenario North or South Carolina so that the if statement passes for either SC or NC.

Feature: NFL Team test

Scenario: Panthers fan check
Given I prompt "What state do you live in? (Abbr.)" and assign user response to variable "State"
Given I prompt "Do you like football? (Y/N)" and assign user response to variable "Football"
If I execute scenario "NC or SC"
And I verify text $Football is equal to "Y" ignoring case
And I see image "Image:images\Panthers_logo.png" within 3 seconds
Then I echo "Panthers fan"
Else I echo "Not a Panthers fan"
Endif

@wip
Scenario: NC or SC
If I verify text $State is not equal to "NC" ignoring case
And I verify text $State is not equal to "SC" ignoring case
Then I fail step
Endif