Groovy可重用函数 - 提取节点值 - groovy.lang.MissingMethodException:

时间:2014-11-18 07:14:29

标签: groovy soapui

我是一个Groovy菜鸟,并尝试使用可重用函数来为SoapUI中的给定测试步骤和节点提取xml节点值。似乎该类运行正常,但问题是在使用该方法时。我收到以下错误:

groovy.lang.MissingMethodException: No signature of method: org.apache.log4j.Logger.info() is         applicable for argument types: (java.lang.String, java.lang.String) values: [return TestStepName, Node] Possible solutions: info(java.lang.Object), info(java.lang.Object, java.lang.Throwable), any(), wait(), dump(), find(groovy.lang.Closure) error at line:

这是我的班级:

class Example
{
def log
def context
def responseSOAXmlStep
def resultValue
def responseNodePath
def storeProperty
// Class constructor with same case as Class name
def Example(logIn,contextIn,testRunnerIn)
    {
    this.log = logIn
    this.context = contextIn
    this.responseSOAXmlStep = responseSOAXmlStep
    this.responseNodePath = responseNodePath
    }

    def execute(responseSOAXmlStep,responseNodePath)
{
    def groovyUtils = new com.eviware.soapui.support.GroovyUtils( context );
        // do some stuff to prove I've run with right context, etc.
        log.info "return "+responseSOAXmlStep,responseNodePath

    def holder = groovyUtils.getXmlHolder( responseSOAXmlStep+"#ResponseAsXml" );
    resultValue = holder.getNodeValue( "//ns1:"+responseNodePath );
    log.info("Node value: " +  resultValue );
    testRunner.testCase.testSuite.setPropertyValue(storeProperty, resultValue);


        return execute
}

}
context.setProperty( "example", new Example( log, context, testRunner) )
log.info "Library Context:"+context

这是我在响应步骤后的一个步骤中进行调用的地方:

// get a reference to the library TestSuite
library = testRunner.testCase.testSuite.project.testSuites["Library"]

// find the module within the library 
module = library.testCases["Library"].testSteps["Second Example_Class"]

// initialise the library; which places an instance of Example in the context
module.run(testRunner, context)

// get the instance of example from the context.
def example = context.example

// run the method, with parameter
log.info "example.execute(responseSOAXmlStep,responseNodePath) = " +        example.execute("TestStepName","Node")

我已经搜索了论坛但找不到符合我查询的答案。任何形式的援助表示赞赏。感谢。

1 个答案:

答案 0 :(得分:0)

您的错误说明表示您在info()上调用了log方法,并传递了两个strings和参数,并且此方法不存在。

问题很容易解决,传递一个带有+的连接字符串作为参数,而不是传递两个字符串。在execute课程中的Example方法中,请使用此代码:

def execute(responseSOAXmlStep,responseNodePath)
{
...
    // USE + TO CONCATENATE STRINGS INSTEAD OF USE , 
    log.info "return " + responseSOAXmlStep + responseNodePath
...
}

而不是:

def execute(responseSOAXmlStep,responseNodePath)
{
...
    // do some stuff to prove I've run with right context, etc.
    log.info "return " + responseSOAXmlStep,responseNodePath 
...
}

修改

正如您在评论中所说,您可能存在另一个问题,即在TestSuite级别存储属性。您正在使用此代码:

testRunner.testCase.testSuite.setPropertyValue(storeProperty, resultValue);

问题是setPropertyValue期望string作为第一个参数,但是代码storeProperty中的这一行尚未定义。尝试将storeProperty定义为:

def storeProperty = "myProperty"调用中使用

setPropertyValue之前。

希望这有帮助,