質問

I'm using Jmeter for testing purposes and I have to edit a paticular variable which is extracted through a regular expression and I'm trying to edit the variable using a javaScript which is in the Beanshell. First of all I would like to know whether I can iunclude javascripts directly in the Beanshell and second How can I invoke a JavaScript Function. For Example the following code.

var passwd = "abcd@123";
        var newpasswd = "";
        var ranVal= "ABCDEF";
 function SaveClick(){
      print("BBBBB");   

                document.write("<h3>Final Encripted Password : </h3>", newpasswd);
            //document.write(newpasswd);
        }
役に立ちましたか?

解決

You cannot mix Beanshell and javascript.

But to use full javascript, use Jsr223 elements and select javascript.

Note that you will need to inline your function code as it is not possible to call a function outside of element.

Anyway, Javascript does not give you access to DOM, so what you are trying to do with document.write will not work.

他のヒント

You can use BSF post processor, which has various scripting language, javascript being one of them.

http://jmeter.apache.org/usermanual/component_reference.html#BSF_PostProcessor Following is sample javascript from one of my test plan. Note the use of eval, putObject, put, log etc.

log.info("processing image index response");
if ("" != prev.getResponseDataAsString()) {
    eval( 'var indexJSON = ' + prev.getResponseDataAsString() );
    vars.putObject("indexJSON", indexJSON);

    vars.put("currentThumb", "0");
    vars.put("currentSlide", "0");

    var next_slide_timestamp=indexJSON[0].timestamp;
    vars.put("next_slide_timestamp", "0");

    var maxSlides=indexJSON.length;
    vars.put("maxSlides", maxSlides);
} else {
    vars.put("currentThumb", "0");
    vars.put("currentSlide", "0");
    vars.put("next_slide_timestamp", "0");
    vars.put("maxSlides", "0");
    log.info("index time : empty response , setting defaults to zero");
}
ライセンス: CC-BY-SA帰属
所属していません StackOverflow
scroll top