Wait for Element upon Page Initialization

How to wait for an element upon page initialization.

Given

There is a page with slow loading of content. During the navigation to this page the test has to wait until some important content element is visible and only then start interaction with the page.

<div id="content-block">
    <span>Some content</span>
</div>
Some content

Implementation

You can choose one of the solutions below.

Using WaitForElement Trigger

using Atata;

namespace SampleApp.UITests
{
    using _ = SomePage;

    [WaitForElement(WaitBy.Id, "content-block", WaitUntil.Visible, TriggerEvents.Init)]
    public class SomePage : Page<_>
    {
    }
}

Using WaitFor Trigger

using Atata;

namespace SampleApp.UITests
{
    using _ = SomePage;

    public class SomePage : Page<_>
    {
        [FindById]
        [WaitFor(Until.Visible)] // By default executes on TriggerEvents.Init.
        public Control<_> ContentBlock { get; private set; }
    }
}

Test

Waiting for the element will be performed upon SomePage page initialization.

Go.To<SomePage>();