Generating a random value

Creating a step to create random values for dynamic data testing

After recording a test that includes a Set text step (for entering text), you can edit the test configuration so that a different, randomly generated, string will be entered for that step each time that the test runs. The random text is generated and stored in a variable using the Generate random value step which you insert prior to the Set text step. You then edit your Set text step to use the variable created in the Generate random value step.
Being able to generate random data for testing enables you to extend coverage without needing to create additional tests, find failed cases within specification, enable distribution of sets of data, and ensure that you're not using the same data over and over in your tests.

To generate a random value using a “Generate random value” step:

  1. Hover over the (arrow symbol) where you want to add the step.
38493849

The action options are displayed.

300300
  1. Click on the "M" (Testim predefined steps).
    The Predefined steps menu opens.
300300
  1. Click on Actions.
    The Actions menu expands.
300300
  1. Scroll down through the menu and select Generate random value.

📘

Alternatively, you can use the search box at the top of the menu to search for Generate random value.

A "Generate random value" step is added in the Editor.

  1. Hover over the newly created step, and click on the Show Properties () icon.
38483848

The Properties panel opens on the right-hand side.

200200
  1. Fill in the properties as described below.
  • Description – The description of the step. (Default = Generate Random Value)
  • Variable name – The name of the variable in which you are storing the random data. (Default = randomValue)
  • String type – The type of characters which your random value consists of:
    • Letters Only: The random data includes only uppercase and lowercase letters.
    • Numbers Only: The random data includes only numerals.
    • Mixed: The random data includes numerals and uppercase and lowercase letters. This is the default.
  • Length – The number of random characters you are generating. (Maximum = 256; Default = 12)
  • Add prefix – Enables you to add a prefix to your randomly generated characters. The prefix can include strings (surrounded by single or double quotes), previously created variables, or a combination of both (connected with a plus symbol).
  • Add suffix – Enables you to add a suffix to your randomly generated characters. The suffix can include strings (surrounded by single or double quotes), previously created variables, or a combination of both (connected with a plus symbol).
  • Variable scope – The scope in which the variable can be passed:
    • Local: Allows you to pass parameters between steps in the same scope.
    • Test: Allows you to pass parameters between steps and groups in the same test. This is the default.
    • Suite: Allows you to pass parameters between tests in the same test suite.
  • When this step fails – Specify what to do if the step fails.
  • When to run step – Specify conditions for when to run the step. For more info, see Conditions.
  • Override timeout – Allows you to override the default time lapse setting which causes Testim to register a fail for a test step, and specify a different time lapse value (in milliseconds).

When the test is run, the generated random value (along with the optional prefix and suffix) is stored in the designated variable.

To modify your “Set text” step to set random text:

  1. Hover over the Set text step you wish to modify, and click on the Show Properties () icon.
38493849

The Properties panel opens on the right-hand side.

200200
  1. In the Text to assign field, enter the Variable Name which you used in the Generate random value step.

📘

The Text to assign field can include text strings (surrounded by single or double quotes), JavaScript expressions, previously created variables, or a combination (connected with a plus symbol).
Variables and JavaScript expressions should NOT be surrounded by quotes.

When the test is run, the text inputted on the screen includes the random value stored in the variable created in the Generate random value step.

Try it yourself

Click here to open a sample test which includes several Generate random value steps. Try running the test and practice adjusting the configuration.

894894