0

I have test data in an XML format, and the Text or Value from a WebElement (Selenium).

I compare both values and the Assert fails. Initially the XML whitespaces (due to formatting) were the obvious issue, but having removed them, I still get the following result. I have pasted the error log in Word and have no visual difference in spacing characters anymore.

Output of Assert

Edit: Further investigation shows that the Assert fails on the newline character. When copying to Word, the whitespace following this character is different between the expected and actual result.

Edit 2: The hexcode in decimal is 13 versus 10 so they are different characters. The question is how to convert one to the other?

FDM
  • 628
  • 6
  • 18

2 Answers2

1

I believe you should specify correct CultureInfo. For example:

Assert.AreEqual(s1, s2, false, new CultureInfo("de-DE"));

Additionally, you can try normalize your strings line endings: Normalize newlines in C#

N. M.
  • 87
  • 1
  • 1
  • 6
  • Tried to add CultureInfo.InvariantCulture but that didn't work. – FDM May 24 '17 at 14:12
  • Yes, after your comment about line endings, I think changing culture won't work. You can try comparing text by lines as workaround (split them with String.Split()). – N. M. May 24 '17 at 14:28
  • And split by which character? – FDM May 24 '17 at 14:32
  • Try something like this: s.Split(new string[] {System.Environment.NewLine}, StringSplitOptions.RemoveEmptyEntries); – N. M. May 24 '17 at 14:34
  • Have you tried string normalization, because it looks like one string has "\r\n" line ending and the other one "\n"? – N. M. May 24 '17 at 14:57
0

The strings that are being compared have a mixture of Line Feeds (Decimal = 10, \n) and Carriage Returns (Decimal = 13, \r).


I think the easiest solution would be to normalize the strings:

yourString.Replace("\r\n", "\n").Replace('\r', '\n');
budi
  • 6,351
  • 10
  • 55
  • 80