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

android Rect.intersect is always false
Correct Place to put .p12 File in a Java Web Application?
StringIndex OutOf Bounds Exception
How to set permissions to facebook properly with socialauth library?
HTTPS security impact on first request for Java client
How to log GC output to specific file including the PID in the filename?
java servlet not found error 404 in eclipse [duplicate]
Regular Expression for name
Attempt to call a method but I get a NullPointerException
setDisplayHomeAsUpEnabled not displaying back arrow with custom actionbar view
Jfugue: Improper MusicXML Format
Defining alias for Servlet context
Getting checked exception while automating a web application in Firefox using selenium webdriver
How to deploy glass-java-starter
web app on machine (on local computer works correctly)
Is it possible to sort an arraylist/hashset without the use of a comparator interface?

Categories

HOME
minimum-spanning-tree
mfc
tinymce
relative-path
iterator
electron
octobercms
jgroups
jpeg
icloud
cross-browser
ebean
pivotal-cloud-foundry
slurm
dacpac
metatrader4
ssl-client-authentication
user-input
modx-revolution
apache-cayenne
commonmark
decomposition
uitypeeditor
saxon
angular-ui
reactive-cocoa
visual-composer
immutable.js
language-agnostic
mmap
tdd
semantic-analysis
kannel
elasticsearch-ruby
webkitspeechrecognition
quote
delicious-api
textmate
stacked
dosbox
simplexml
mixture-model
az-application-insights
sqlite2
angularjs-factory
leading-zero
preconditions
ruby-on-rails-3.1
firebase-admin
keydown
bootstrap-dialog
netcdf4
acoustics
angular2-meteor
scorm
babel-core
alphabet
tizen-native-app
jxcore
diagnostics
composite-key
sybase-asa
ifs
redundancy
quartz-composer
eventkit
gridpane
libpng
infix-notation
intrusion-detection
superstack
master-slave
icu4j
kcachegrind
muse
0xdbe
mmc
jsapi
codeigniter-url
fpml
preferences
project-planning
typeof
comexception
mechanize-ruby
jboss-weld
commoncrypto
google-cloud-save
opcache
jplaton
back-stack
delphi-6
angularjs-controller
pvrtc
chuck
datawindow
twrequest
hirefire
heartbeat
actionview
sql-server-profiler
audio-capture
javap
geneva-server

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