断言运算符从各种变量前后计数
Assert operator to count before and after from various variable
我有代码来获取数据库记录,发送测试数据(下面的代码中没有显示),
并计算 before/after 大小。
我可以做下面的断言来直接使用 printIn 结果进行简单的数学计算吗?
assert responseListAfter.size() == responseListBefore.size + results
这是完整代码
//count the DB records which State = New
String dbQuery = "SELECT COUNT(*) as count FROM dispenseorders.dispenseorder where status = 'true'"
List results = CustomKeywords.'swisslog.database.getSQLResults'(GlobalVariable.dbConnString , GlobalVariable.dbUsername , GlobalVariable.dbPassword ,GlobalVariable.dbDriver ,dbQuery )
println results
//Before Refresh. count number of records in Kafka Topic A
def TopicBefore = 'A'
def NewMessageBefore = consumeMessageBefore(TopicBefore)
def responseListBefore = new JsonSlurper().parseText(consumeMessageBefore.getResponseText())
def consumeMessageBefore(def topic) {
WS.sendRequest(findTestObject('Object Repository/Kafka/subscribe_to_topic_A', [('topic_name') : topic, ('KafkaRestName') : GlobalVariable.KafkaRestName
, ('KafkaRestPort') : GlobalVariable.KafkaRestPort]))
return consumeMessageBefore = WS.sendRequestAndVerify(findTestObject('Object Repository/Kafka/consume_message_from_topic_for_DR',
[('KafkaRestName') : GlobalVariable.KafkaRestName, ('KafkaRestPort') : GlobalVariable.KafkaRestPort]))
}
println('before Request Refresh: \n' + responseListBefore.size)
WebUI.delay(10)
//after Refresh. count number of records in Kafka Topic A
def TopicAfter = 'A'
def NewMessageAfter = consumeMessageAfter(TopicAfter)
def responseListAfter = new JsonSlurper().parseText(consumeMessageAfter.getResponseText())
def consumeMessageAfter(def topic) {
WS.sendRequest(findTestObject('Object Repository/Kafka/subscribe_to_topic_for_DR', [('topic_name') : topic, ('KafkaRestName') : GlobalVariable.KafkaRestName
, ('KafkaRestPort') : GlobalVariable.KafkaRestPort]))
return consumeMessageAfter = WS.sendRequestAndVerify(findTestObject('Object Repository/Kafka/consume_message_from_topic_for_DR',
[('KafkaRestName') : GlobalVariable.KafkaRestName, ('KafkaRestPort') : GlobalVariable.KafkaRestPort]))
}
println('after Request Refresh: \n' + responseListAfter.size)
//check total messages. After Refresh count = Before Refresh count + DB records
assert responseListAfter.size() == responseListBefore.size + results
results
是一个列表,你需要一个列表大小(int)才能将它添加到其他整数:
assert responseListAfter.size() == responseListBefore.size() + results.size()
我有代码来获取数据库记录,发送测试数据(下面的代码中没有显示), 并计算 before/after 大小。
我可以做下面的断言来直接使用 printIn 结果进行简单的数学计算吗?
assert responseListAfter.size() == responseListBefore.size + results
这是完整代码
//count the DB records which State = New
String dbQuery = "SELECT COUNT(*) as count FROM dispenseorders.dispenseorder where status = 'true'"
List results = CustomKeywords.'swisslog.database.getSQLResults'(GlobalVariable.dbConnString , GlobalVariable.dbUsername , GlobalVariable.dbPassword ,GlobalVariable.dbDriver ,dbQuery )
println results
//Before Refresh. count number of records in Kafka Topic A
def TopicBefore = 'A'
def NewMessageBefore = consumeMessageBefore(TopicBefore)
def responseListBefore = new JsonSlurper().parseText(consumeMessageBefore.getResponseText())
def consumeMessageBefore(def topic) {
WS.sendRequest(findTestObject('Object Repository/Kafka/subscribe_to_topic_A', [('topic_name') : topic, ('KafkaRestName') : GlobalVariable.KafkaRestName
, ('KafkaRestPort') : GlobalVariable.KafkaRestPort]))
return consumeMessageBefore = WS.sendRequestAndVerify(findTestObject('Object Repository/Kafka/consume_message_from_topic_for_DR',
[('KafkaRestName') : GlobalVariable.KafkaRestName, ('KafkaRestPort') : GlobalVariable.KafkaRestPort]))
}
println('before Request Refresh: \n' + responseListBefore.size)
WebUI.delay(10)
//after Refresh. count number of records in Kafka Topic A
def TopicAfter = 'A'
def NewMessageAfter = consumeMessageAfter(TopicAfter)
def responseListAfter = new JsonSlurper().parseText(consumeMessageAfter.getResponseText())
def consumeMessageAfter(def topic) {
WS.sendRequest(findTestObject('Object Repository/Kafka/subscribe_to_topic_for_DR', [('topic_name') : topic, ('KafkaRestName') : GlobalVariable.KafkaRestName
, ('KafkaRestPort') : GlobalVariable.KafkaRestPort]))
return consumeMessageAfter = WS.sendRequestAndVerify(findTestObject('Object Repository/Kafka/consume_message_from_topic_for_DR',
[('KafkaRestName') : GlobalVariable.KafkaRestName, ('KafkaRestPort') : GlobalVariable.KafkaRestPort]))
}
println('after Request Refresh: \n' + responseListAfter.size)
//check total messages. After Refresh count = Before Refresh count + DB records
assert responseListAfter.size() == responseListBefore.size + results
results
是一个列表,你需要一个列表大小(int)才能将它添加到其他整数:
assert responseListAfter.size() == responseListBefore.size() + results.size()