Cycle can increment variable values but does not include steps for simple math
Cycle now includes steps to execute simple Groovy statements inline as well as execute complex Groovy scripts.
The 2 Cycle steps that execute Groovy are:
I execute Groovy "<GROOVY_STATEMENTS>"
I execute Groovy script "<GROOVY_SCRIPT_FILE>"
This article assumes a conceptual familiarity with Groovy/Java including general syntax, data types, import statements, class references and method usage.
For more information on Groovy see Apache Groovy
Two items of note regarding Cycle and Groovy.
This sample Feature contains 4 Scenarios representing the 4 staples of simple math. Groovy is powerful and can do much more complicated processing but this article focuses on the basics.
In each of the Scenarios the numbers to work with are assigned to Cycle variables and then passed into the inline version of the Groovy step to perform the function. The inline Groovy step will work with direct numbers as well but more commonly variables will be referenced in your Features.
After the mathematical function is performed a step to validate the results is executed.
Feature: Simple Math
Scenario: Addition
Given I assign 4 to variable "qty"
And I assign 8 to variable "lines"
When I execute Groovy "sum = qty + lines"
Then I verify number $sum is equal to 12
Scenario: Subtraction
Given I assign 4 to variable "qty"
And I assign 8 to variable "lines"
When I execute Groovy "difference = lines - qty"
Then I verify number $difference is equal to 4
Scenario: Multiplication
Given I assign 4 to variable "qty"
And I assign 8 to variable "lines"
When I execute Groovy "product = qty * lines"
Then I verify number $product is equal to 32
Scenario: Division
Given I assign 4 to variable "qty"
And I assign 8 to variable "lines"
When I execute Groovy "quotient = lines/qty"
Then I verify number $quotient is equal to 2