3

I am using selenium webdriver with java and trying to verify some texts I find on a page. The text contains diacritics like ţ ă etc.

The problem I encounter is when I run my test from the command line using maven; I need to do this because I will be integrating them into Jenkins.

So I have a simple assert in my test:

Assert.assertEquals("some text with ţ", driver.findElement(text).getText());

which fails and I don't know what is the right way to make this work.

I have read that the default encoding for strings in Java is UTF-16, so when the text is taken from the page with getText, the string is already encoded and I suppose that means that the characters are lost. On the other hand, I don't know if the comparing text itself "some text with ţ" is interpreted ok.

Has anyone had problems similar to this? And how have you solved them?

Thanks

Maria
  • 107
  • 1
  • 1
  • 8
  • To find out what `driver.findElement(text).getText()` is, I would make it part of the erro-text. `Assert.assertEquals("some text with ţ", driver.findElement(text).getText(), "Thext was :'"+driver.findElement(text).getText()+"'");`This might give a clou what the problem is. – MrSmith42 Jan 14 '14 at 14:50

1 Answers1

1

Maven is even issuing a warning specific to your error:

WARNING: character encoding not set. Using the platform default encoding, i.e., the 
build is platform-dependent!

or a similar message.

The solution is to:

  1. make sure you save the Java source code files in UTF-8;
  2. make sure you explicitly configure the encoding in pom.xml (a setting on the Compiler plugin).
Marko Topolnik
  • 195,646
  • 29
  • 319
  • 436