Triggers

A list of triggers to bind with different component events.

Trigger - is an attribute containing some functionality that is automatically executed in response to certain events on a particular UIComponent. For example, when a click on button occurs it may be defined that a wait should be executed; or add page title verification upon page object initialization. Just mark control property or page object class with necessary trigger attribute.

Trigger

Represents the base attribute class for the triggers. An inherited class should implement Execute method.

Syntax

public abstract class TriggerAttribute : MulticastAttribute

Properties

public TriggerEvents

On { get; set; }

Gets or sets the trigger events.

public TriggerPriority

Priority { get; set; }

Gets or sets the priority. The default value is Medium.

Methods

protected abstract void

Execute<TOwner>(TriggerContext<TOwner> context)

where TOwner : PageObject<TOwner>, IPageObject<TOwner>

Executes the specified trigger action.

TriggerEvents

The flags enumeration that specifies the trigger events.

Value Description
None None of the events.
Init Occurs upon the page object initialization.
DeInit Occurs upon the page object deinitialization.
BeforeAccess Occurs before any access to the component.
AfterAccess Occurs after any access to the component.
BeforeGet Occurs before the value is taken from the control.
AfterGet Occurs after the value is taken from the control.
BeforeSet Occurs before the value is set to the control.
AfterSet Occurs after the value is set to the control.
BeforeClick Occurs before the click on the control.
AfterClick Occurs after the click on the control.
BeforeHover Occurs before the hover on the control.
AfterHover Occurs after the hover on the control.
BeforeFocus Occurs before the control gets the focus.
AfterFocus Occurs after the control gets the focus.
BeforeBlur Occurs before the control loses the focus.
AfterBlur Occurs after the control loses the focus.
BeforeScroll Occurs before the scrolling to control.
AfterScroll Occurs after the scrolling to control.

TriggerPriority

The enumeration that specifies the priority of the trigger execution.

Value Description
Highest The highest priority.
Higher The higher priority.
High The high priority.
Medium The medium priority.
Low The low priority.
Lower The lower priority.
Lowest The lowest priority.

VerifyTitle

Specifies the verification of the page title. By default occurs upon the page object initialization. If no value is specified, it uses the class name as the expected value with the TermCase.Title casing applied.

[VerifyTitle]
public class ProductDetailsPage : Page<_> 
{
}

The example verifies that the page title should equal “Product Details”.

VerifyTitleSettings

Defines the settings to apply for the VerifyTitleAttribute trigger.

For example, set the default title format in global Atata configuration:

AtataContext.GlobalConfiguration
    .Attributes.Global.Add(new VerifyTitleSettingsAttribute { Format = "{0} - Atata Sample App" });

Or using assembly attribute:

[assembly: VerifyTitleSettings(Format = "{0} - Atata Sample App")]

VerifyH1-H6

Specifies the verification of h1-h6 elements content. By default occurs upon the page object initialization. If no value is specified, it uses the class name as the expected value with the TermCase.Title casing applied.

[VerifyH1]
[VerifyH2("General")]
[VerifyH2("Additional", Index = 1)]
public class ProductDetailsPage : Page<_> 
{
}

The example verifies that the page’s h1 element should have content “Product Details”, first h2 should be “General” and second h2 should be “Additional”.

VerifyContent

Specifies the verification of the page content. Verifies whether the component contains the specified content values. By default occurs upon the page object initialization.

[VerifyContent("Some text", "Another text")]
public class SamplePage : Page<_>
{
}

The example verifies that the page content should contain text: “Some text” and “Another text”.

VerifyContentMatches

Specifies the verification of the page content. Verifies whether the component content matches any of the specified values. By default occurs upon the page object initialization.

[VerifyContentMatches(TermMatch.Contains, "Primary", "Secondary")]
public class SamplePage : Page<_>
{
    [VerifyContentMatches(TermMatch.StartsWith, "Start")]
    [VerifyContentMatches(TermMatch.EndsWith, "end")]
    public Link<_> SomeLink { get; private set; }
}

The example verifies that the page content should contain the text: “Primary” or “Secondary”. Also, verifies that the content of SomeLink should start with “Start” text and end with “end”.

VerifyExists

Indicates that the component should be verified whether it exists on the specified event. By default occurs upon the page object initialization.

public class SamplePage : Page<_>
{
    [VerifyExists]
    public Button<_> Add { get; private set; }
}

VerifyMissing

Indicates that the component should be verified whether it is missing on the specified event. By default occurs upon the page object initialization.

public class SamplePage : Page<_>
{
    [VerifyMissing]
    public Button<_> Delete { get; private set; }
}

