[ReadyAPI]:使用Groovy脚本

时间:2018-03-19 21:06:29

标签: soapui ready-api

需要帮助: 将我的ReadyAPI从2.0升级到2.3版本。我有groovy脚本连接到项目级别定义的数据库。升级后会抛出以下错误。

错误:

  

引起:groovy.lang.MissingMethodException:没有方法签名:   com.eviware.soapui.impl.wsdl.support.connections.DefaultDatabaseConnectionContainer.getDatabaseConnectionByName()   适用于参数类型:(java.lang.String)值:[MyDB]       在org.codehaus.groovy.runtime.ScriptBytecodeAdapter.unwrap(ScriptBytecodeAdapter.java:58)       在org.codehaus.groovy.runtime.callsite.PojoMetaClassSite.call(PojoMetaClassSite.java:49)       在org.codehaus.groovy.runtime.callsite.CallSiteArray.defaultCall(CallSiteArray.java:48)       在org.codehaus.groovy.runtime.callsite.AbstractCallSite.call(AbstractCallSite.java:113)       在org.codehaus.groovy.runtime.callsite.AbstractCallSite.call(AbstractCallSite.java:125)       在Script3.run(Script3.groovy:11)       在com.eviware.soapui.support.scripting.groovy.SoapUIGroovyScriptEngine.run(SoapUIGroovyScriptEngine.java:98)       在com.eviware.soapui.support.scripting.groovy.SoapUIProGroovyScriptEngineFactory $ SoapUIProGroovyScriptEngine.run(SoapUIProGroovyScriptEngineFactory.java:82)       在com.eviware.soapui.impl.wsdl.testcase.WsdlTestCase.runScript(WsdlTestCase.java:984)       在com.eviware.soapui.impl.wsdl.testcase.WsdlTestCase.runSetupScript(WsdlTestCase.java:989)       ... 9更多

我的剧本:

import groovy.sql.Sql
com.eviware.soapui.support.GroovyUtils.registerJdbcDriver("com.microsoft.sqlserver.jdbc.SQLServerDriver");
def rbConObj = context.testCase.testSuite.project.databaseConnectionContainer.getDatabaseConnectionByName("MyDB");
def rbconstring = rbConObj.getConnectionString();
def sql = Sql.newInstance(rbconstring);
sql.executeUpdate("UPDATE Table SET Column = 2 Where ID = 1505")

1 个答案:

答案 0 :(得分:1)

SmartBear支持论坛中的评论说,版本2.2中已弃用DatabaseConnectionContainer,但我不认为这是对的。方法getDatabaseConnectionByName已经重构为getResourceByName。这会更好。