I am performing string comparison in selenium automation. For a field, I am getting this value from UI:
Actual Value: Institutional Investors & Consultants — Canada
And same value, I have stored as a String expected value in my test.
Expected Value: Institutional Investors & Consultants — Canada
When I perform, testng assertEqual method to this, this is failing with this error message:
Actual Result : Institutional Investors & Consultants — Canada
Expected Result : Institutional Investors & Consultants — Canada
I tried to remove these special character with:
replaceAll("â€", "-")
but failed with the same message.
Try setting the encoding in the constructor of string:
subject = new String(subject.getBytes("UTF-8"), "UTF-8");
This also didn't work.
I have apache common lang3 and jsoup also. If anyone knows any good method from there to tackle this, let me know, as first I want to avoid regex and use standard libraries.
Code:
if(loc contains ("Canada")) {
Assert.assertEquals("somelocator.getText().trim()", "ExpectedValue");
}
Moreover, just simple println is prining as:
Institutional Investors & Consultants — Canada for Institutional Investors & Consultants — Canada.
When I print it in different console, then it prints fine.