#java #selenium #if-statement #selenium-webdriver
#java #селен #if-statement #selenium-webdriver
Вопрос:
У меня есть значение, которое в операторе if содержит equals, но все равно оно не проходит тест. пожалуйста, помогите найти проблему в скрипте.
Мне нужно if (383797)contains ($ 383,797)
Тест должен пройти
// Database query to get value
ResultSet rs = stmt.executeQuery(query);
while (rs.next()){
String mytotal = rs.getString(2);
System.out.println(mytotal);
BigDecimal result = new BigDecimal(mytotal);
System.out.println(result " convert valueOf to int");
// round of to million
System.out.println(result.divide(new BigDecimal("1000000")).setScale(0, RoundingMode.FLOOR) " Result 3");
// Database data value
String aarwavalue = (result.divide(new BigDecimal("1000000")).setScale(0, RoundingMode.FLOOR) "");
System.out.println(aarwavalue);
driver.switchTo().frame("mstrFrame");
//Extract dynamic id for aarawtotal
WebElement extractxpathid = driver.findElement(By.xpath("//span[text()='AA RWA']"));
System.out.println(extractxpathid.getAttribute("id"));
String pathnum = extractxpathid.getAttribute("id");
String[] xpathid = pathnum.split("-");
System.out.println(xpathid[0]);
System.out.println(xpathid[1]);
System.out.println(xpathid[2]);
// UI data
String aarwatotal = driver.findElement(By.xpath("(//td[@class='x-grid-cell x-grid-td x-grid-cell-headerId-gridcolumn-" xpathid[1] " x-unselectable'])[last()]//div")).getText();
System.out.println(aarwatotal);
//assert UI value to database value
if(aarwatotal.contains(aarwavalue))
{
Reporter.log("Successfully Database value equal UI value " aarwatotal);
Add_Log.info("Successfully Database value equal UI value " aarwatotal);
}
else
{
Reporter.log(" Database value not equal UI value " aarwatotal "and" aarwavalue);
Add_Log.info("Database value not equal UI value " aarwatotal "and" aarwavalue);
// Assert.fail();
}
if(aarwavalue.equalsIgnoreCase(aarwatotal))
{
Reporter.log("Successfully Database value equal UI value " aarwatotal);
Add_Log.info("Successfully Database value equal UI value " aarwatotal);
}
else
{
Reporter.log(" Database value not equal UI value " aarwatotal "and" aarwavalue);
Add_Log.info("Database value not equal UI value " aarwatotal "and" aarwavalue);
//Assert.fail();
}
}
ВЫВОД
383797521414.9034250
383797521414.9034250 convert valueOf to int
383797 Result 3
383797
gridcolumn-1020-textEl
gridcolumn
1020
textEl
$ 383,797
Database value not equal UI value $ 383,797 and 383797
Database value not equal UI value $ 383,797 and 383797
Ответ №1:
Возвращается сравнение значений false
, поэтому оно не проходит тест. Проблема с запятой ,
Вы можете манипулировать String
aarwatotal
, чтобы удалить запятую следующим образом:
String aarwatotal = driver.findElement(By.xpath("(//td[@class='x-grid-cell x-grid-td x-grid-cell-headerId-gridcolumn-" xpathid[1] " x-unselectable'])[last()]//div")).getText();
//in the line below we replace the comma with empty String
aarwatotal = aarwatotal.replaceAll(",", "");
После этого aarwatotal
будет равно: $ 383797
и теперь вы можете проверить, правильно ли он содержит 383797
Остальная часть кода может оставаться неизменной.