Example of a legacy snippet
If your workspace contains legacy snippets, we recommend that you convert your legacy snippets into parameterized snippets. The benefits of enabling snippet parameters include:
- Greater reusability: By overriding default parameter values, it's easier to reuse snippets across your workspace.
This guide outlines the steps you can take to convert your legacy snippets into parameterized snippets.
Enabling parameters for a legacy snippet
- Open a test that contains the legacy snippet in the mabl Trainer. The step that uses a legacy snippet will show an Unparameterized snippet badge.
- Click on the Unparameterized snippet badge or the pencil icon to edit the snippet step.
- Click on the Edit code button. The Snippet Editor will appear in a new window.
- Click on Enable parameters.
- Identify any variables that come from the
This snippet accesses a variable called "text" from the
- Convert those variables into parameters.
The "text" variable is added as the default parameter.
- Click Run to confirm that the snippet is working as expected.
- Click Save to confirm your changes. When you hover over the snippet step in the Trainer, you should see the parameters.
- Save your test with the newly converted snippet.
Once you've enabled parameters for your snippet, you can override the default value with a current value!
When you enable parameters in the code editor, adding a description of what a snippet does and how to work with its parameters can be helpful for other members of your workspace.