Blazemeter 運行 Jmeter 腳本 - JSR223 腳本中的問題,檢索任務 javax.script.ScriptException: groovy.lang.MissingMethodException

喬希

我正在嘗試在 blazemeter 中運行一個有效的 jmeter 腳本,但是在嘗試運行我的 groovy 腳本時遇到以下錯誤。我正在編寫嘗試訪問在以前的 groovy 腳本中設置的 jmeter 屬性。

<JSR223PostProcessor guiclass="TestBeanGUI" testclass="JSR223PostProcessor" testname="Get Tasks to be Added" enabled="true">
            <stringProp name="cacheKey">true</stringProp>
            <stringProp name="filename"></stringProp>
            <stringProp name="parameters"></stringProp>
            <stringProp name="script">

import groovy.json.JsonOutput;

def failureMessage = &quot;&quot;;
def jsonResponse = null;

JsonSlurper JSON = new JsonSlurper ();
JsonOutput JsonOut = new JsonOutput ();

try {
    def numTasksToAdd = vars[&apos;numTasksToAdd&apos;] as Integer;    
    jsonResponse = JSON.parseText(prev.getResponseDataAsString());
    props.put(&quot;tasks&quot;, JsonOut.toJson(jsonResponse.result[0..numTasksToAdd]))
    } catch (Exception e) {
    failureMessage += &quot;Invalid JSON.\n&quot;
    log.info(e.toString());
}
</stringProp>
<stringProp name="scriptLanguage">groovy</stringProp>
</JSR223PostProcessor>

第二個常規腳本

<JSR223PostProcessor guiclass="TestBeanGUI" testclass="JSR223PostProcessor" testname="Retrieve Tasks " enabled="true">
          <stringProp name="cacheKey">true</stringProp>
          <stringProp name="filename"></stringProp>
          <stringProp name="parameters"></stringProp>
          <stringProp name="script">

import groovy.json.JsonSlurper;

JsonSlurper JSON = new JsonSlurper ();

var props = org.apache.jmeter.util.JMeterUtils.getJMeterProperties();

def failureMessage = &quot;&quot;;
def tasks = null;

try {
    
     tasks = JSON.parseText(props.get(&quot;tasks&quot;));

    for (i = 0; i &lt; tasks.size(); i++) {
        
            vars.put(&quot;taskId&quot; + i.toString(), tasks[i].id.toString());
            vars.put(&quot;taskTag&quot; + i.toString(), tasks[i].sourceTag.toString());
        
    }  

    vars.put(&quot;taskCount&quot;, tasks.size().toString());
         
    } catch (Exception e) {
    failureMessage += &quot;Invalid JSON.\n&quot;
    log.info(e.toString());
}


</stringProp>
<stringProp name="scriptLanguage">groovy</stringProp>
</JSR223PostProcessor>

在我的 jmeter 文件中,並收到以下錯誤

2021-11-17 20:18:51,294 ERROR o.a.j.e.JSR223PostProcessor: Problem in JSR223 script, Retrieve Tasks 
javax.script.ScriptException: groovy.lang.MissingMethodException: No signature of method: org.codehaus.groovy.jsr223.GroovyScriptEngineImpl.var() is applicable for argument types: (java.util.Properties) values: [[jdbc.config.jdbc.driver.class:com.mysql.jdbc.Driver|org.postgresql.Driver|oracle.jdbc.OracleDriver|com.ingres.jdbc.IngresDriver|com.microsoft.sqlserver.jdbc.SQLServerDriver|com.microsoft.jdbc.sqlserver.SQLServerDriver|org.apache.derby.jdbc.ClientDriver|org.hsqldb.jdbc.JDBCDriver|com.ibm.db2.jcc.DB2Driver|org.apache.derby.jdbc.ClientDriver|org.h2.Driver|org.firebirdsql.jdbc.FBDriver|org.mariadb.jdbc.Driver|org.sqlite.JDBC|net.sourceforge.jtds.jdbc.Driver|com.exasol.jdbc.EXADriver, ...]]
Possible solutions: eval(java.io.Reader), eval(java.lang.String), wait(), every(), any(), wait(long)
    at org.codehaus.groovy.jsr223.GroovyScriptEngineImpl.eval(GroovyScriptEngineImpl.java:324) ~[groovy-all-2.4.16.jar:2.4.16]
    at org.codehaus.groovy.jsr223.GroovyCompiledScript.eval(GroovyCompiledScript.java:72) ~[groovy-all-2.4.16.jar:2.4.16]
    at javax.script.CompiledScript.eval(CompiledScript.java:89) ~[java.scripting:?]
    at org.apache.jmeter.util.JSR223TestElement.processFileOrScript(JSR223TestElement.java:223) ~[ApacheJMeter_core.jar:5.2.1]
    at org.apache.jmeter.extractor.JSR223PostProcessor.process(JSR223PostProcessor.java:44) [ApacheJMeter_components.jar:5.2.1]
    at org.apache.jmeter.threads.JMeterThread.runPostProcessors(JMeterThread.java:931) [ApacheJMeter_core.jar:5.2.1]
    at org.apache.jmeter.threads.JMeterThread.executeSamplePackage(JMeterThread.java:569) [ApacheJMeter_core.jar:5.2.1]
    at org.apache.jmeter.threads.JMeterThread.processSampler(JMeterThread.java:490) [ApacheJMeter_core.jar:5.2.1]
    at org.apache.jmeter.threads.JMeterThread.run(JMeterThread.java:257) [ApacheJMeter_core.jar:5.2.1]
    at java.lang.Thread.run(Thread.java:829) [?:?]
德米特里

為了解決編譯失敗問題,您需要更改以下內容:

var props = org.apache.jmeter.util.JMeterUtils.getJMeterProperties();

對此:

def props = org.apache.jmeter.util.JMeterUtils.getJMeterProperties();

一般來說,您甚至不需要這一行,因為props速記是JSR223 測試元素的預定義變量

在此處輸入圖片說明

有關此和其他公開給 Groovy 的JMeter API速記的更多詳細信息,請參閱您應該與 Groovy 一起使用的前 8 個 JMeter Java 類文章

本文收集自互联网,转载请注明来源。

如有侵权,请联系 [email protected] 删除。

编辑于
0

我来说两句

0 条评论
登录 后参与评论

相关文章