Until

The enumeration that specifies the waiting condition of the component/element.

Values

Missing

Waits until the component/element will be missing.

Hidden

Waits until the component/element will be hidden.

MissingOrHidden

Waits until the component/element will be missing or hidden.

Visible

Waits until the component/element will be visible.

VisibleOrHidden

Waits until the component/element will be visible or hidden.

VisibleThenHidden

Waits until the component/element will be visible and then until it will be hidden.

VisibleThenMissing

Waits until the component/element will be visible and then until it will be missing.

VisibleThenMissingOrHidden

Waits until the component/element will be visible and then until it will be missing or hidden.

MissingThenVisible

Waits until the component/element will be missing and then until it will be visible.

HiddenThenVisible

Waits until the component/element will be hidden and then until it will be visible.

MissingOrHiddenThenVisible

Waits until the component/element will be missing or hidden and then until it will be visible.

WaitFor

Specifies the condition of the component to wait for. By default occurs upon the page object initialization.

It calls component’s Wait method passing Until value to it.

public class SamplePage : Page<_>
{
    // Wait upon page object initialization until the control is visible.
    [WaitFor]
    public Text<_> ContentBlock { get; private set; }

    // Wait upon page object deinitialization until the control is missing or hidden.
    [WaitFor(Until.MissingOrHidden, TriggerEvents.DeInit)]
    public Text<_> SavingIndicator { get; private set; }
}

Parameters

Until

until = Until.Visible

The waiting condition. The default is Visible.

TriggerEvents

on = TriggerEvents.Init

The trigger events. The default is Init.

TriggerPriority

priority = TriggerPriority.Medium

The priority. The default is Medium.

Properties

public bool

ThrowOnPresenceFailure { get; set; }

Gets or sets a value indicating whether to throw the exception on the presence (exists or visible) failure. The default value is true.

public bool

ThrowOnAbsenceFailure { get; set; }

Gets or sets a value indicating whether to throw the exception on the absence (missing or hidden) failure. The default value is true.

public double

PresenceTimeout { get; set; }

Gets or sets the presence (exists or visible) timeout in seconds. The default value is taken from AtataContext.Current.RetryTimeout.TotalSeconds.

public double

AbsenceTimeout { get; set; }

Gets or sets the absence (missing or hidden) timeout in seconds. The default value is taken from AtataContext.Current.RetryTimeout.TotalSeconds.

public double

RetryInterval { get; set; }

Gets or sets the retry interval. The default value is taken from AtataContext.Current.RetryInterval.TotalSeconds.

WaitForElement

Specifies the waiting for the element. By default occurs after the click.

public class SamplePage : Page<_>
{
    [WaitForElement(WaitBy.Class, "busy-indicator", Until.VisibleThenMissingOrHidden)]
    public Button<_> Refresh { get; private set; }
}

The example after the click on Refresh button waits for element with class “busy-indicator” to become visible and then waits until it will become hidden or missing.

Parameters

WaitBy

waitBy

The kind of the element selector to wait for.

string

selector

The selector.

Until

until = Until.MissingOrHidden

The waiting condition. The default is MissingOrHidden.

TriggerEvents

on = TriggerEvents.AfterClick

The trigger events. The default is AfterClick.

TriggerPriority

priority = TriggerPriority.Medium

The priority. The default is Medium.

Properties

public ScopeSource

ScopeSource { get; set; }

Gets or sets the scope source. The default value is ScopeSource.Parent.

public bool

ThrowOnPresenceFailure { get; set; }

Gets or sets a value indicating whether to throw the exception on the presence (exists or visible) failure. The default value is true.

public bool

ThrowOnAbsenceFailure { get; set; }

Gets or sets a value indicating whether to throw the exception on the absence (missing or hidden) failure. The default value is true.

public double

PresenceTimeout { get; set; }

Gets or sets the presence (exists or visible) timeout in seconds. The default value is taken from AtataContext.Current.RetryTimeout.TotalSeconds.

public double

AbsenceTimeout { get; set; }

Gets or sets the absence (missing or hidden) timeout in seconds. The default value is taken from AtataContext.Current.RetryTimeout.TotalSeconds.

public double

RetryInterval { get; set; }

Gets or sets the retry interval. The default value is taken from AtataContext.Current.RetryInterval.TotalSeconds.

WaitBy

The enumeration that specifies the kind of the element selector for the waiting.

Value Description
Id Uses the id selector kind.
Name Uses the name selector kind.
Class Uses the class selector kind.
Css Uses the CSS selector kind.
XPath Uses the XPath selector kind.

