我是一个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")
我已经搜索了论坛但找不到符合我查询的答案。任何形式的援助表示赞赏。感谢。
答案 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
之前。
希望这有帮助,