i have a problem with "containsAll" of two different arrays.
i tried "assert nameDB.containsAll(nameUI)", but doesn't work even this. my code looks like this
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")
Output:
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]
The problem is in data types:
nameUI << text
so nameUI
has "1" as string.
nameDB << count
so nameDB
has 1 as count (integer).
UPDATE:
You can try the following fix (convert "count" to string):
nameDB << count.toString()