我对两个不同数组的“ containsAll”有疑问。
我尝试了“断言nameDB.containsAll(nameUI)”,但即使这样也不起作用。我的代码看起来像这样
List<WebElements> elements = DriverFactory.getWebDriver().findElements(By.xpath("//div[@class='sc-bdVaJa sc-gZMcBi koDwGg']"))
List<WebElements> ibans = DriverFactory.getWebDriver().findElements(By.xpath("//div[@class='sc-bdVaJa sc-bwzfXH cUWysv']"))
def nameUI = []
def ibanArray = []
def nameDB = []
//Get and print from UI
for(int i = 0; i < elements.size(); i++) {
def text = elements.get(i).getText()
nameUI << text
}
for (int j = 0; j < ibans.size(); j++){
def ibantxt = ibans.get(j).getText()
ibanArray << ibantxt
//Get account names from DB and print
Database_Cards model = AccountDataService.countCards(ibanArray[j])
def count = model.countCards
println count
nameDB << count
}
println "Iban List:" + ibanArray
println "Count DB: " + nameDB
println "Count UI: " + nameUI
if(nameDB.size() == nameUI.size()){
KeywordUtil.logInfo("Array size - OK")
}
else {
KeywordUtil.logInfo("Array size - Error")
}
if (nameUI.containsAll(nameDB)) {
println nameDB + "=" + nameUI
KeywordUtil.logInfo("It's OK - UI Objects are Same DB")
}
else {
println nameDB + "!=" + nameUI
KeywordUtil.logInfo("UI Objects are NOT Same DB")
}
assert nameDB.containsAll(nameUI)
KeywordUtil.logInfo("It's OK - Accounts are displayed Correctly")
输出:
Count DB: [1]
2019-07-31 10:15:12.688 DEBUG testcase.123 - 17: println("Count UI: " + nameUI)
Count UI: [1]
2019-07-31 10:15:12.688 DEBUG testcase.123 - 18: if (nameDB.size() == nameUI.size())
2019-07-31 10:15:12.688 DEBUG testcase.123 - 1: logInfo("Array size - OK")
2019-07-31 10:15:12.688 INFO com.kms.katalon.core.util.KeywordUtil - Array size - OK
2019-07-31 10:15:12.688 DEBUG testcase.123 - 20: if (nameUI.containsAll(nameDB))
2019-07-31 10:15:12.688 DEBUG testcase.123 - 21: else
2019-07-31 10:15:12.688 DEBUG testcase.123 - 1: println(nameDB + "!=" + nameUI)
[1, !=, 1]
2019-07-31 10:15:12.697 DEBUG testcase.123 - 2: logInfo("UI Objects are NOT Same DB")
2019-07-31 10:15:12.697 INFO com.kms.katalon.core.util.KeywordUtil - UI Objects are NOT Same DB
2019-07-31 10:15:12.697 DEBUG testcase.123 - 22: assert nameDB.containsAll(nameUI)
2019-07-31 10:15:12.697 ERROR c.k.katalon.core.main.TestCaseExecutor - ❌ Test Cases/123 FAILED.
Reason:
Assertion failed:
assert nameDB.containsAll(nameUI)
| | |
[1] false [1]
答案 0 :(得分:2)
问题出在数据类型上:
nameUI << text
,因此nameUI
以“ 1”作为字符串。
nameDB << count
,因此nameDB
的计数为1(整数)。
更新:
您可以尝试以下修复(将“计数”转换为字符串):
nameDB << count.toString()