Examples of using Return and arguments in JS Steps
  • 29 Sep 2023
  • 2 Minutes to read
  • Contributors
  • Dark
    Light

Examples of using Return and arguments in JS Steps

  • Dark
    Light

Article Summary

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:

Example

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.
スクリーンショット 2023-09-22 15.49.00.png

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.

スクリーンショット 2023-09-22 15.49.41.png

In this example, we will name it "random" add the argument.
スクリーンショット 2023-09-22 15.49.57.png

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].
スクリーンショット 2023-09-22 15.50.35.png

3. In the JS Step, add "TEST" in front of the random text and return the value

The random text specified in [2. Dynamic Value] will be assigned to the "random" argument we added in step 2 above, so we will write the following JavaScript to add the fixed string "TEST" in front of the random text. We will also return the value so that we can use it in subsequent steps.

return "TEST" + random;

スクリーンショット 2023-09-22 15.52.31.png

4. Use the returned value in a subsequent step

In the Input step in step 4, select [Other step's result] and specify [3. Execute JavaScript], which is the JS Step we just created.
スクリーンショット 2023-09-22 15.53.21.png

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.
スクリーンショット 2023-09-22 16.02.20.png

スクリーンショット 2023-09-22 16.02.28.png

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.


Was this article helpful?

Changing your password will log you out immediately. Use the new password to log back in.
First name must have atleast 2 characters. Numbers and special characters are not allowed.
Last name must have atleast 1 characters. Numbers and special characters are not allowed.
Enter a valid email
Enter a valid password
Your profile has been successfully updated.