I figured out the testProjectsAreShownAfterCreation failed (also) because Selenium was too quick to count all the zero Project items before they were considered “displayed”, so I added an explicit wait.
// Find all elements with CSS selector ".col-8 .list-group-item".
var waitForProjects = new WebDriverWait(_webDriver, TimeSpan.FromSeconds(1));
waitForProjects.Until(d => d.FindElement(By.CssSelector(".col-8 .list-group-item")).Displayed);
// FAILED because it didn't wait for any elements to be "displayed"
ReadOnlyCollection<IWebElement> projects = _webDriver.FindElements(By.CssSelector(".col-8 .list-group-item"));
And just some reassuring questions:
- Did I do the right thing and did I do the thing right? Disregarding clean code, repetitions etc.?
- Is this just how things work, that Selenium doesn’t implicitly wait when finding multiple items (because naturally how should it know whether to wait for them to exist or not) and it’s my responsibility to explicitly ensure the surrounding conditions are favourable (like finding a single element) before I take a snapshot of the collection?
- … or did I completely miss the fact that no implicit wait has been set up in this case and if I configured an implicit wait then FindElements would also use it somehow?