Request for ExpectedConditions.attributeContains and ExpectedConditions.attributeToBe
See original GitHub issueHi,
First of all, I tried to find any issue already opened with the same request or similar one. Could not find it so I’m adding this one. Link and close this one if it’s already opened.
For my Selenium projects I love to use the ExpectedConditions.attributeContains and/or ExpectedConditions.attributeToBe but in Protractor these are not implemented and in my opinion these are a must have.
In Angular a lot of element changes happen just by only changing the class attribute, in my case I have an element that when clicked has the ‘.active’ class if we click the next element this class disappears from the first one and moves to the second element. In the automation that I’m doing is critical as I check if the element is already active, if not give him a click to make it active, wait for the class to be present and then I do the actions that I want, but I hate to redefine the element just for the wait and I hate more to use sleeps in my code.
There is already in place the ExpectedConditions.textToBePresentInElementValue so what I’m proposing is just to do something similar but instead of checking only the attribute value, checks any element attribute passed by as argument:
attributeContains(elementFinder: ElementFinder, attribute: string, text: string): Function {
let hasText = () => {
return elementFinder.getAttribute(attribute).then((actualText: string): boolean => {
return actualText.indexOf(text) > -1;
}, falseIfMissing);
};
return this.and(this.presenceOf(elementFinder), hasText);
}
and
attributeIs(elementFinder: ElementFinder, attribute: string, text: string): Function {
let hasText = () => {
return elementFinder.getAttribute(attribute).then((actualText: string): boolean => {
return actualText === text;
}, falseIfMissing);
};
return this.and(this.presenceOf(elementFinder), hasText);
}
There’s no big impact just by adding these two methods. If you implement these two, also redefine textToBePresentInElementValue to use attributeContains and pass ‘value’ as argument. They do the same.
Hope you take this request in consideration for the next release.
Thanks, Marco
Issue Analytics
- State:
- Created 6 years ago
- Reactions:2
- Comments:5 (1 by maintainers)
Top GitHub Comments
Was this ever done or is there an available alternative? I need to wait for an attribute to equal a certain string, but haven’t found the way to do this.
https://github.com/angular/protractor/pull/4993