如果我的斷言失敗,我想從響應打印屬性值。樣品錯誤響應:如何在拆卸腳本中打印來自響應的屬性值
<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>
我想打印價值「的服務標註失敗」如果我的斷言失敗。
目前我的腳本是打印斷言狀態和測試用例名稱。我想打印來自響應的特定屬性值。我的拆解腳本:
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();
你能在這裏使用提供給你的其他問題的代碼片段嗎? – Rao
@Rao,我有一個TestSuite,裏面有60-70個TestSteps。我之前的問題中的代碼片段用於每個TestStep中的腳本斷言。但是這個代碼片段,我用在TestSuite的拆卸腳本中。所以我想要一個可以在tearDown腳本中使用的腳本,它可以從所有TestSteps中提取數據,並可以相應地在Excel中寫入該屬性值。 – Abhishek
好的。但是,所有的測試步驟是否得到相同類型的響應(遵循相同的模式)? – Rao