我试图在数组列表中找到变量值但显示错误弹出窗口。
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)值:[[148281,148282,148277]]可能的解决方案:contains(java.lang.CharSequence), contains(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]
答案 0 :(得分:1)
assert Created_BookingID.containsAll(RoomID)
没有方法签名:
java.lang.String.containsAll()
适用于参数类型:(java.util.ArrayList) 值:[[148281,148282,148277]]
您尝试在String对象上调用containsAll()
方法。这意味着Created_BookingID
此时可变为String。
如果要检查字符串Created_BookingID
是否在数组RoomID
中
代码将是这样的:
assert Created_BookingID in RoomID