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

Out of memory while processing large number of objects in HashMap/Hashtable/ArrayList
how do you increase panel width?
Batch insert to the binary tree in java
android.database.sqlite.SQLiteDiskIOException
Java Newbie : Are the two ways of function definition identical
how to resolve ExpatParser$parseException
extract SOAP Message into a string in a way other that SOAPMessageContext.getMessage();
Why do I have to add a JSeparator twice?
Create a Logoff button to clear down all bean data and redirect to login - Java
Seam 2.2 conditional injection
Bean validation not working. I'm using JPA 2.0 and Hibernate 3.3
Using Parcelable model classes outside Android, with a Parcelable wrapper
Java Hangman - replacing underscore with character [duplicate]
Is WindowBuilder Pro already installed in Eclipse?
read a webpage programmatically and extract some information
Which is faster for filtring a set of data, a select query or a loop?

Categories

HOME
server
hashmap
grep
react-router
infragistics
sharepoint-designer
survey
gps
sql-server-2016
installshield
angular-ui-bootstrap
windows-server
primary-key
numeral.js
phaser
messages
lombok
graphlab
aurigma
text-rendering
samoa
functional-testing
chromium-embedded
opennlp
internet-explorer-9
virtualdub
replaceall
primitive
microsoft-chart-controls
stormpath
binary-data
bosh
ghost4j
http-referer
google-api-nodejs-client
android-ble
restlet
sharefile
webix-treetable
impersonation
temporary-files
lumberjack
ensembles
powershell-dsc
nand2tetris
spring-security-kerberos
fakeiteasy
acoustics
jsch
avconv
taffy
filepicker
elgg
drupal-6
magma
mediaelement
eventkit
google-cdn
ableton-live
savon
fody
thrust
nsfilemanager
moveit
hexdump
bluegiga
two-factor-authentication
associative-array
freedesktop.org
collapse
mutation-observers
sysinternals
sailfish-os
operation
remobjects
device-orientation
fscommand
sorl-thumbnail
block-device
android-imagebutton
terminfo
jubula
wp-query
poller
xsockets.net
lcs
smtp-auth
cassini-dev
hamiltonian-cycle
enter
hgsubversion
deobfuscation
self-extracting
mysql-error-1005
virtual-functions
mediarss

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