A Context is a logical step that must occur before a scenario is run. A scenario can have one or more Contexts defined. A Context refers to a Java class with the methods setUp() and tearDown().
You can add contexts by using the Add button on the Context bar. It is possible to specify multiple Contexts. For ex. Logged In.
However, this action does not create the underlying Java class. You must invoke the Create Context from the pull-down menu in the Context to create the Java class.
Existing Contexts are available as Content Assist inside the Context editor. You can reuse existing contexts by typing in the first few characters of the Context and then invoking Ctrl+Space on it.
Contexts can be reused across Scenarios. Therefore, an initialization step common to multiple scenarios can be abstracted as a Context in each of those scenarios. Twist also allows the same Context name to have multiple number of parameters. In a technical context, this would create additional methods with parameters in the underlying class with the same name. Thus, Contexts can be overloaded.
The Rename Context available on a context from the pull-down menu, lets the user rename an existing context. Following rename, the underlying context fixtures are also modified accordingly.
During scenario execution, each of the Contexts are invoked in the order they are specified. Before executing any Workflow or Business Rules Table in the scenario, the setUp method of each Context is executed.
After execution of all Workflows and Tables in the scenario, the tearDown methods of the Contexts would be executed in the reverse order of the order in which they are specified.
The tearDown methods of Contexts get invoked even when scenarios fail or throw an error.