【问题标题】:Performance Testing_JMeter性能测试_JMeter
【发布时间】:2018-12-22 14:18:35
【问题描述】:

我是 jMeter 的新手,在我的应用程序中,我有“源”和“目标”下拉框,我每次都需要生成一个随机值,如果“源和目标相同”则无法预订机票,

提前致谢,

【问题讨论】:

  • 欢迎来到 SO。请参阅stackoverflow.com/help/mcve 寻求帮助。您应该包括您尝试过的内容以及为什么它不能满足您的需要。

标签: regex string jmeter string-comparison


【解决方案1】:
  1. 添加相关的PostProcessor 以从框1 中获取所有下拉值。对于HTML 响应,建议使用CSS/JQuery Extractor。确保将“匹配号”设置为-1

    因此,您应该有 2 组 JMeter Variables 类似:

    source_1=foo
    source_2=bar
    source_3=baz
    source_matchNr=3
    
    destination_1=foo
    destination_2=bar
    destination_3=baz
    destination_matchNr=3
    
  2. 在 CSS/JQuery 提取器之后添加JSR223 PostProcessor,并将以下代码放入“脚本”区域:

    import org.apache.commons.lang3.RandomUtils
    import org.apache.jmeter.threads.JMeterVariables
    
    def randomSource = getRandomCity('source', vars)
    
    while (true) {
        def randomDestination = getRandomCity('destination', vars)
        if (!randomSource.equals(randomDestination)) {
            vars.put('randomSource', randomSource)
            vars.put('randomDestination', randomDestination)
            break
        }
    }
    
    def static getRandomCity(String prefix, JMeterVariables vars) {
        return vars.get(prefix + '_' + RandomUtils.nextInt(1, vars.get(prefix + '_matchNr') as int))
    }
    

    以上代码将创建以下 JMeter 变量:

    • ${randomSource}
    • ${randomDestination}

    您可以在需要时使用。确切的设置可能不同,但想法应该仍然相同。见

【讨论】:

    猜你喜欢
    • 2013-05-12
    • 1970-01-01
    • 1970-01-01
    • 2012-05-02
    • 2012-02-02
    • 2017-04-17
    • 2015-06-09
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多