2015-10-20 32 views
-1

我以前在LoadRunner上工作過,我發現Neoload中的腳本是一個很大的痛苦。另外我用JavaScript編寫代碼並不好。如果在Neoload工具中使用JavaScript的隨機變量的條件

我只是想使用Neoload工具捕獲堆棧變量(名稱)。

Ex。 name_1,name_2,name_3,name_4

所以我需要隨機化並從上述4中進行選擇。

可以說,名稱_ $ {randInt}。我很好,直到這。

現在,我需要檢查這個變量的值,Say for ex。名稱_ $ {randInt}的值爲'已檢查'。現在這就是我需要的。

如果名稱_ $ {randInt} ='檢查',myVar = on; else myVar = off

而這個myVar會反饋給我的腳本。

聽起來很簡單,但如何使用Neoload使用JavaScript來完成?

下面的示例代碼中給出,

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

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

context.variableManager.setValue("computedVar1",computedValue); 

回答

0

<!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> 
+0

我專門找一些幫助Neoload工具..請分享有關該工具的一些信息.. – Nitya

+0

JavaScript是在客戶端執行......我認爲你可以根據你的需要調整這些代碼。 你可以把你的源代碼嘗試幫助你嗎? – jmmunoz

+0

請再次查看帖子,查看我現在插入的示例代碼。 – Nitya