I have E2E tests (using Selenium WebDriver) for an Angular 4/ASP.NET Core Web API application.
I am suffering from occasional timeout/wait issues within some of the tests.
The E2E framework has a method WaitForAngular() which uses some Javascript (taken from Protractor) that waits for Angular to indicate it has loaded all 'testabilities' before continuing (see https://stackoverflow.com/a/39349865/95423)
However this doesn't seem totally reliable and occasionally on a run we end up with indefinite waits occurring.
The other approach we use is implicit waits for the element in question to be rendered:
var url = "targetURL"
Driver.Instance.Navigate().GoToUrl(url);
var waitSeconds = 15;
var navWait = new WebDriverWait(Driver.Instance, TimeSpan.FromSeconds(waitSeconds))
{
Message = $"The targetURL failed to load in {waitSeconds} seconds"
};
navWait.Until(x => x.FindElementById(targetUrlId) != null || x.FindElementById(forbiddenId) != null);
I'm seeing more robust results from the second approach, however it means more code and potentially more brittle tests if the condition of the implicit wait is not carefully considered.
Which is the better approach here, or is there an alternative?