I have this script:
var last_build_no = this.getTitle();
var plain_build_no = "#53 ";
console.log(last_build_no.length);
console.log(plain_build_no.length);
And this is the output:
5
4
'#53 '
'#53 '
What could be the reason of this difference and how can I convert this strings in same format ?
Because of this difference my test case is failing but the strings I saw looks same:
test.assertEquals(last_build_no, plain_build_no, "Last Build page has expected title");
The string contains a "zero width space". You can see it if you log the character codes:
last_build_no.split("").forEach(c => console.log(c.charCodeAt(0)));
/*
Outputs:
35
53
8203 <-- http://www.fileformat.info/info/unicode/char/200b/index.htm
51
32
*/
Unicode has the following zero-width characters:
You can remove it with a simple regular expression:
var last_build_no = '#53 '.replace(/[\u200B-\u200D\uFEFF]/g, '');
console.log(last_build_no.length); // Output: 4
See this SO answer for more info