我是groovy脚本和soap UI的新手。我将脚本断言添加到测试步骤。但是,当我运行测试用例时,脚本断言没有运行。我必须手动运行它来验证我的回答是否正确。有人可以帮我吗?我的groovy脚本测试断言:
import groovy.json.JsonSlurper
//grab response
def response = messageExchange.response.responseContent
//Convert to JsonSluper to access data
def list = new JsonSlurper().parseText(response)
//check delegates are in one session per timeslot
for (i = 0; i < list.size(); i++) {
// find all items for this delegate in this timeslot
def itemsForThisDelegateInThisTimeslot = list.findAll {element -> element.delegateId == list[i].delegateId && element.agendaItemId== list[i].agendaItemId}
log.info(list[i].delegateId)
// there should not be more than 1
if(itemsForThisDelegateInThisTimeslot.size() > 1) {
log.info(list[i].delegateId + "Delegate already assigned to a workshop at same time");
//Assert fail in execution
throw new Error ('Fail')
}
}
首先,此脚本断言中没有断言。查看Groovy断言。
如果你“声称”脚本是通过或失败,你需要......
assert (response.contains('Something from the response'));
要么
assert (someBooleanVar == true);
如果通过,则步骤变为绿色。如果失败,它会变成红色。
恕我直言,它看起来你在步骤失败时抛出异常。我不会以这种方式使用异常。捕获和报告代码问题是一个例外。不是测试失败。
关于异常,请查看Groovy Try和Catch。
至于运行(或不运行)测试用例时的运行。我怀疑它正在运行,但由于你没有断言任何东西,你无法看到结果。
有没有注意到屏幕底部的脚本日志选项卡?测试步骤运行时,所有log.info语句都将在此处。我建议清除此日志(在“脚本日志”窗口中右键单击...),然后再次运行测试用例,并在脚本日志中查看一些日志消息。