4

Requirement: Post response time of every sampler to Mongo DB, for that created an HttpClient java code(Class function).

Problem: Need to call the custom (reuse same code between 150+ jmx file) Java function to be called from Beanshell after every sampler.

void logTransaction(responseTime,samplerName);

Solution need: Incorporate custom java function(.c or .txt) with jmx file.

For example in Load runner we can include .h file(shared in common path) with reusable code and include in globals.h.

Is there any method or solution available with jmeter ?

4

4 回答 4

2

您可以在同样支持 Java/Beanshell 语言的JSR223 Sampler中运行相同的脚本文件。

Script file字段中输入脚本文件名并在不同的 jmx 文件中重用它

于 2017-10-02T05:25:03.150 回答
1

创建一个包含可重用 Java 代码的 JAR,并从 JSR223 侦听器中调用它,检查“缓存已编译的脚本(如果可用)”。

JSR223 监听器

使用默认脚本语言 (Groovy) 对您的通话进行编码:

def yourInstanceClass = new YourClass()
yourInstanceClass.logTransation(sampleResult.getTime(), sampleResult. getSampleLabel());
于 2017-10-31T19:24:03.637 回答
1

在此处输入图像描述

通过保存在 java 文件中并在 JSR223 中给出文件路径,可以重用代码。

于 2017-10-26T12:39:10.067 回答
0
  1. 将下一行添加到user.properties文件(位于 JMeter 安装的“bin”文件夹中)

    beanshell.sampler.init=BeanShellSampler.bshrc
    
  2. 将您的logTransaction函数放入BeanShellSampler.bshrc文件(相同位置,JMeter 的“bin”文件夹)
  3. 下次启动 JMeter 时,您将能够在任何脚本中从任何Beanshell 采样器调用该函数

参考:

于 2017-10-03T05:07:05.047 回答