I am trying to get text from a popup message and then compare it with another string to check whether or not both are same.
var text = element(by.css('.modal.fade.AppLockPopup.in'));
//expect(text.getText()).toEqual("Warning" + "\n" + " You haven't saved your changes.Are "+ "\n" +" you sure you want to discard your changes? "+ "\n" +" Yes No");
expect(text.getText()).toEqual("Warning You haven't saved your changes.Are you sure you want to discard your changes? Yes No");
How do I compare these strings?
Since you are having issues with spaces and newlines, I would suggest using a regular expression to normalize all sequences of whitespace into a single regular space before comparing the two values using your testing framework:
var text = element(by.css('.modal.fade.AppLockPopup.in')).getText().then(function (e) {
return e.replace(/\s+/g, ' ')
})
expect(text).toEqual(
"Warning You haven't saved your changes. Are you sure you want to discard your changes? Yes No"
)