cancel
Showing results for 
Search instead for 
Did you mean: 

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

Highlighted
New Contributor

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
5 REPLIES 5
Highlighted
Moderator

Hi @VeryDogeWow,

 

Thanks for reaching out!

 

Community, any ideas on why the assertion fails?

 

Thanks in advance for looking into this!


Olga Terentieva
SmartBear Assistant Community Manager

Highlighted
New Contributor

Hi Olga,

 

seems to be an unsolvable problem Smiley Very Happy

Anyway, thanks for trying to revive this thread.

 

Kind regards

VeryDogeWow

Highlighted
Moderator

Hi @VeryDogeWow,

 

I have contacted our Support team regarding this. It looks like without values you get in the Response and from the database, it’s difficult to suggest anything. So, they first need to find out whether this is the issue with getting a response or with the Assertion. Can you check what values you get when running testrunner.sh?

The investigation can take long, so, it’s probably worth contacting the support team directly by this link.

 


Olga Terentieva
SmartBear Assistant Community Manager

Highlighted
New Contributor

Hi Olga,

 

the retreived values are visible in the console output. The datasource teststep returns "OnLine|OffLine|Unknown" and the value of the response is "OnLine". However it's not able to correctly extract that value from the response, which is why in the console output you can see "" as value. Ultimately that is the reason the assertion fails. 

 

Thanks for looking into this

VeryDogeWow

Highlighted
Moderator

@VeryDogeWow, the support team said that they need your raw response, so they now encourage you to create a support case to properly organize the investigation Smiley Happy
It would be great if you could share your results here when you have some.

Thanks in advance!

 

 


Olga Terentieva
SmartBear Assistant Community Manager

New Here?
Join us and watch the welcome video:
Announcements
TechCorner Leaderboard
Want a fun and easy way to learn ReadyAPI and show off your skills? Try solving weekly TechCorner challenges and get into the Leaderboard!


Challenge Status

Get a full Raw JMS request

Participate!

Compare an expected JSON value and actual response in Events

Participate!

Fetch value/data from JSON response using Groovy Script

See replies!

Get data from Petstore and add it to Excel sheets

Participate!
Top Kudoed Authors