Triggers

A bunch of triggers to bind with the 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.

Syntax

[AttributeUsage(AttributeTargets.Property | AttributeTargets.Class | AttributeTargets.Interface | AttributeTargets.Assembly, AllowMultiple = true)]
public abstract class TriggerAttribute : Attribute

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.

public TriggerScope

AppliesTo { get; set; }

Gets or sets the scope to apply the trigger to. The default value is Self.

public bool

IsDefinedAtComponentLevel { get; }

Gets a value indicating whether this trigger is defined at the component level.

Methods

protected internal 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 de-initialization.
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.
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.

TriggerScope

The enumeration that specifies the scope of the trigger application.

Value Description
Self Indicates that the trigger applies to the class/member declared.
Children Indicates that the trigger applies to the child control properties.

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:

[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 oject initialization until the control is visible.
    [WaitFor]
    public Text<_> ContentBlock { get; private set; }

    // Wait upon page oject de-initialization 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.AfterClick

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.VisibleAndHidden)]
    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.

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.

Wait

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

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

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

WaitForJQueryAjax

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

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

WaitForAngularJSAjax

Indicates that the waiting should be performed until the AngularJS (v1.*) AJAX is completed. By default occurs after the click.

public class SamplePage : Page<_>
{
    [WaitForAngularJSAjax]
    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.

Screenshot

Indicates that the screenshot should be captured with an optional title. By default occurs before the click.

public class SamplePage : Page<_>
{
    [Screenshot]
    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()
    {
    }
}

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.

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; }
}

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")]
[ControlFinding(FindTermBy.ChildContent)]
[ClickParent(AppliesTo = TriggerScope.Children)]
public class BSDropdown<TOwner> : Clickable<TOwner>
    where TOwner : PageObject<TOwner>
{
}

The control class is marked with the [ClickParent(AppliesTo = TriggerScope.Children)] 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; }
}