One of them that you should look for with toMatch() , as in the accepted answer, is partial matches. For example, suppose you have an element that can have the correct and incorrect classes, and you want to verify that it has the correct class. If you used expect(element.getAttribute('class')).toMatch('correct') , this will return true even if the element has a class incorrect .
My suggestion:
If you want to accept only exact matches, you can create a helper method for it:
var hasClass = function (element, cls) { return element.getAttribute('class').then(function (classes) { return classes.split(' ').indexOf(cls) !== -1; }); };
You can use it like this (taking advantage of the expect automatically resolving promises in Protractor):
expect(hasClass(element(by.name('getoffer')), 'ngDirty')).toBe(true);
Sergey K Apr 13 '14 at 17:40 2014-04-13 17:40
source share