Skip to content

Latest commit

 

History

History
30 lines (21 loc) · 1.02 KB

no-repetitive-locators.md

File metadata and controls

30 lines (21 loc) · 1.02 KB

Discourage repeating locators

This rule would warn if repetitive locators would be detected in a single file in support of the DRY principle.

👎 For example:

var MyPage = function () {
   this.grids = element.all(by.css(".mygrid"));
   this.firstGrid = element.all(by.css(".mygrid")).first();
}

Here, .mygrid locator is used two times.

👍 A better version:

var MyPage = function () {
   this.grids = element.all(by.css(".mygrid"));
   this.firstGrid = this.grids.first();
}

Note that the rule is looking for exact duplicates of the locators - where both the by locator type and the value are repeated.

When not to have this rule enabled

If this rule produces too much false positives and warns about locators being repetitive when repetition is something you have intended to have, disable the rule. Though, I suggest leaving it enabled globally and having it disabled for specific files or problematic parts of code instead.