WaitSeconds

Specifies the waiting period in seconds. By default occurs after any action.

public class SamplePage : Page<_>
{
    [WaitSeconds(2)]
    public Button<_> Save { get; private set; }
}

The example waits 2 seconds after the click on the Save button.

WaitForAlertBox

Indicates to wait for an alert box to be present on the specified event. Be default occurs after the click.

public class SamplePage : Page<_>
{
    [WaitForAlertBox]
    public Button<_> Perform { get; private set; }
}

WaitForScript

Represents the base trigger attribute for a waiting for script to be executed successfully. An inherited class should override BuildScript method and optionally BuildReportMessage.

WaitForDocumentReadyState

Indicates that the waiting should be performed until the document is ready/loaded. By default occurs upon the page object initialization.

[WaitForDocumentReadyState]
public class SamplePage : Page<_>
{
}

WaitForJQueryAjax

Indicates that the waiting should be performed until the jQuery AJAX is completed. By default occurs after the click.

[WaitForJQueryAjax(TriggerEvents.Init)]
public class SamplePage : Page<_>
{
    [WaitForJQueryAjax]
    public Button<_> Save { get; private set; }
}

WaitForAngular

Indicates to wait until Angular (v2+) has finished rendering and has no outstanding HTTP calls. By default occurs after the click.

Apply to button after click:

[WaitForAngular(TriggerEvents.AfterClick)]
public Button<_> Save { get; private set;}

Apply to page object upon initialization:

[WaitForAngular(TriggerEvents.Init)]
public class SomePage : Page<_>
{
}

Apply the trigger globally for all Init and AfterClick events:

AtataContext.GlobalConfiguration
    .Attributes.Global.Add(new WaitForAngularAttribute(TriggerEvents.Init | TriggerEvents.AfterClick));

WaitForAngularJS

Indicates to wait until AngularJS (v1) has finished rendering and has no outstanding HTTP calls. By default occurs after the click.

public class SamplePage : Page<_>
{
    [WaitForAngularJS]
    public Button<_> Save { get; private set; }
}

LogInfo

Defines the information message to be logged on the specified event.

[LogInfo("Opening product editor", TriggerEvents.OnPageObjectInit)]
public class ProductEditPage : Page<_>
{
    [LogInfo("Product is saved", TriggerEvents.AfterClick)]
    public Button<_> Save { get; private set; }
}

The example writes “Opening product editor” message to the log during the page initialization. Then, after the Save button click, the “Product is saved” message is written to the log.

TakeScreenshot

Indicates that a screenshot should be captured with an optional title.

[TakeScreenshot(TriggerEvents.Init)]
public class SamplePage : Page<_>
{
    [TakeScreenshot(TriggerEvents.BeforeClick)]
    public Button<_> Save { get; private set; }
}

TakePageSnapshot

Indicates that a page snapshot should be captured with an optional title.

[TakePageSnapshot(TriggerEvents.Init)]
public class SamplePage : Page<_>
{
    [TakePageSnapshot(TriggerEvents.BeforeClick)]
    public Button<_> Save { get; private set; }
}

InvokeMethod

Defines the method to invoke on the specified event.

public class SamplePage : Page<_>
{
    [InvokeMethod(nameof(OnBeforePerform), TriggerEvents.BeforeClick)]
    [InvokeMethod(nameof(OnAfterPerform), TriggerEvents.AfterClick)]
    public Button<_> Perform { get; private set; }

    private void OnBeforePerform()
    {
    }

    private void OnAfterPerform()
    {
    }
}

InvokeDelegate

Defines the delegate to invoke on the specified event.

AtataContext.GlobalConfiguration
    .Attributes.Component(typeof(Page<>)).Add(
        new InvokeDelegateAttribute(
            () =>
            {
                // Do something.
            },
            TriggerEvents.Init));
AtataContext.GlobalConfiguration
    .Attributes.Component<SomePage>().Add(
        new InvokeDelegateAttribute(DoSomething, TriggerEvents.Init));

void DoSomething()
{
}

CloseAlertBox

Indicates that the alert box should be closed on the specified event. Be default occurs after the click.

<button onclick="alert('The item is removed!')">Delete</button>
public class SamplePage : Page<_>
{
    [CloseAlertBox]
    public Button<_> Delete { get; private set; }
}

The example defines that the alert box should be closed after the click on the Delete button.

CloseConfirmBox

Indicates that the confirm box should be closed on the specified event. Be default occurs after the click. By default accepts the confirm box.

