java


Comparing data between website and Excel data


i am comparing a text box value and the value in excel sheet by using assert() (TestNG)
the problem i am facing is even though the value in excel and website text box is same it is showing error - java.lang.AssertionError: expected [0.02] but found [0.0200]
HTML CODE:
<input id="ctl00_ContentPlaceHolder1_txtBlackCost1" class="textboxnew" type="text"
style="width:50px;text-align: right" onblur="AllowNumber(this,this.value);
CallonBlur(this.value,'spn_Black_1');
Calculate_BlackChargeableRate(this.value,1,'cost');" maxlength="12" value="0.0200"
name="ctl00$ContentPlaceHolder1$txtBlackCost1">
Selenium Code:
public static void CompareStringTextByID(String xlpath,String sheetName,int rownum,int cellnum,String LocationName,String WebelementID)
{
WebElement TxtBoxContent = driver.findElement(By.id(WebelementID));
String Content = TxtBoxContent.getAttribute("value");
String ExcelData = Generic.getXlCellValue(xlpath, sheetName, rownum, cellnum);
Assert.assertEquals(Content, ""+ExcelData);
Reporter.log(LocationName+" Data Verification -- PASS",true);
}

Alter the format in the spreadsheet to match the format from your test. Or the other way around if I have read wrong. They both need to be to 2 decimal places. At least that is what I think it is.

You are comparing strings, not numbers. "0.2" is not the same as "0.200".
Try converting them to Decimals before comparing them.
DecimalFormat df = new DecimalFormat("0.00");
df.setMaximumFractionDigits(2);
String decimal = df.format(someString);
Ideally, create BigDecimal objects and compare those.

If you are going to compare to integer please convert the string to integer before comparing this will help you reduce the confusion
to convert the sting to Double please use
double aDouble = Double.parseDouble("0.02");


Related Links

Java input from text file with an unusual format
Wanting to call data from a other table into a table
How do you retrieve the latest Document from a MongoCollection (MongoDB v3.3)
Validation of setModel()? [Resolved]
Maven Spring Boot Failed to instantiate SLF4J LoggerFactory Reported exception:
Java Embedded Database h2
How to make ZXing shown in part of activity (not full screen) in android?
Customizing entity generation from datasource in IntelliJ IDEA
How to call a jasper report from a Perl script?
com.sun.org.apache.xalan.internal.xsltc.trax.TransformerFactoryImpl in java1.8 vs java1.7
how to play video using java?
Adding Facebook authentication to my Spring MVC application
Scala Maven Plugin not handling Scala source folder and reporting lifecycle error
Using arrays to get positive numbers
Parse https with jsoup (java)
Java interfaces in jar archives

Categories

HOME
log4j
debugging
keras
google-play
homebrew
sqlite-net-extensions
amortized-analysis
binary-tree
disassembler
applepay
elasticsearch-hadoop
gnupg
wheelnav.js
windows-azure-storage
moonmail
quartz-scheduler
serverless-framework
opentracing
pc
fatal-error
finite-automata
nodatime
grails3
cloudhub
lcd
p-value
shopware
bootstrap-duallistbox
bootstrap-material-design
xacml
objectanimator
binary-data
perlin-noise
textmate
form-data
accelerate-framework
wpf-controls
occlusion
jna
document.write
trim
squib
avro4s
fakeiteasy
slick-3.0
multipeer-connectivity
paxos
datastax-startup
diagnostics
np-complete
nsarray
pearson
blacklist
or-tools
pintos
infix-notation
radtreelist
bonobo
fputcsv
testng-dataprovider
sdf
packagist
bluemix-app-scan
dataview
system.management
iad
vhd
browser-bugs
angular-local-storage
web-controls
clipperlib
codeigniter-url
google-style-guide
java-metro-framework
tld
seaside
app42
html5-notifications
mysqltuner
sitemesh
spring-io
odata4j
shellexecute
gwt-rpc
comaddin
spring-validator
jelly
pvrtc
viewswitcher
semantic-diff
assembly-loading
eclipse-templates
window-management
vdsp
disclosure
mysql-error-1005
gamequery
routedevent
rescale
uimenucontroller
privilege





Mobile Apps Dev
Database Users
javascript
java
csharp
php
android
MS Developer
developer works
python
ios
c
html
jquery
RDBMS discuss
Cloud Virtualization