0
我想在數組列表中查找變量值,但顯示錯誤彈出窗口。使用Groovy腳本斷言數組列表中的變量值
Groovy代碼: -
def testCase = messageExchange.modelItem.testCase;
def Created_BookingID = testCase.testSuite.project.getPropertyValue("Created_BookingID");
log.info Created_BookingID
import groovy.json.JsonSlurper
JsonSlurper jsonSlurper = new JsonSlurper()
String jsonString = context.expand('${ListAllRoomBookings#Response}')
Map convertedJSONMap = jsonSlurper.parseText(jsonString)
def RoomID
//If you have the nodes then fetch the first one only
if(convertedJSONMap."RoomBookings"){
RoomID = convertedJSONMap."RoomBookings"."BookingData"."BookingID"
log.info RoomID
}
//Find the created booking in list.
assert Created_BookingID.containsAll(RoomID)
錯誤: - 方法的無簽名:java.lang.String.containsAll()是適用於參數類型:(java.util.ArrayList中)的值:[[包含(java.lang.CharSequence),contains(java.lang.String),notifyAll()
在窗口中打印值: -
Wed Aug 02 17:17:22 IST 2017:INFO:148277
Wed Aug 02 17:17:22 IST 2017:INFO:[148281, 148282, 148277]
現在錯誤顯示: - 斷言Created_BookingID在RoomID | | | 148277 | [148281,148282,148277] false – rAJ
你確定RoomID也包含字符串值(與Created_BookingID相同)?檢查'RoomID'元素的數據類型 - 調用這個:'log.info(RoomID [0] .getClass()。toString())''。在斷言前將'Created_BookingID'的數據類型轉換爲'RoomID'類型。 – daggett
謝謝。 'Created_BookingID'位於String中,'RoomID'位於Integer中。 – rAJ