【问题标题】:If Condition for a Random Variable using JavaScript in Neoload Tool在 Neoload Tool 中使用 JavaScript 的随机变量的 If 条件
【发布时间】:2015-10-20 08:53:07
【问题描述】:

我之前在 LoadRunner 工作过,我发现在 Neoload 中编写脚本非常痛苦。我也不擅长用 JavaScript 编码。

我只是想使用 Neoload 工具捕获堆栈变量(名称)。

例如。 name_1, name_2, name_3, name_4

所以我需要随机化并从上述 4 个中进行选择。

比方说,name_${randInt}。到此为止我还好。

现在,我需要检查这个变量的值,例如。 name_${randInt} 的值为“已检查”。现在这就是我需要的。

如果 name_${randInt} = '检查',myVar = on;否则 myVar = 关闭

这个 myVar 被反馈给我的脚本。

听起来可能很简单,但是如何使用 Neoload 使用 Javascript 来完成呢?

示例代码如下,

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

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

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

【问题讨论】:

    标签: javascript if-statement random performance-testing neoload


    【解决方案1】:

    例子

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

    【讨论】:

    • 我正在专门寻求有关 Neoload 工具的帮助。请分享一些与该工具有关的信息。
    • javascript 在客户端执行...我认为您可以根据需要调整此代码。你能把你的源代码试试看帮助你吗?
    • 请再次查看帖子以获取我现在插入的示例代码。
    猜你喜欢
    • 2020-11-02
    • 1970-01-01
    • 2017-03-29
    • 2017-11-22
    • 2018-09-17
    • 2019-09-06
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多