Reuse steps with blocks
Some tests will use the same steps. For example, most many test sessions start with login. To avoid rewriting login instructions in each story, and to allow for easy maintenance, you can create Blocks.
A Block is a group of steps that can be reused across stories. A block is essentially a function you can reuse in many places in your code. When you change the block, all the stories that use it will use the new version.
- Blocks are uniquely identified by a slug. Slugs are unique across a test suite. When saving a block, the version id is updated, but the slug doesn't change.
- Blocks can contain variables
- If a block contains variables, those variables will need to be redefined in every story that uses them or passed from CI. Stories are the ultimate source of truth for variables.
- Blocks cannot contain blocks
- A story can contain 0, 1 or many blocks
- Updating a block will impact all the stories that use it
Creating a block
To create a block, just create a story in the studio, but instead of saving it click on Save as block.
Editing a block
In any test suite, go to the Blocks tab, find your block and select Edit in the dropdown menu. This will pop open the studio, where you can edit the block.
Using a block
In the studio, click on Block in the step palette and pick your block. Only blocks from the same test suite can be imported so far.