With flow parameters, you can scope variables to a single flow or reuse a flow with different variables. If you are familiar with common programming languages, you can think of flows as functions and parameters as input for one instance of the flow.
This article shows you how to work with parameterized flows in the mabl Trainer, including how to…
- Add parameters to a new flow
- Add parameters to an existing flow
- Override default parameter values
- Update default parameter values
- Export flow parameters outside a flow
- Remove flow parameters
How parameters work
When you create a flow parameter, mabl automatically adds the flow. prefix, so the parameter named email becomes flow.email. Flow parameters are initialized when the flow starts, and they are only available within the Start flow and End flow steps. If you don’t see your flow parameters in the dropdown, check your cursor position.
Flow parameters have two layers of values:
- The default value is set through Manage parameters. It applies to every instance of the flow that hasn’t been overridden. When you change a default value, the change applies to all instances that use the default.
- The override value is set on a specific flow instance in the Parameters tab. It applies only to that one use of the flow in that one test. Overriding a parameter in one instance does not affect any other instance of the flow, even within the same test.
If an override is set, it takes precedence over the default. To revert to the default, clear the override field. For example, imagine you create a “Login” flow with an email parameter and a default value of default_user@example.com:
- In Test A, you override
emailwithtestuser_a@example.com. - In Test B, you leave the default.
If you later change the default to new_default@example.com, Test B picks up the new value, but Test A still uses the override value: testuser_a@example.com.
How to add parameters to a new flow
To add parameters to a new flow, take the following steps in the mabl Trainer:
- Click on + (Add step) > Create a flow.
- Give the flow a name.
- Click on the Parameters tab.
- Click on Manage parameters to add new parameters.
- Give your parameters a name and a default value. You may enter a static string or number, a random value using valid expressions, or reference another variable from the test. Environment variables, DataTable variables, and variables created earlier in the test can all be referenced as parameter values using the
{{@variableName}}syntax. - Click OK to save your changes.
For example, to create a reusable “Login” flow, you might add two parameters: email with a default value of {{@app.defaults.username}} and password with a default value of {{@app.defaults.password}}.
If you use a variable as a flow parameter value, make sure that variable is initialized before the start of the flow. Otherwise, the step that uses the flow parameter will provide the value [not yet evaluated].
How to add parameters to an existing flow
To add parameters to an existing flow, open a test that contains the flow in the mabl Trainer and take the following steps:
- Click on the pencil icon to edit the flow.
- Click on the Parameters tab.
- Click on Manage parameters to add new parameters.
- Give your parameters a name and a default value.
After adding parameters, update the steps inside the flow to reference them. Adding parameters does not automatically change existing steps. For example, if your “Login” flow currently has a hardcoded email address in the email input step, you need to edit that step and replace the hardcoded value with {{@flow.email}}.
Replacing values in a flow with flow parameters
How to override default parameter values
To override a flow’s default parameter values, take the following steps:
- Click on the pencil icon to edit the flow.
- Click on the Parameters tab.
- Update the parameter value(s) to override the default.
- Click OK to save the override.
Overriding flow parameters in one instance does not update parameter values in other instances of the flow, even within the same test. For example, if your test uses the “Login” flow twice, for example once for an admin user and once for a standard user, you can override email independently in each instance.
Overriding default parameters
Parameters and looping
If a flow is looped, the same parameter values apply to every iteration. To run the same flow with different values, import the flow multiple times with separate overrides.
How to update default parameter values
To update a flow’s default parameter values, take the following steps:
- Click on the pencil icon to edit the flow.
- Click on the Parameters tab.
- Click on Manage parameters.
- Update the default parameter value(s).
- Click OK to save the new default parameter values.
Updating the default parameter values changes the values for any instance of the flow that uses the default parameter values. Any instance of the flow with parameter overrides is not affected. For example, if the default password for your “Login” flow changes, updating it in Manage parameters updates the password for every test that uses the default. Any test that uses an override for password keeps its override value.
Updating default parameter values
How to export flow parameters outside a flow
Variables created inside a flow are accessible in subsequent test steps, including steps in a parent flow or the containing test. However, flow parameters, the variables that are prefixed with flow., are scoped to the flow and are not accessible outside it.
If you want to use a flow parameter’s value outside a flow, create a new variable within the flow that stores the flow parameter’s value.
For example, if your “Login” flow captures a session token as flow.sessionToken, and you want to use thise value in a step after the flow ends, create a variable named sessionToken inside the flow with the value {{@flow.sessionToken}}. The variable sessionToken is then available in subsequent test steps outside the flow.
If you use the name of a variable already used earlier in the test, you will overwrite the original variable.
How to remove flow parameters
To remove flow parameters, open a test that contains the flow in the mabl Trainer and take the following steps:
- Click on the pencil icon to edit the flow.
- Click on the Parameters tab.
- Click on Manage parameters.
- Remove the parameters.
- Click OK.
If you remove parameters, change the steps in the flow to use regular variables instead of flow parameters or revert the flow version to a version before you started using parameters. Otherwise, the step that uses the flow parameter will provide the value [not yet evaluated].
Deleting flow parameters