1

我有一个包含两个断言的测试步骤。

  • 不是 SOAP 错误
  • 包含。条件是响应应该包含“消息发送成功”

现在我有一个 groovy 脚本,我正在执行这个测试步骤。使用这个 groovy 脚本,我需要打印断言名称、值和状态。下面是我写的代码:

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

如您所见,我能够打印断言名称和状态,但不能打印“包含”断言的值。请帮助我如何获得特定断言的价值。

提前致谢。

4

2 回答 2

1

所以这里有一些东西供你阅读

和我试过的

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
于 2013-09-04T18:14:48.123 回答
0

Abhishek's response did contain you answer I believe but just not in the format you were looking for.

I was looking for the same info for custom reporting and after digging through The SoapUI forms I stumbled upon this.

The piece of code that I believe you are looking for is:

log.info e.getToken()

however this is an example of how to retrieve it only when an error occurs but you can get it in a valid scenario using something similar to:

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

This is a subset of my code but produces the log message:

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

My SoapUI script assertion was checking to see if my response contained the string "success".

Thanks Abhishek for your response!

于 2013-09-20T16:12:54.933 回答