Abhishek
Abhishek

Reputation: 698

How to print atribute value from Response in teardown script

I want to print attribute value from response if my assertion fails. Sample error Response:

<soapenv:Body>
  <ns0:Fault xmlns:ns1="http://www.w3.org/2003/05/soap-envelope" xmlns:ns0="http://schemas.xmlsoap.org/soap/envelope/">
     <faultcode>OSB-382500</faultcode>
     <faultstring>Mandatory Parameter Customer Type cannot be empty (uuid: 1f8b9637-11b1-47ea-9ebd-3abf2fda950e)</faultstring>
     <detail>
        <ns0:Fault xmlns:ns0="http://group.vodafone.com/contract/vfo/fault/v1" xmlns:ns2="http://group.vodafone.com/contract/vho/header/v1" xmlns:ns3="http://group.vodafone.com/schema/common/v1" xmlns:ns6="http://docs.oasis-open.org/wsrf/bf-2" xmlns:ns7="http://www.w3.org/2005/08/addressing">
           <ns6:Timestamp>2017-08-16T20:44:27.15+05:30</ns6:Timestamp>
           <ns6:ErrorCode>500</ns6:ErrorCode>
           <ns0:Name/>
           <ns0:Severity>Critical</ns0:Severity>
           <ns0:Category>Technical</ns0:Category>
           <ns0:ReasonCode>ReasonCode</ns0:ReasonCode>
           <ns0:Message>Service Callout Failure</ns0:Message>
        </ns0:Fault>
     </detail>
  </ns0:Fault>
</soapenv:Body>

I want to print value "Service Callout Failure" if my assertion fails.

Currently my script is printing assertion status and testcase name. I want to print the particular attribute value from response. My Teardown Script:

import com.eviware.soapui.model.testsuite.Assertable.AssertionStatus
import jxl.*;
import jxl.write.*;

def TestCase = testRunner.getTestCase()
def StepList = TestCase.getTestStepList()
def status
def i = 0

WritableWorkbook workbook1 = Workbook.createWorkbook(new File("C:\\report1.xls"));
WritableSheet sheet1 = workbook1.createSheet("Report Worksheet", 0);

StepList.each{
    if(it.metaClass.hasProperty(it,'assertionStatus')){
        if(it.assertionStatus == AssertionStatus.FAILED){
            log.info "${it.name} FAIL..."
            status = "FAIL"; 
        }else if(it.assertionStatus == AssertionStatus.VALID){
            log.info "${it.name} OK!"
            status = "Passed";
        }else if(it.assertionStatus == AssertionStatus.UNKNOWN){
            log.info "${it.name} UNKNOWN (PROBABLY NOT EXECUTED)"
            status = "UNKNOWN";
        }
    }
    Label label1 = new Label(i, sheet1.rows, it.name);
    Label label2 = new Label(i+1, sheet1.rows, status);
    sheet1.addCell(label1); 
    sheet1.addCell(label2);
}
workbook1.write();
workbook1.close();

Upvotes: 0

Views: 291

Answers (2)

Abhishek
Abhishek

Reputation: 698

I used the below statement:

def req = it.name; message[k] = context.expand('${'+req+'#Response#declare namespace ns0=\'http://group.vodafone.com/contract/vfo/fault/v1\'; //ns0:Message}')

and it worked.

Upvotes: 0

Michael Babich
Michael Babich

Reputation: 142

I am using context.expand to get data from response to groovy, for example

def hotel = context.expand( '${SearchHotels#Response#declare namespace ns1=\'someNamespace\'; declare namespace ns2=\'someNamespace2\'; //ns2:SearchHotelsResponse[1]/ns2:SearchHotelsResult[1]/ns1:TWS_HotelList[1]/ns1:Hotel[1]}' )

Namespace aside, at SearchHotels#Response... SearchHotels is name of test step, you can get response message using correct path to ns0:Message and then print it instead of constant data...

Upvotes: 1

Related Questions