Protractor is (in 2015) widely known as difficult to use. Here are some tips:

((JavascriptExecutor) driver).executeAsyncScript("angular.getTestability(document.querySelector('body')).whenStable(arguments[0])");

That will synchronously wait for Angular to finish whatever it's doing - digest cycle, animations, HTTP requests, etc. We make that call after every click on the app, and will hopefully remember to add it after every other event-triggering interaction we start using. So far, we haven't had to add any other explicit waits, and the tests are rock-solid.

Because that waits, we also had to set a global timeout on WebDriver:

driver.manage().timeouts().setScriptTimeout(10, TimeUnit.SECONDS);

The other trick we've developed is to always filter the results of a query for elements by WebElement::isDisplayed. We have a lot of elements on hidden cached views, and it seems that findElements finds those even though they're not visible.

Unless otherwise stated, the content of this page is licensed under Creative Commons Attribution-ShareAlike 3.0 License