如何在拆解脚本中从Response打印属性值

时间:2017-08-16 15:50:49

标签: soap groovy soapui

如果断言失败,我想从响应中打印属性值。示例错误响应:

<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>

我想打印价值&#34;服务标注失败&#34;如果我的断言失败了。

目前我的脚本正在打印断言状态和测试用例名称。我想从响应中打印特定的属性值。我的拆解脚本:

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();

2 个答案:

答案 0 :(得分:1)

我正在使用 context.expand 从响应中获取数据到groovy, 例如

&#13;
&#13;
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]}' )
&#13;
&#13;
&#13;

除了名称空间,在 SearchHotels #Response ... SearchHotels是测试步骤的名称,您可以使用正确的ns0路径获取响应消息:消息然后打印它而不是常数......

答案 1 :(得分:0)

我使用了以下声明:

MyVar

并且有效。