我有一个测试步骤,其中包含两个断言。
现在我有一个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
如您所见,我能够打印断言名称和状态,但不能打印'Contains'断言的值。请帮助我如何获得特定断言的价值。
提前致谢。
答案 0 :(得分: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
答案 1 :(得分:0)
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脚本断言正在检查我的响应是否包含字符串“success”。
感谢Abhishek的回复!