Loading and waiting
Results that take a moment. A test that does not wait for them fails here, so it is the place to practise waiting.
1. Results behind a spinner
The button asks the server for three results; the server answers after 1.5 seconds. Meanwhile a spinner is shown. Every click draws the list again, so elements found before the click are gone afterwards.
Loading…Loads: 0
2. A message that appears later
The message appears 2 seconds after the click, without a spinner.
3. A call made with jQuery
The same request, made with $.ajax, without a spinner. VAF waits until jQuery has no request
running before it looks for a section, so the text below is already updated when the test reads it.
Status: Not loaded
What to practise
- Tell VAF which element is the loader (
LetsUseLoader), click, and read the results. - Click twice and read the list again: the old elements are stale.
- Wait for the late message without a fixed sleep.
?delay=in the address of the request changes the wait (0–5000 ms).
Waiting in VAF: guide, section 6.
Tested in VAF-Demo
A test of this page from VAF-Demo: the whole VAF chain, from the page to the element, is in the test.
[Test]
public void ResultsAreReadAfterTheLoaderIsGone()
{
// From now on VAF waits for the spinner to disappear before it looks for an element.
SharedContext.Browser.LetsUseLoader<LoadingPage.Spinner>();
SharedContext.App.Should().HaveSection<LoadingPage.SpinnerDemo>()
.That.Should().HaveElement<LoadingPage.SpinnerDemo.Load>()
.That.AsButton().LetsClick();
SharedContext.App.Should().HaveSection<LoadingPage.SpinnerDemo>()
.That.Should().HaveElement<LoadingPage.SpinnerDemo.LoadCount>()
.That.AsCounterField().Should().HaveValue("1")
.AndAlso().Should().HaveElement<LoadingPage.SpinnerDemo.FirstResult>()
.That.AsLabelText().Should().HaveValue("Alpha (load 1)");
}
On GitHub (opens in a new tab)
-
Page object
—
LoadingPage.cs: the locators of this page -
Native tests
—
LoadingTests.cs: the whole VAF chain in each test - The whole project and its README Latest test run (GitHub Actions)