Enable javascript in your browser for better experience. Need to know to enable it? Go here.
Blogs Banner

Twist 2.5: Sharing data between workflows

With Twist 2.5, we are introducing a new feature called Data Store which can be used to simplify sharing data between Workflows. This blog post explains how to use Twist data store.

At scenario execution time, Twist exposes two different stores for keeping data. A Scenario Store and a Suite Store. Scenario Store is unique to each scenario and will be only available till the scenario execution ends. A Suite Store has a wider scope and makes data available throughout the lifetime of the execution. Scenario Store can be used to share data between Workflows in the same scenario and Suite Store can be used to share data between different scenarios.
 
Note: Sharing data between different scenarios is not a good practice as it prevents parallel execution of scenarios and can lead to scenarios that depend on the order in which they are executed.
 

An example for Scenario Store

Consider the use case where a website requires users to login before accessing some features. In this case, you would create a login Context which would handle the log in and this Context will be used by a Scenario defined elsewhere. This makes it harder to access the ID of the current user in the Scenario steps. The Data Store solves this issue by making this data available throughout the execution lifetime of a Scenario.
 
The Scenario would look like this:
 
 
The login Context would look like:
public class ShouldBeLoggedIn {
    @Autowired
    private TwistScenarioDataStore scenarioStore;
    public void setUp() throws Exception {
        // Your actual login code goes here
        // User ID is added to scenario store
        scenarioStore.put("CurrentUser", 1);
    }
    public void tearDown() throws Exception {
        // Your actual logout code goes here
    }
}
 
The Workflow would look like this:
public class Workflow {
    @Autowired
    private TwistScenarioDataStore scenarioStore;
    public void printTheCurrentUser() throws Exception {
        // Getting the current user from the scenario store
        System.out.println("Current user ID is " + scenarioStore.get("CurrentUser"));
    }
}
 
When executed, this will print:
Current user ID is 1
 
The scenarioStore is auto wired and instantiated automatically by Twist during run time. This ensures that the user does not have to define the Store in each Workflow implementation.
 

Suite Store

The Suite Store also works in a similar manner. However, it is not defined automatically by Twist. If you wish to use this, just add the following to your Workflow implementation.
    @Autowired
    private TwistSuiteDataStore suiteStore;
Once this definition is added, Twist takes care of automatically initializing the suiteStore.
 

The newly-released Twist 2.5 also includes improvements to explore fixtures, test secure sites, and collate verification failures without halting the scenario. 

Try Twist now to improve test automation and fine-tune your CD process.

 

Disclaimer: The statements and opinions expressed in this article are those of the author(s) and do not necessarily reflect the positions of Thoughtworks.

Keep up to date with our latest insights