SoapUI自動化--Groovy指令碼常用操作
soapUI-Groovy指令碼常見操作:(嘔心一個星期整理和test,經確認完全可以使用)
1.連線資料庫
//SQLServer
def sql=Sql.newInstance(url:"jdbc:sqlserver://192.168.1.2:1433;databaseName=databaseName",user:"sa",password:"password",driverClassName:"com.microsoft.sqlserver.jdbc.SQLServerDriver")
//Oracle
//def sql=Sql.newInstance("jdbc:inetpool:inetora:192.168.1.2?database=database&sid=sid","sa","password","com.inet.pool.PoolDriver")
//MySql
//def sql = Sql.newInstance("jdbc:mysql://localhost:3306/test","root","password","com.mysql.jdbc.Driver")
================================================================================================================================
2.執行資料庫語句
def allPayCode=sql.rows("select * from test.paycode")
log.info(allPayCode)
log.info(allPayCode[0])
log.info(allPayCode[0].PayCode)
Sun Aug 19 20:48:09 CST 2012:INFO:[{PayCode=1001, PayCodeName=input}, {PayCode=3001, PayCodeName=tuikuang}, {PayCode=2001, PayCodeName=zhuanzhang}]
Sun Aug 19 20:48:09 CST 2012:INFO:{PayCode=1001, PayCodeName=input}
Sun Aug 19 20:48:09 CST 2012:INFO:1001
*********************************************************************************************************
def fPayCode=sql.firstRow("select * from test.paycode")
log.info(fPayCode)
Sun Aug 19 20:55:26 CST 2012:INFO:{PayCode=1001, PayCodeName=input}
*********************************************************************************************************
def insertTable=execute("")
execute的返回結果是boolean型別的
===============================================================================================================================
3.對testCase的一些操作
--Property
def properties=testRunner.testCase.testSteps["Properties"]
//com.eviware.soapui.impl.wsdl.teststeps.WsdlPropertiesTestStep
def oriCardNo=properties.getPropertyValue("Number")
//獲取property中的值
properties.setPropertyValue("Number","999999")
//設定property中的對應名稱的值
--SOAPRequest
def groovyUtils = new com.eviware.soapui.support.GroovyUtils( context )
def holder = groovyUtils.getXmlHolder( "qqCheck#Response" )
holder.namespaces["ns1"] = "http://WebXml.com.cn/"
def value=holder.getNodeValue( "//ns1:qqCheckOnlineResponse[1]/ns1:qqCheckOnlineResult[1]" )
*******************************************************************************************************************
def wsdlRequestStep=testRunner.testCase.testSteps["qqCheck"]
//com.eviware.soapui.impl.wsdl.teststeps.WsdlTestRequestStep
def wsdlRequest=wsdlRequestStep.getTestRequest()
//com.eviware.soapui.impl.wsdl.teststeps.WsdlTestRequest
def wsdlResponse=wsdlRequest.getResponseContentAsXml()
//java.lang.String
def groovyUtils = new com.eviware.soapui.support.GroovyUtils( context )
def holder = groovyUtils.getXmlHolder(wsdlResponse)
holder.namespaces["ns1"] = "http://WebXml.com.cn/"
def value=holder.getNodeValue( "//ns1:qqCheckOnlineResponse[1]/ns1:qqCheckOnlineResult[1]" )
--HTTPRequest
def httpRequestStep=testRunner.testCase.testSteps["HTTPRequest"]
//com.eviware.soapui.impl.wsdl.teststeps.HttpTestRequestStep
def httpRequest=httpRequestStep.getHttpRequest()//com.eviware.soapui.impl.wsdl.teststeps.HttpTestRequest
def httpResponse=httpRequest.getResponseContentAsXml()
def groovyUtils = new com.eviware.soapui.support.GroovyUtils( context )
def holder = groovyUtils.getXmlHolder(wsdlResponse)