Groovy 如何将所有断言失败消息打印到SoapUI的HTML报告中
我正在使用groovy运行测试用例和断言数据。我想将每一条失败的消息打印到Groovy 如何将所有断言失败消息打印到SoapUI的HTML报告中,groovy,soapui,Groovy,Soapui,我正在使用groovy运行测试用例和断言数据。我想将每一条失败的消息打印到html junit generate report 示例代码 import groovy.json.JsonSlurper def ResponseMessage = messageExchange.response.responseContent def jsonString = new JsonSlurper().parseText(ResponseMessage) assert
html junit generate report
示例代码
import groovy.json.JsonSlurper
def ResponseMessage = messageExchange.response.responseContent
def jsonString = new JsonSlurper().parseText(ResponseMessage)
assert !(jsonString.isEmpty())
assert jsonString.code == 200
assert jsonString.status == "success"
def accountInfo = jsonString.data
assert !(accountInfo.isEmpty())
def inc=0
//CHECKING LANGUAGES IN RESPONSE
if(accountInfo.languages.id!=null)
{
log.info("Language added successfully")
}
else
{
log.info("Language NOT added.") //want to display this in html report
inc++
}
if(accountInfo.educations!=null)
{
log.info("Educations added successfully")
}
else
{
log.info("Educations NOT added.") //want to display this in html report
inc++
}
assert inc<=0,"API unable to return all parameters, Please check logs"
import groovy.json.JsonSlurper
def ResponseMessage=messageExchange.response.responseContent
def jsonString=new JsonSlurper().parseText(ResponseMessage)
断言!(jsonString.isEmpty())
断言jsonString.code==200
assert jsonString.status==“成功”
def accountInfo=jsonString.data
断言!(accountInfo.isEmpty())
def inc=0
//在响应中检查语言
if(accountInfo.languages.id!=null)
{
log.info(“语言添加成功”)
}
其他的
{
log.info(“未添加语言”)//要在html报告中显示此信息吗
公司++
}
if(accountInfo.educations!=null)
{
log.info(“成功添加教育”)
}
其他的
{
log.info(“未添加教育内容”)//要在html报告中显示此内容吗
公司++
}
断言印加0
报告
在junit样式的html生成的报告中,如果测试失败,它只显示一条名为API的消息,无法返回所有参数,请检查日志
但我想要的是将每个IF条件消息显示到HTML报告中,如果任何条件进入ELSE部分。两个指针:
- 断言在第一次失败时停止,只有此失败消息是junit报告的一部分
- 话虽如此,用户将不知道当前响应是否存在任何进一步的验证失败
- 属于
if..else
的消息不属于junit报告
- 为了实现这一点,需要收集所有这些消息,并最终显示收集的错误消息
- 下面的解决方案使用一个变量,
messages
,并附加每个故障,以便在末尾显示它们。通过这种方式,如果OP需要,所有故障都可以显示在报告中
- 除了
assert
语句之外,用户还可以使用下面的语句显示报告中的消息
if(messages)抛出新错误(messages.toString())
脚本断言
import groovy.json.JsonSlurper
//check if the response is empty
assert context.response, 'Response is empty or null'
def jsonString = new JsonSlurper().parseText(context.response)
def messages = new StringBuffer()
jsonString.code == 200 ?: messages.append("Code does not match: actual[${jsonString.code}], expected[200]\n")
jsonString.status == "success" ?: messages.append("Status does not match: actual[${jsonString.status}], expected[success]\n")
def accountInfo = jsonString.data
accountInfo ?: messages.append('AccountInfo is empty or null\n')
def inc=0
//CHECKING LANGUAGES IN RESPONSE
if(accountInfo.languages.id) {
log.info('Language added successfully')
} else {
log.error('Language NOT added.') //want to display this in html report
messages.append('Language not added.\n')
inc++
}
if(accountInfo.educations) {
log.info('Educations added successfully')
} else {
log.error('Educations NOT added.') //want to display this in html report
messages.append('Educations NOT added.\n')
inc++
}
//inc<=0 ?: messages.append('API unable to return all parameters, Please check logs.')
//if(messages.toString()) throw new Error(messages.toString())
assert inc<=0, messages.append('API unable to return all parameters, Please check logs.').toString()
import groovy.json.JsonSlurper
//检查响应是否为空
断言context.response,“响应为空或null”
def jsonString=new JsonSlurper().parseText(context.response)
def messages=new StringBuffer()
jsonString.code==200?:messages.append(“代码不匹配:实际[${jsonString.code}],应为[200]\n”)
jsonString.status==“成功”?:messages.append(“状态不匹配:实际[${jsonString.status}],应为[success]\n”)
def accountInfo=jsonString.data
accountInfo?:messages.append('accountInfo为空或null\n')
def inc=0
//在响应中检查语言
if(accountInfo.languages.id){
log.info('已成功添加语言')
}否则{
log.error('未添加语言')//要在html报告中显示此信息吗
messages.append('未添加语言。\n')
公司++
}
if(会计信息教育){
log.info('已成功添加教育')
}否则{
log.error('Educations NOT added')//要在html报告中显示此信息吗
messages.append('未添加教育。\n')
公司++
}
//你给出的解决方案对我来说很好。只有一个问题,就是即使断言失败,我的测试用例也不会失败。直到一切正常为止。但当我看到JUnitHTML报告时。它显示状态=通过。我想要的是,当断言失败时,报告应该失败,并在报告中打印所有断言消息,以查看哪个失败了。您使用了它吗?它是否显示了您想要的所有信息?您尝试过使用SoapUI本身吗?只是在答案中将if(messages)
更改为if(messages.toString())
。你能试试这个更新的答案吗?