我试图从弹出消息中获取文本,然后将其与另一个字符串进行比较,以检查两者是否相同。
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");
如何比较这些字符串?
答案 0 :(得分:2)
由于您遇到空格和换行问题,我建议使用正则表达式将所有空白序列规范化为单个常规空间,然后再使用您的测试框架比较这两个值:
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"
)