0

I previously worked on LoadRunner and I find scripting in Neoload to be a great pain. Also I am not that good in coding with JavaScript.

I am just trying to capture a stack variable (name) using Neoload tool.

Ex. name_1, name_2, name_3, name_4

So I need to randomize and choose from 4 of the above.

Lets say, name_${randInt}. I'm ok till this.

Now, I need to check the value for this variable, Say for ex. name_${randInt} has the value 'Checked'. Now this is what I need.

If name_${randInt} = 'Checked', myVar = on; else myVar = off

And this myVar is fed back to my script.

Might sound simple but how can this be done with Javascript using Neoload?

Sample code is given below,

var check = context.variableManager.getValue("ERRP_CheckUnCheck");

if (check==null)
{
    computedValue = 'on'
}
else
{
    computedValue = null
}

context.variableManager.setValue("computedVar1",computedValue);
Nitya
  • 53
  • 8

1 Answers1

0

Example

<!DOCTYPE html>
<html lang="en">
<head>
  <title>Example</title>
  <meta charset="utf-8">
  <meta name="viewport" content="width=device-width, initial-scale=1">
  <script src="http://code.jquery.com/jquery-2.1.4.min.js"></script>
  </head>
<body>

<div class="container">
    element1 <input type="checkbox" id="elem1"/>
    element2 <input type="checkbox" id="elem2"/>
    element3 <input type="checkbox" id="elem3"/>
    element4 <input type="checkbox" id="elem4"/>
</div>
<button id="selectrandom">Select random</button>
<button id="whoiselect">who is select</button>

<script>

$(document).ready(function(){
    $('#selectrandom').on('click',function(){
    //count checkbox
    //$('.container').find('[type=checkbox]').length;  
    //random
    //parseInt((Math.random()*elements))
    //value to select
    //parseInt((Math.random()* $('.container').find('[type=checkbox]').length))+1

        //set all checked false
        $('.container').find('[type=checkbox]').prop('checked',false);

        $('#elem'+(parseInt((Math.random()* $('.container').find('[type=checkbox]').length))+1)).prop('checked',true);
    });
        $('#whoiselect').on('click',function(){
        if($( "input:checked" ).prop('id')!==undefined){
            alert($( "input:checked" ).prop('id'));
        }else{
            alert('Are not selected');
        }
    });


});
</script>

</body>
</html>
jmmunoz
  • 101
  • 1
  • 4
  • I'm specifically looking for some help with Neoload tool.. Kindly share some information pertaining to the tool.. – Nitya Oct 20 '15 at 10:41
  • javascript is executed in client... i think you can adapt this code to you need. can you put your source code to try help you? – jmmunoz Oct 20 '15 at 10:51
  • Please look into the post again for the sample code that I inserted now. – Nitya Oct 20 '15 at 11:22