Forum Discussion

werther78's avatar
werther78
New Contributor
6 years ago

Parametize test data from JDBC into request

Hi, I am new to SoapUI, I am able to connect to my database for now. I want to know how can I use the data from the query and input that into the request parameter so that it gives a response using groovy script. My query will give tracking numbers and I want the soapui to input these tracking numbers and give the appropriate response.

 

 

Thanks.

2 Replies

  • In SoapUI open source, after JDBC connection, response will be shown in xml format.

    Please see below image, wher I am doing a sample JDBC connection

     

    From this response I retrieve Email value with this groovy script. And set this Email value as a Properties in TestSuite. So that I can use this property in any TestCase. [${#TestSuite#Properties}]

     

     

    Like Email You can retreve Tracking Number from response. I think It will help you. 

     

  • luluberlu's avatar
    luluberlu
    Occasional Contributor

    hi

    i got solution for you.

    example of groovy script which recover and test one database field value : 

    before you have : testcase property with expected values, and a JDBC Step which give you database answer :

    <Results>
    <ResultSet fetchSize="0">
    <Row rowNumber="1">
    <databasename.datafield1>123</databasename.datafield1>

    ...
    <databasename.datafieldname>123</databasename.datafieldname>
    ... 

    </Row>
    </ResultSet>
    </Results>

     

    import com.eviware.soapui.support.XmlHolder

    def reponse = context.expand( '${JDBCTestStep#ResponseAsXml#//*:Results/ResultSet/Row}' )
    def egal = true
    if (reponse != "") {
    // log.info " answer recover : " + reponse 
    // Test field in database 
    def Slurp = new XmlSlurper().parseText(reponse)
    def FieldDB = Slurp."databasename.datafieldname"
    // log.info " FieldDB : " + FieldDB
    def FieldExpected = testRunner.testCase.getPropertyValue("FieldValueExpected")
    if (FieldDB == FieldExpected ) { log.info " the field  " + FieldDB + " is correct in database."}
    else { egal = false; log.info " the field " + FieldDB + " is not correct in database."}
    }
    else { egal = false; log.info " request sent is empty !"}
    assert egal