Is it a good approach to use browser.wait()
for each and every element in javascript-protractor? Is their any other better approach?
Asked
Active
Viewed 337 times
0

Pransh Tiwari
- 3,983
- 1
- 32
- 43

user812142
- 163
- 2
- 17
-
are you using `protractor.ExpectedConditions` along with `browser.wait()` ? – Saddam Pojee Dec 09 '18 at 10:38
2 Answers
1
browser.wait()
You provide an Expected Condition function for Protractor/WebDriverJS
to execute and wait for the result of the function to evaluate to true. Protractor would continuously execute the function and stop once the result of the function evaluates to true or a configurable timeout has been reached.
browser.wait(EC.textToBePresentInElement(element(by.binding('myvar')), "expected"), 5000, "Text is not something I've expected");
var EC = protractor.ExpectedConditions;
var anyTextToBePresentInElement = function(elementFinder) {
var hasText = function() {
return elementFinder.getText().then(function(actualText) {
return actualText;
});
};
return EC.and(EC.presenceOf(elementFinder), hasText);
};

Rao
- 397
- 1
- 12
-1
If you want to have some wait before finding each element then you should go with implicit wait..
If not on each find element then if you are using wait with some condition like wait for element/ element to be clickable ( Expected conditions) or like page to contain something[smart wait] then its good l, Else its not good idea to implement hardocded wait[ browser.sleep()].
Refer below link:-

Yash Jagdale
- 1,446
- 14
- 17
-
I'm suggest not to use implicit waiter at all because you add some magic to your test logic. Also, if you will add it, please, read articles how it interact with explicit waiters and how it works. – Oleksii Dec 09 '18 at 21:15
-
@Oleksii - Using implicit wait more than 20 sec is not good , But it’s always helps if you are using less implicit wait(By defaults its 0). Also Implicit wait will be applicable on each find element by default. – Yash Jagdale Dec 09 '18 at 21:18
-
Yep, but if you use it you should now HOW, because "applicable" word has zero explanation how exactly works implicit wait. And I'm sure that 80% of people don't know how it works, but use it. And when some problems appear they don't know what is going on. – Oleksii Dec 10 '18 at 12:52
-