簡體   English   中英

如何使用Groovy腳本獲取斷言值

[英]How to get assertion value using groovy script

我有一個包含兩個斷言的測試步驟。

  • 不是SOAP錯誤
  • 包含。 條件是響應應包含“消息發送成功”

現在,我有一個普通的腳本,可以在其中執行此測試步驟。 使用此常規腳本,我需要打印斷言名稱,值和狀態。 以下是我編寫的代碼:

testStepSrc = testCase.getTestStepByName(testName)
Assertioncounter = testStepSrc.getAssertionList().size()
for (AssertionCount in 0..Assertioncounter-1)
{
log.info("Assertion :" + testStepSrc.getAssertionAt(AssertionCount).getName() + " :: " + testStepSrc.getAssertionAt(AssertionCount).getStatus())

error = testStepSrc.getAssertionAt(AssertionCount).getErrors()
if (error != null)
   {
    log.error(error[0].getMessage())
   }
 }

但在輸出中顯示為:

Wed Sep 04 17:21:11 IST 2013:INFO:Assertion :Not SOAP Fault :: VALID
Wed Sep 04 17:21:11 IST 2013:INFO:Assertion :Contains :: VALID

如您所見,我能夠打印斷言的名稱和狀態,但不能打印“包含”斷言的值。 請幫助我如何獲取特定斷言的值。

提前致謝。

所以這里有一些東西供您閱讀

和我嘗試過的

def assertionsList = testRunner.getTestCase().getTestStepByName("Test Step Name").getAssertionList()
for( e in assertionsList){
    log.info e.getToken() //gives the value of the content to search for
    log.info e.DESCRIPTION
    log.info e.ID
    log.info e.LABEL
    log.info e.toString()
}

這給出了以下輸出

Wed Sep 04 15:12:19 ADT 2013:INFO:Abhishek //the contains assertion was checking for the word "Abhishek" in the response of my test step where the assertion was applied.
Wed Sep 04 15:12:19 ADT 2013:INFO:Searches for the existence of a string token in the property value, supports regular expressions. Applicable to any property. 
Wed Sep 04 15:12:19 ADT 2013:INFO:Simple Contains
Wed Sep 04 15:12:19 ADT 2013:INFO:Contains
Wed Sep 04 15:12:19 ADT 2013:INFO:com.eviware.soapui.impl.wsdl.teststeps.assertions.basic.SimpleContainsAssertion@c4115f0

我相信Abhishek的回答確實包含您的答案,但並非以您想要的格式。

我一直在尋找用於自定義報告的相同信息,並且在深入研究SoapUI表單之后,我偶然發現了這一點。

我相信您正在尋找的代碼段是:

log.info e.getToken()

但是,這是一個僅在發生錯誤時如何檢索它的示例,但您可以在有效的情況下使用類似於以下內容的方法獲取它:

def iAssertionName = assertionNameList[j]
def iAssertionStatus = testStep.getAssertionAt(j).getStatus().toString()
def tstep = testStep.getName()
def gStatus =  testStep.getAssertionAt(j).status
def expect = testStep.getAssertionAt(j).getToken()
log.info "Expected Content: " + expect

這是我的代碼的一個子集,但會生成日志消息:

Fri Sep 20 11:04:09 CDT 2013:INFO:Expected Content: success

我的SoapUI腳本斷言正在檢查我的響應是否包含字符串“成功”。

感謝Abhishek的回復!

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM