Reputation: 3
Say we have a script written to assert "InnerText" property of a HTML control. So we assert "Login Now"and it passes.
Now, say on the browser it is displayed as
"Login
Now"
Still CodedUI will pass it.
Is there any way this can be checked?
Upvotes: 0
Views: 37
Reputation: 14038
If the original assert checks that the string is Login Now
but the web page has changed so that the browser shows the two lines:
Login
Now
then the assert will fail because the string is Login\r\nNow
. (From the question it is possible that the string also has some spaces, so it could be Login \r\n Now
.)
There are at least two ways of handling this.
First you could do two asserts. One that the inner text contains Login
and the other that it contains Now
. But this would pass the strings Now Login
also You must Login Now
and that could be wrong.
Another approach is to read the inner text value, remove any leading and training spaces, convert any intervening white space to a single space, then finally do the assert. If the original assert is something like
Assert.Equals(innerText, "Login Now");
then you could replace it with something like:
Assert.Equals(Regex.Replace(innerText.Trim(), "\\s+", " "), "Login Now");
Upvotes: 1