TruClient Web - How to select a random action?

Within the truclient interface I have a group of actions that are grouped together into a For...Next loop and want to randomly select one of the actions to execute. Is there a way to do this in the native TruClient interface or do I need to switch to a code-based TruClient script?

2 Replies
Fleet Admiral
Fleet Admiral


You can add an "If Block" from the Toolbox and surround any step you wish. Write JavaScript code with some randomization logic to ensure the If step condition is true randomly.




Vice Admiral Vice Admiral
Vice Admiral

I implemented Shlomi's way to select random step. 

1. Drag and drop javascript and add below code.

var i;
i=Math.floor((Math.random() * 3) + 1);

//change the number 3 into number of steps you have in the for loop.

2. In For loop, change the variable from i to j

3. Surround each step inside For Loop by if condition and add the condition for each if step as shown below. 



Thank you,
NaveenKumar Namachivayam |
Learn TruWeb - my Udemy Course "Performance Testing using TruWeb" |
The opinions expressed above are the personal opinions of the authors, not of Micro Focus. By using this site, you accept the Terms of Use and Rules of Participation. Certain versions of content ("Material") accessible here may contain branding from Hewlett-Packard Company (now HP Inc.) and Hewlett Packard Enterprise Company. As of September 1, 2017, the Material is now offered by Micro Focus, a separately owned and operated company. Any reference to the HP and Hewlett Packard Enterprise/HPE marks is historical in nature, and the HP and Hewlett Packard Enterprise/HPE marks are the property of their respective owners.