Forum Discussion

praneeth12's avatar
praneeth12
Occasional Contributor
5 years ago

JDBCrequst from groovy script,After successful connection and query executed.How to set response .

//query executed from script

def con = Sql.newInstance("jdbc:oracle:thin:@vXXX:XXX", "XXX", "XXX", "oracle.jdbc.driver.OracleDriver")
//Sucessfully Connected Database
def respId = con.rows("SELECT CODE from STATUS where STATUS_ID = '22' "

//Now getting proper response. Hear how to add response name value to Property from groovy script.

 

//query executed from JDBCRequst from jdbc custom  property i am seting values to PropertyStep 

//if i am run JDBCRequst with out script i can save the response in property as ResponseAsXml with that property i can save values into property using script. 

def step = context.testCase.testSteps['Properties']

step.propertyNames?.each {
step.removeProperty(it)
}
//Parent nodes like Result,ResultSet,Row
dbdata.'**'.find{
//log.info it.name()
it.name() == 'Row'

}.childNodes().each {
//log.info "${it}"
def prop = step.hasProperty(it.name()) ? step.getProperty(it.name()) : step.addProperty(it.name())
//log.info prop
prop.value = it.text()
//log.info it.text()

.

    • praneeth12's avatar
      praneeth12
      Occasional Contributor

      licNum = con.rows("SELECT * from LICENSE where LICENSE_NUMBER='564767' ")

      I am getting data from data base all column values with below format useing jdbcRequst from groovy.

      [{LICENSE_ID=421, IS_ACTIVE=1,  LICENSE_CLASS_ID=1, APPROVED_EVENT_DATE=null}]

      how to Set above Name and values to properties.

      • HimanshuTayal's avatar
        HimanshuTayal
        Community Hero

        praneeth12 :

         

        If it is a array then you can use:

         

        arrSize = licNum.size();

        for(int i= 0 ; i < arrSize ; i++){

        if(i==0){

        testRunner.testCase.getTestStepByName("Properties").setPropertyValue("LICENSE_ID",licNum[i])

        }

        else if(i == 1){

        testRunner.testCase.getTestStepByName("Properties").setPropertyValue("IS_ACTIVE",licNum[i])

        }

        }

        likewise, hope it will resolve your issue 🙂