Message is not printing on the console in jmeter using JSR223 and groovy

对着背影说爱祢 提交于 2019-11-30 01:07:03

问题


println() inside static void main method is not printing anything anywhere, whereas only println() prints in terminal. Here is my code:

class CalcMain {
static void main(def args) throws Exception {
    ScriptEngineManager factory = new ScriptEngineManager();
    ScriptEngine engine = factory.getEngineByName("groovy");

    println("testing");
  }
}

And when I ran it shows pass (Green Triangle in Jmeter) but doesnt print anything on terminal

Whereas a simple program such as

println("testing");

prints on terminal.

Could some one please let me know where I am doing wrong?

Thanks


回答1:


Don't use System.out.println in a Groovy or Beanshell step in jmeter. Instead , do this:

1. Enable the stdout console in Jmeter so that you can see the output.
2. Use  log.info("Message:" + vars.get("variableName"));  instead.



回答2:


Use below to display text in JMeter Response Tab in "Results Tree":

SampleResult.setResponseData("Document: " + variable,"UTF-8");

Use below to log in the console text area of JMeter:

log.info("hello");



回答3:


Chapter "2. OUT" shows the answer:

https://jmetervn.com/2016/12/05/jsr223-with-groovy-variables-part-1/

use the OUT command.

OUT.println("INPUT MESSAGE HERE");



回答4:


Try it: System.out.println("testing")




回答5:


You have not provided all code, just your part produces errors as imports are also needed. Definition of class does not run by its own, you need as instance and then run in explicitly, then it prints (both with and w/out System.out. prefix) to terminal:

import javax.script.ScriptEngine;
import javax.script.ScriptEngineManager;

class CalcMain {
static void main(def args) throws Exception {
    ScriptEngineManager factory = new ScriptEngineManager();
    ScriptEngine engine = factory.getEngineByName("groovy");

    println ("testing1");
    System.out.println ("testing2");
  }
}

CalcMain test1 = new CalcMain();
test1.main();
println ("testing3");

Output:

testing1
testing2
testing3


来源:https://stackoverflow.com/questions/19805712/message-is-not-printing-on-the-console-in-jmeter-using-jsr223-and-groovy

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!