Chorus provides a built in handler called Chorus Context
This handler is used to view or manipulate variables stored within the Chorus Context
To use the handler, add Uses: Chorus Context
to the top of your feature file.
You can then make use of the steps provided:
Uses: Chorus Context
Feature: Show Chorus Context Steps
Scenario: Create a Context variable
Given the context has no values in it
When I create a context variable myVar with value 2
Then the context variable myVar exists
And the context variable myVar has the value 2
And I show context variable myVar
#the last step above will show the value of the variable in Chorus' output
n.b. Most often Context variables are set or updated by the step implementation methods in handler classes. The ChorusContext handler gives you the ability to view and manipulate these directly in your scenario.
You can define handler properties which will be loaded into the ChorusContext at the start of each Scenario
These properties need to be prefixed with ‘context.’
context.myVariable=myValue
context.myVariable2=myValue2
So that the Chorus Context handler will load these, you need to add Uses: Chorus Context
at the top of your feature file
At present these variables are loaded into the context as String values
Step | Example | Deprecated | Description | Retry Duration (wait for step to pass) |
---|---|---|---|---|
.*the context is empty | Given then context is empty | No | Check there are no variables set in the Chorus Context | |
.*create a context variable (.*) with (?:the )?value (.*) | When I create a context variable foo with the value bar | No | Create a variable within the Chorus Context with the value provided | |
.*context variable (.*) has (?:the )?value (.*) | Then the context variable foo has the value bar | No | Check the named context variable has the value specified | |
.*context variable (.*) exists | Then the context variable foo exists | No | Check the named Chorus Context variable exists | |
.*show (?:the )?context variable (.*) | And I show the context variable foo | No | Show the current value of the context variable in Chorus' output | |
.*type of (?:the )?context variable (.*) is (.*) | Then the type of the context variable foo is String | No | Check the type of the context variable (matching against the Java Class simple name) | |
.*add (?:the )?(?:value )?([\d\.]+) to (?:the )?context variable (.*) | And I add 5 to the context variable myNumericValue | No | Add the value provided to the named context variable which must contain a numeric value | |
.*subtract (?:the )?(?:value )?([\d\.]+) from (?:the )?context variable (.*) | And I subtract 5 from the context variable myNumericValue | No | Subtract the value provided to the named context variable which must contain a numeric value | |
.*multiply (?:the )?context variable (.*) by (?:the )?(?:value )?([\d\.]+) | And I multiply the context variable myNumericValue by 10 | No | Multiply the named context variable which must contain a numeric value by the specified number | |
.*divide (?:the )?context variable (.*) by (?:the )?(?:value )?([\d\.]+) | And I divide the context variable myNumericValue by 10 | No | Divide the named context variable which must contain a numeric value by the specified number | |
.*increment (?:the )?context variable (.*) | When I increment the context variable myVariable | No | Add one to the named context variable which must contain a numeric value | |
.*decrement (?:the )?context variable (.*) | When I decrement the context variable myVariable | No | Subtract one from the named context variable which must contain a numeric value | |
.*divide (?:the )?context variable (.*) by (.*) and take the remainder | When I divide context variable myVar by 10 and take the remainder | No | Set the named context variable to the remainder after dividing it by the specified number | |
.*(?:the )?context variable (.*) is a (.*) | Then the context variable myVar is a String | No | Assert the type of a context variable, by specifying the name of a concrete Java class. |
Property | Is Mandatory | Description | Default | Validation |
---|