<button onclick="confirm('Are you sure you want to delete the item?')">Delete</button>
public class SamplePage : Page<_>
{
    [CloseConfirmBox]
    public Button<_> Delete { get; private set; }
}

The example defines that the confirm box should be closed with the acceptance after the click on the Delete button.

Focus

Indicates that the focusing on the control should be performed on the specified event. By default occurs before set.

public class SamplePage : Page<_>
{
    [Focus]
    public TextInput<_> SomeInput { get; private set; }
}

Blur

Indicates that the control blurring (removing focus) should be performed on the specified event. By default occurs after set.

public class SamplePage : Page<_>
{
    [Blur]
    public TextInput<_> SomeInput { get; private set; }
}

PressKeys

Defines the keys to press on the specified event. By default occurs after the set.

public class SamplePage : Page<_>
{
    [PressKeys("end")]
    public TextInput<_> SomeInput { get; private set; }
}
Go.To<SamplePage>()
    .SomeInput.Set("start")
    .SomeInput.Should.Equal("startend");

The example appends “end” text to the end of SomeInput each time it is being set.

PressEnter

Indicates that the Enter key should be pressed on the specified event. By default occurs after the set.

public class SamplePage : Page<_>
{
    [PressEnter]
    public TextInput<_> SomeInput { get; private set; }
}

PressEscape

Indicates that the Escape key should be pressed on the specified event. By default occurs after the set.

public class SamplePage : Page<_>
{
    [PressEscape]
    public TextInput<_> SomeInput { get; private set; }
}

PressTab

Indicates that the Tab key should be pressed on the specified event. By default occurs after the set.

public class SamplePage : Page<_>
{
    [PressTab]
    public TextInput<_> SomeInput { get; private set; }
}

PressHome

Indicates that the Home key should be pressed on the specified event. By default occurs after the set.

public class SamplePage : Page<_>
{
    [PressHome]
    public TextInput<_> SomeInput { get; private set; }
}

PressEnd

Indicates that the End key should be pressed on the specified event. By default occurs after the set.

public class SamplePage : Page<_>
{
    [PressEnd]
    public TextInput<_> SomeInput { get; private set; }
}

ScrollDown

Indicates that the scroll down should be performed on the specified event. By default occurs before any access to the component.

public class SamplePage : Page<_>
{
    [ScrollDown]
    public Button<_> Save { get; private set; }
}

ScrollUp

Indicates that the scroll up should be performed on the specified event. By default occurs before any access to the component.

public class SamplePage : Page<_>
{
    [ScrollUp]
    public Button<_> Save { get; private set; }
}

ClickParent

Indicates that the click on the parent component should occur on the specified event. By default occurs before any access to the component. Is useful for the drop-down button/menu controls.

Here is the Bootstrap’s dropdown example:

<li class="dropdown">
    <a href="#" class="dropdown-toggle" data-toggle="dropdown" role="button">
        Account <span class="caret"></span>
    </a>
    <ul class="dropdown-menu">
        <li>
            <a href="#">Settings</a>
        </li>
        <li>
            <a href="#">Sign Out</a>
        </li>
    </ul>
</li>

Bootstrap’s dropdown control can be defined with the following class:

[ControlDefinition(ContainingClass = "dropdown", ComponentTypeName = "dropdown")]
[FindByChildContent]
[ClickParent(TargetChildren = true)]
public class BSDropdown<TOwner> : Clickable<TOwner>
    where TOwner : PageObject<TOwner>
{
}

The control class is marked with the [ClickParent(TargetChildren = true)] attribute that means that before the clicking on any of the child component the click on the parent (drop-down) should be performed.

And the specified above account drop-down can be implemented as follows:

public class AccountDropdown : BSDropdown<_>
{
    public Link<SignInPage, _> SignOut { get; private set; }

    public Link<SettingsPage, _> Settings { get; private set; }
}

HoverParent

Indicates that the hover on the parent component should occur on the specified event. By default occurs before any access to the component. Is useful for the drop-down menu item controls.

public class SampleControl<TOwner> : Control<TOwner>
    where TOwner : PageObject<TOwner>
{
    [HoverParent]
    public Button<TOwner> SubItem { get; private set; }
}

RightClickParent

Indicates that the right click on the parent component should occur on the specified event. By default occurs before any access to the component. Is useful for the context menu item controls.

[RightClickParent(TargetChildren = true)]
public class SampleControl<TOwner> : Control<TOwner>
    where TOwner : PageObject<TOwner>
{
    public Button<ItemEditPage, TOwner> Edit { get; private set; }

    public Button<TOwner> Delete { get; private set; }
}