如何在拆解脚本中打印 Response 的属性值
How to print atribute value from Response in teardown script
如果断言失败,我想打印响应中的属性值。示例错误响应:
<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>
如果断言失败,我想打印值 "Service Callout Failure"。
目前我的脚本正在打印断言状态和测试用例名称。我想从响应中打印特定的属性值。我的拆解脚本:
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();
我正在使用 context.expand 从对 groovy 的响应中获取数据,
例如
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]}' )
除了命名空间,在 SearchHotels#Response... SearchHotels 是测试步骤的名称,您可以使用正确的路径获取响应消息到 ns0:Message 然后打印它而不是常量数据...
我使用了以下语句:
def req = it.name; message[k] = context.expand('${'+req+'#Response#declare namespace ns0=\'http://group.vodafone.com/contract/vfo/fault/v1\'; //ns0:Message}')
成功了。
如果断言失败,我想打印响应中的属性值。示例错误响应:
<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>
如果断言失败,我想打印值 "Service Callout Failure"。
目前我的脚本正在打印断言状态和测试用例名称。我想从响应中打印特定的属性值。我的拆解脚本:
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();
我正在使用 context.expand 从对 groovy 的响应中获取数据, 例如
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]}' )
除了命名空间,在 SearchHotels#Response... SearchHotels 是测试步骤的名称,您可以使用正确的路径获取响应消息到 ns0:Message 然后打印它而不是常量数据...
我使用了以下语句:
def req = it.name; message[k] = context.expand('${'+req+'#Response#declare namespace ns0=\'http://group.vodafone.com/contract/vfo/fault/v1\'; //ns0:Message}')
成功了。