Skip to content

Latest commit

 

History

History
43 lines (33 loc) · 1.76 KB

bare-element-finders.md

File metadata and controls

43 lines (33 loc) · 1.76 KB

Warn if a bare ElementFinder or ElementArrayFinder is declared with no applied action

This rule is inspired by this problem when there was an ElementFinder declared but no action was applied.

In this case, Protractor would not actually even try to locate the element, because according to documentation:

The ElementFinder knows how to locate the DOM element using the locator you passed in as a parameter, but it has not actually done so yet. It will not contact the browser until an action method has been called.

It is easy to forget to actually call an ElementFinder method and the rule would be handy in these kind of cases.

Rule details

👎 Any use of the following patterns are considered warnings:

element(by.id('signin_submit_btn'));
element.all(by.className('myClass'));
element.all(by.css(".class")).get(0);
$(".class");
$$(".class").first();
element.all(by.css(".class")).last();
element(by.css(".class1")).element(by.css(".class2"));
element(by.css(".class1")).$(".class2");
$$(".class1").first().element(by.css(".class2"));
$(".class1").$(".class2");

👍 The following patterns are not warnings:

element(by.id('signin_submit_btn')).click();
element.all(by.className('myClass')).first().click();
element.all(by.css(".class")).get(0).sendKeys("test");
$(".class").sendKeys("test");
$$(".class").first().sendKeys("test");
element.all(by.css(".class")).last().click();
element(by.css(".class1")).element(by.css(".class2")).click();
element(by.css(".class1")).$(".class2").sendKeys("test");
$$(".class1").first().element(by.css(".class2")).sendKeys("test");
$(".class1").$(".class2").sendKeys("test");