In support of the DRY principle and to improve readability of page object fields definitions, this rule would try its best finding parts of CSS selectors that are unnecessarily repeated.
👎 Consider this Page Object:
var MyPage = function () {
this.parent = $(".container #parent");
this.child1 = $(".container #parent div:first-of-type");
this.child2 = $(".container #parent #subcontainer > .add-client");
}
👍 The .container #parent
part in this case is repeated and should be reused instead:
var MyPage = function () {
this.parent = $(".container #parent");
this.child1 = this.parent.$("div:first-of-type");
this.child2 = this.parent.$("#subcontainer > .add-client");
}
At the moment, I am not completely sure how well this rule would work for real-world Protractor codebases. If you see it reporting false positives, please report through the issue tracker and consider disabling the rule.