Forum Discussion

vd484's avatar
vd484
Occasional Contributor
15 years ago

Script assertion - need help

Hello

I need some help with script assertion.

I am using a script assertion in a Test Response step and i have the below code:

def groovyUtils = new com.eviware.soapui.support.GroovyUtils(context)
def requestHolder = groovyUtils.getXmlHolder(messageExchange.requestContent)
def responseHolder = groovyUtils.getXmlHolder(messageExchange.responseContent)

////Data_Variables
A = "1A"
B = "1B"

for( i in ["1", "2"]){
log.info(i)
//set response variables according to product

A_Actual = responseHolder.getNodeValue(("//ns1:ABCD[1]/ns2:ABCD[1]/ns2:ABCD[1]/ns2:ABCD[1]/ns2:ABCD[1]/ns2:ABCD[1]/ns2:ABCD[1]/ns2:ABCD[XYZ]/@A").replaceAll("XYZ", i))
B_Actual = responseHolder.getNodeValue(("//ns2:ABCD[1]/ns2:ABCD[1]/ns2:ABCD[1]/ns2:ABCD[1]/ns2:ABCD[1]/ns2:ABCD[1]/ns2:ABCD[1]/ns2:ABCD[XYZ]/@B").replaceAll("XYZ", i))


assert A = A_Actual
assert B = B_Actual
}

if Assert A = A_Actual fails and Assert B = B_Actual also fails ..it only reports A failed in the request/response Output result file and does not show information that B failed.

Can you please let me know what i have to do to get all failed statements show up in the request response file.

2) question 2 - is there a way to send a string into the request/response output result file from a script assertion - using groovy code.

Appreciate your help.

Thanks
vd484

4 Replies

  • M_McDonald's avatar
    M_McDonald
    Super Contributor
    OK. For this example create 2 script assertions (see screenshot attached.)

    In the first assertion put code like this (I have simplified the code to verify, change your xmlHolder as appropriate for your use.)

    def groovyUtils = new com.eviware.soapui.support.GroovyUtils(context)
    def responseHolder = groovyUtils.getXmlHolder("<result><a>1A</a><b>1B</b></result>")

    context.put("responseHolder", responseHolder) // save in context for later use

    def A = "1A"
    def A_Actual = responseHolder.getNodeValue("//a")
    assert A == A_Actual


    In the second assertion, put this:

    def responseHolder = context.get("responseHolder") // get holder from context

    def B = "1B"
    def B_Actual = responseHolder.getNodeValue("//b")
    assert B == B_Actual


    This way the assertions are separated and will all execute regardless of the results of the previous ones.
  • Hi!

    1) the assert statement throws an exception if it fails, thus the second assert will never be reached if the first fails. Maybe you can merge them into just one assert?

    2) hmm.. can you be more specific on exactly where you want to write the string?

    regards!

    /Ole
    eviware.com
  • M_McDonald's avatar
    M_McDonald
    Super Contributor
    1) How about 2 assertions, one for A and one for B? If you only want to create the holder once, you can do it in the first assertion and put it into the context and retrieve it from there in the second assertion.
  • Usha_Kodali's avatar
    Usha_Kodali
    Frequent Contributor
    McDonald,
    Can you give an example how to achieve what you explained?
    I have numerous assertions in my script. When one assertion fails rest of the exceptions never get executed which is not I want.
    I want to have all the assertions to run through and then give me the status of each exception and print error messages.

    How to achieve this?