cancel
Showing results for 
Search instead for 
Did you mean: 

Groovy script getting value from response doesn't work when using testrunner.sh

Highlighted
Visitor

Groovy script getting value from response doesn't work when using testrunner.sh

I am trying to use a script assertion to get a property's value from a SOAP response in a groovy script, verify that value and then write the assertion's result to a local database. All works well (you can see the code posted below) when starting the test case from the user interface. When I start the project from the command line via testrunner however, not so much. For some reason the value I retrieve returns an empty string, thus the assertion always fails. I will also paste the error log below. So here's my question: 

Why can't it retrieve the correct value from the response when using the testrunner? And how can I fix this? 

Thank you very much in advance for your assistance.

 

Groovy Script Assertion:

import com.eviware.soapui.support.XmlHolder
import groovy.sql.Sql

def holder = new XmlHolder( messageExchange.responseContentAsXml )
holder.namespaces["ns2"] = "http://www.tmforum.org/mtop/fmw/xsd/gen/v1"
holder.namespaces["ns10"] = "http://www.tmforum.org/mtop/nra/xsd/cmo/v1"
holder.namespaces["ns4"] = "http://www.tmforum.org/mtop/rtm/xsd/mr/v1"

//Reading regex from the local database using DataSource test step
def regex_Range_HW = context.expand( '${DataSource-actual_run_state#mapping_huawei_Range_HW}' )

//Getting node value from response

def value = context.expand( '${actual_run_state#Response#declare namespace ns2=\'http://www.tmforum.org/mtop/fmw/xsd/gen/v1\'; declare namespace ns10=\'http://www.tmforum.org/mtop/nra/xsd/cmo/v1\'; declare namespace ns4=\'http://www.tmforum.org/mtop/rtm/xsd/mr/v1\'; //ns4:getManagedObjectStatusResponse[1]/ns4:objStatusList[1]/ns10:objectStatus[1]/ns10:statusList[1]/ns2:nvs[1]/ns2:value[1]}' )

//Assertion with regular expression
def regexResult = value.matches(regex_Range_HW)
//Then writing result to database; 

 And here is the error log (it seems to me, that the retrieved value from the response is just an empty string):

14:31:35,808 INFO  [WsdlProject] Loaded project from [file:/home/user/Desktop/PlausiChecks.xml]
14:31:35,972 INFO  [SoapUIProTestCaseRunner] Running tests in the project [PlausiChecks]
14:31:35,979 INFO  [SoapUIProTestCaseRunner] Running Project [PlausiChecks], runType = SEQUENTIAL
14:31:35,994 INFO  [SoapUIProTestCaseRunner] Running TestCase [Copy of ONT-Verfügbarkeit prüfen]
14:31:36,197 INFO  [SoapUIProTestCaseRunner] running step [DataSource-actual_run_state]
14:31:36,227 INFO  [DBDataSource] Retrieved 1 columns from the result set
14:31:36,233 INFO  [SoapUIProTestCaseRunner] running step [actual_run_state]
14:31:37,379 INFO  [SoapUIProTestCaseRunner] Assertion [SOAP Response] has status PASS
14:31:37,379 INFO  [SoapUIProTestCaseRunner] Assertion [Contains] has status PASS
14:31:37,379 INFO  [SoapUIProTestCaseRunner] Assertion [AssertValueOfRunningStatusMySQL] has status FAIL
14:31:37,380 ERROR [SoapUIProTestCaseRunner] ASSERTION FAILED -> assert (node.getAttribute("RunningStatus").matches(regex_Range_HW)) ==~ true
        |    |                             |       |                |
        |    ""                            false   |                false
        |                                          OffLine|OnLine|Unknown
        <?xml version="1.0" encoding="UTF-8"?>
        <ns2:value xmlns:ns2="http://www.tmforum.org/mtop/fmw/xsd/gen/v1"
                   xmlns="http://www.tmforum.org/mtop/fmw/xsd/hdr/v1"
                   xmlns:ns4="http://www.tmforum.org/mtop/rtm/xsd/mr/v1"
                   xmlns:ns3="http://www.tmforum.org/mtop/fmw/xsd/nam/v1"
                   xmlns:ns6="http://www.tmforum.org/mtop/nrb/xsd/lp/v1"
                   xmlns:ns5="http://www.tmforum.org/mtop/nra/xsd/ethoam/v1"
                   xmlns:ns8="http://www.tmforum.org/mtop/rp/xsd/rucon/v1"
                   xmlns:ns7="http://www.tmforum.org/mtop/fmw/xsd/msg/v1"
                   xmlns:ns13="http://www.tmforum.org/mtop/nrb/xsd/cri/v1"
                   xmlns:ns9="http://www.tmforum.org/mtop/rp/xsd/ep/v1"
                   xmlns:ns12="http://www.tmforum.org/mtop/fmw/xsd/coi/v1"
                   xmlns:ns11="http://www.tmforum.org/mtop/nrb/xsd/lay/v1"
                   xmlns:ns10="http://www.tmforum.org/mtop/nra/xsd/cmo/v1"
                   xmlns:ns17="http://www.tmforum.org/mtop/nrf/xsd/ctp/v1"
                   xmlns:ns16="http://www.tmforum.org/mtop/nrf/xsd/tpdata/v1"
                   xmlns:ns15="http://www.tmforum.org/mtop/nrf/xsd/ptp/v1"
                   xmlns:ns14="http://www.tmforum.org/mtop/nrf/xsd/eq/v1"
                   xmlns:ns19="http://www.tmforum.org/mtop/nrf/xsd/eh/v1"
                   xmlns:ns18="http://www.tmforum.org/mtop/nrf/xsd/ru/v1"
                   xmlns:ns20="http://www.tmforum.org/mtop/nrf/xsd/ftp/v1"
                   xmlns:ns24="http://www.tmforum.org/mtop/nrb/xsd/crmd/v1"
                   xmlns:ns23="http://www.tmforum.org/mtop/nrb/xsd/crcd/v1"
                   xmlns:ns22="http://www.tmforum.org/mtop/fmw/xsd/cocd/v1"
                   xmlns:ns21="http://www.tmforum.org/mtop/fmw/xsd/cosd/v1"
                   xmlns:ns26="http://www.tmforum.org/mtop/nrf/xsd/tp/v1"
                   xmlns:ns25="http://www.tmforum.org/mtop/nrf/xsd/eq-inv/v1"
                   xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/">OnLine</ns2:value>
14:31:37,380 INFO  [SoapUIProTestCaseRunner] Assertion [AppendResponseToFile] has status PASS
14:31:37,380 ERROR [SoapUIProTestCaseRunner] actual_run_state failed, exporting to [/var/lib/jenkins/workspace/Testautomatisierung EMS Access/RC191_Use_Case-Copy_of_ONTVerfügbarkeit_prüfen-actual_run_state-0-FAIL.txt]
14:31:37,387 INFO  [SoapUIProTestCaseRunner] Finished running TestCase [Copy of ONT-Verfügbarkeit prüfen], time taken: 1174ms, status: FAIL
14:31:37,392 INFO  [SoapUIProTestCaseRunner] Project [PlausiChecks] finished with status [FAIL] in 1409ms
14:31:37,393 INFO  [license] ReadyAPI 2.3.0 shutting down
Watch a new Video
Top Kudoed Authors