문제

I use JavaScript to parse my JSON result in BSF Assertion. For more reusability, i try to write my own JavaScript library. I would like use the library in my BSF Assertion.

Maybe i misunderstand the documents, i cannot find anyway to import my library in BSF. Dose only BeanShell provide this kind of method to import external script? (http://jmeter.apache.org/usermanual/functions.html#__BeanShell)

I even try another way but in vain.

1.Create BSF PreProcessor and put my library (named: myScript) in it.

function test(){
    log.info("Test Library");
}

2.Import the code and invoke it,

${__BeanShell(vars.get("myScript"))};
test()

But it doesn't work .. :(

Any idea?

도움이 되었습니까?

해결책

You can use JSR223 PreProcessor Choose Javascript language

Include your library using for example __FileToStringjsCode and put it in UserDefinedVariable:

jsCode / __FileToString(path to file)

In my example, file contains:

var s = "toto"; 

In you script:

${jsCode};
vars.put("toto", s);

Anyway I am not sure using Javascript is great for performances.

Groovy is a better option.

다른 팁

With BSF Element, you could expose javascript functions too. Check the example JMeter-Load-Javascript-Libraries-For-Future-Usage

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top