我是jmeter的新手,我想使用java代码以非GUI的方式执行jmeter。
在端点上进行测试时,我想通过 java 代码传递"随请求发送参数"。所以我尝试按如下方式发送数据
HTTPSampler httpSampler = new HTTPSampler();
httpSampler.setProtocol("http");
httpSampler.setDomain(hostip);
httpSampler.setPort(8080);
httpSampler.setPath(endpointpath);
httpSampler.setMethod("POST");
HTTPArgument httpArgument = new HTTPArgument();
httpArgument.setValue("[{ "firstname": "", "name": "Venkat"}]");
没有错误来。请求未添加到数据库
有人可以建议并提供一个示例代码来使用 java 添加后请求正文吗?
httpSampler 没有关联的参数。基本上,您只是在发送没有任何参数的http请求。
您可能必须使用 addTestElement/setArgument 方法将参数关联到 httpsampler。
httpSampler.setMethod("POST");
HTTPArgument httpArgument = new HTTPArgument();
httpArgument.setValue("[{ "firstname": "venkatachalam", "name": "Venkata"}]");
httpSampler.addTestElement(httpArgument);
只是好奇 - 顺便说一下,你为什么要使用 java 创建你的 JMeter 测试?
要在非 gui 模式下运行 JMeter 测试,请使用以下命令和选项。(假设您将 %JMETER_HOME%/bin 添加到您的 PATH 变量中(
jmeter -n -t D:TestScriptsscript.jmx -l D:TestScriptsscriptresults.jtl
- -n [这指定 JMeter 将在非 gui 模式下运行]
- -t [包含测试计划的 JMX 文件的名称]
- -l [要将示例结果记录到的 JTL 文件的名称]
- -j [JMeter 运行日志文件的名称]。
除了这些选项之外,JMeter 还有其他几个参数可用于在非 GUI 模式下运行。
- -R [远程服务器列表] 在指定的远程服务器中运行测试
- -H [代理服务器主机名或 IP 地址]-P [代理服务器端口]