Examples of using Return and arguments in JS Steps
JS Steps support return and arguments, which may make it possible to perform actions that you can't achieve with the standard features.
In this article, we will look at an example that uses return and arguments.
How to Use JS Steps and Dynamic Values
We will use JS Steps and the Dynamic Values in this article, but we will not cover the basics of how to use these features. To learn the basics, please refer to the following pages:
As an example, let's look at how to achieve the following actions:
- Add the fixed character "TEST" in front of the random text generated by the Dynamic Value feature, and enter the returned value "TEST + random text" in an input step.
1. Generate a random text using Dynamic Values
First, we want to generate a random text. Add a Dynamic Value step to the scenario and specify [Random text with specific characters].
In this example, we will use the default settings for its length and characters.
2. Create a JS Step and add an argument
Next, add a JS Step and add an argument by clicking [Add argument] in the JS Step.
In this example, we will name it "random" add the argument.
We want to use the [Random text with specific characters] we created in step 1 above, so under Argument values, select [Other step's result] and specify [2. Dynamic Value].
3. In the JS Step, add "TEST" in front of the random text and return the value
return "TEST" + random;
4. Use the returned value in a subsequent step
When we run the test with this setup, step 3 returns "TEST + random text", and from the screenshot in step 4, we can confirm that the target action was performed correctly.
As you can see, you can test a wide range of actions using return and arguments.
If you have any questions about using JS Steps, please feel free to contact support.