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

Mockito verify argument contains another string ignoring case
Can anyone tell me what components they are in this picture, so I can google it?
How it is decided which catch block comes first?
Maven dependency on original Spring Boot JAR [duplicate]
Java local variable notation: 'textEntered' or 'enteredText'? [closed]
How SLF4J/ JPA / JAX-RS find their implementation?
Java - Creating multiple objects and making them distinguishable
Hibernate starts altering on tables which didn't created
Giving priority to some processes, without starvation for the others [closed]
JaCoCo coverage report not displayed in Sonarqube 5.3
How to change user in hdfs using sparkSubmit in java
What is the difference between Files.walk.filter and Files.find?
Java: Filtering Panels like a JTable
Auto Extracting XPATH of all html elements using JAVA
How to convert em dash in java
Is Java's import keyword for source files or binary files?

Categories

HOME
sendgrid
xamarin
cloud
hook
azure-data-factory
relative-path
grep
bookshelf.js
gis
setup-deployment
yahoo-oauth
razor
amortized-analysis
electronics
alpha
fancybox
mouse
add
volttron
midi
spring-xd
izpack
numeral.js
percona
quartz-scheduler
jsdoc
footer
apache-metamodel
flux
code-review
dbext
jasonette
ehcache
sylius
hammerspoon
trading
shopware
selectedindexchanged
fopen
ping
ejabberd-module
gitignore
quote
google-cloud-endpoints-v2
language-concepts
jmonkeyengine
swisscomdev
webdriver-manager
email-templates
pubmed
multipeer-connectivity
theming
idisposable
git-diff
namecoin
imanage
synchronous
messenger
parallel-data-warehouse
httplistener
ado.net-entity-data-model
underscore.js-templating
pcf
qpid
skype4py
master-slave
bluemix-app-scan
two-factor-authentication
spidermonkey
libressl
responsive-images
apache-commons-fileupload
processmodel
clipperlib
rake-task
codeigniter-url
applescript-objc
responsive-slides
mechanize-ruby
datagridviewcolumn
meteor-velocity
tws
mylyn
chronoforms
ember-app-kit
flashvars
specification-pattern
spring-portlet-mvc
work-stealing
subscript
pydot
xtype
yui-datatable
jmock
w3wp.exe
data-driven
ctp4
ugc

Resources

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