String ValidPricePoint=""; Double sumOfMinorRisk;
String sum1,sum2
ValidPricePoint=ValidPricePoint.replaceAll(" ","");
sumOfMinorRisk = Double.valueOf(ValidPricePoint);
sum1=String.format ("%,f", sumOfMinorRisk);
sum1=sum1.replaceAll("\\.?0*$", "");
sum1=sum1.replaceAll(",", "");
// sum1=sum1.replaceAll("\\.?0*$", "");
sum2=String.format ("%,.0f", sumOfMinorRisk*2);
Assert.assertEquals(driver.findElement(pdeath_risk_sum).getAttribute("value"), risk_sum1);
Hello everyone,
I have a little problem here, i am trying to convert String into Double to make some adjustments and than convert it again to String with right formatting. String is taken from website element in it's value can be for example "700 000".
So I get the value, than i remove the space in that value to make first conversion possible. After that i make adjustment like multiply that value by 2 (since that's how it changes on a website) and than return that value to previous state so in the end i should get "1 400 000".
Now the problem is that the Test fails in assertion and it gives me error that it expects 700 000 but found 700 000 (that's literally an error i got). I admit that after multiplication i got value of 1 400 000.0000 but as you can see i used
sum1=sum1.replaceAll("\\.?0*$", "");sum1=sum1.replaceAll(",", "");
or much simpler "(,.0f", variable with value)
both methods give same String value that is (or is supposed to be) "1 400 000" or with variable sum1
it is "700 000".
Any ideas where i fail with my logic or how to get the assertion right in this case.
Side Note : If i use variable sum1
like this sum1 = "700 000"
the assertion will not fail hence the test will pass but it will not do so if the data changes and with it the value on the website (because its calculated on fly).
Thank you for any help. Cheers!
Aucun commentaire:
Enregistrer un commentaire