如何使用Groovy脚本来获取断言值

问题描述 投票:1回答:2

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

  • 不是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

正如你所看到的,我可以断言打印的姓名和身份,但没有价值“包含”断言。请帮我如何获得一个特定断言的价值。

提前致谢。

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

0
投票

阿布舍克的反应都包含你回答我相信,但只是没有你要找的格式。

我一直在寻找的自定义报表,并通过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脚本断言是检查,看看我的反应将包含字符串“成功”。

阿布舍克感谢您的答复!

© www.soinside.com 2019 - 2024. All rights reserved.