Components

A list of classes that represent the most often used HTML components.

UIComponent

Represents the base class for UI components (page objects and controls).

When accessing any UIComponent’s and inherited type’s member that uses Scope (actual HTML element) property, executes TriggerEvents.BeforeAccess and TriggerEvents.AfterAccess triggers. Find out more on triggers.

Syntax

There are 2 UIComponent classes. The generic one is inherited from the non-generic:

public abstract class UIComponent

and

[GetsContentFromSource(ContentSource.Text)]
public abstract class UIComponent<TOwner> : UIComponent, IUIComponent<TOwner>
    where TOwner : PageObject<TOwner>

TOwner is the type of the owner page object. Declaring any control or page object requires specifying TOwner.

Properties

public ValueProvider<bool, TOwner>

IsPresent { get; }

Gets the ValueProvider<bool, TOwner> of a value indicating whether the component is present considering the Visibility of component.

Component.IsPresent.WaitTo.BeTrue();
public ValueProvider<bool, TOwner>

IsVisible { get; }

Gets the ValueProvider<bool, TOwner> of a value indicating whether the component is visible.

Component.IsVisible.Should.BeTrue();
public ValueProvider<bool, TOwner>

IsVisibleInViewport { get; }

Gets the ValueProvider<bool, TOwner> of a value indicating whether the component is visible in viewport.

Component.IsVisibleInViewport.Should.BeTrue();
public ValueProvider<string, TOwner>

Content { get; }

Gets the ValueProvider<string, TOwner> of the text content. Gets a content using ContentGetBehaviorAttribute associated with the component, which by default is GetsContentFromSourceAttribute with ContentSource.Text argument, meaning that by default it returns IWebElement.Text property value of component scope’s IWebElement element.

Component.Content.Should.Contain("some text");
public ValueProvider<string, TOwner>

TagName { get; }

Gets the ValueProvider<string, TOwner> of the scope element tag name.

string tagName = Component.TagName;
public UIComponentLocationProvider<TOwner>

ComponentLocation { get; }

Gets the UIComponentLocationProvider<TOwner> instance that provides an access to the scope element’s location (X and Y).

Component.ComponentLocation.X.Should.BeGreater(10);
public UIComponentSizeProvider<TOwner>

ComponentSize { get; }

Gets the UIComponentSizeProvider<TOwner> instance that provides an access to the scope element’s size (Width and Height).

Component.ComponentSize.Height.Should.BeLessOrEqual(15);
public UIComponentDomAttributesProvider<TOwner>

DomAttributes { get; }

Gets the UIComponentDomAttributesProvider<TOwner> instance that provides an access to the scope element’s DOM attributes.

Component.DomAttributes["data-value"].Should.Equal("val");
public UIComponentDomPropertiesProvider<TOwner>

DomProperties { get; }

Gets the UIComponentDomPropertiesProvider<TOwner> instance that provides an access to the scope element’s DOM properties.

Component.DomProperties.Id.Should.Be("some-id");
public ValueProvider<IEnumerable<string>, TOwner>

DomClasses { get; }

Gets the ValueProvider<TValue, TOwner> instance that provides a list of the scope element’s DOM classes.

Component.DomClasses.Should.Contain("some-class");
bool hasSomeClass = Component.DomClasses.Value.Contains("some-class");
public UIComponentCssProvider<TOwner>

Css { get; }

Gets the UIComponentCssProvider<TOwner> instance that provides an access to the scope element’s CSS properties.

Component.Css["display"].Should.Equal("block");
public UIComponentScriptExecutor<TOwner>

Script { get; }

Gets the UIComponentScriptExecutor<TOwner> instance that provides a set of methods for JavaScript execution.

Component.Script.Execute("runSomeGenericScript();");
Component.Script.ExecuteAgainst("arguments[0].value = arguments[1];", "new value");
public UIComponentChildrenList<TOwner>

Controls { get; }

Gets the list of child controls.

public UIComponentMetadata

Metadata { get; }

Gets the metadata of the component. It is possible to query/add/remove attributes in metadata at any moment.

Component.Metadata.Push(new WaitAttribute(2));
public UIComponentVerificationProvider<UIComponent<TOwner>, TOwner>

Should { get; }

Gets the assertion verification provider that has a set of verification extension methods.

Component.Should.BePresent();
Component.Should.Not.BeHidden();
Component.Should.BeDisabled();
public UIComponentVerificationProvider<UIComponent<TOwner>, TOwner>

ExpectTo { get; }

Gets the expectation verification provider that has a set of verification extension methods.

Component.ExpectTo.BeVisibleInViewport();
public UIComponentVerificationProvider<UIComponent<TOwner>, TOwner>

WaitTo { get; }

Gets the waiting verification provider that has a set of verification extension methods. Uses WaitingTimeout and WaitingRetryInterval of AtataContext.Current for timeout and retry interval.

Component.WaitTo.BeVisible();
public ScopeSource

ScopeSource { get; }

Gets the source of the scope, e.g., ScopeSource.Parent, ScopeSource.Page, etc.

public IWebElement

Scope { get; }

Gets the IWebElement instance that represents the scope HTML element associated with this component. Also executes TriggerEvents.BeforeAccess and TriggerEvents.AfterAccess triggers.

Component.Scope.SendKeys("some text");
public ISearchContext

ScopeContext { get; }

Gets the ISearchContext instance that represents the scope search context (where to find the children of this component). By default is the same as Scope. Also can execute TriggerEvents.BeforeAccess and TriggerEvents.AfterAccess triggers.

public UIComponent<TOwner>

Parent { get; }

Gets the parent component.

public Owner

Owner { get; }

Gets the owner page object.

public AtataContext

Context { get; }

Gets the AtataContext instance with which this component is associated.

public string

ComponentName { get; set; }

Gets or sets the name of the component.

public string

ComponentTypeName { get; }

Gets the name of the component type. Returns the value of ComponentTypeName property for control from ControlDefinitionAttribute and for page object from PageObjectDefinitionAttribute.

public string

ComponentFullName { get; }

Gets the full name of the component including parent component full name, own component name and own component type name.

Methods

public IWebElement

GetScope(SearchOptions options = null)

Gets the IWebElement instance that represents the scope HTML element. Also executes TriggerEvents.BeforeAccess and TriggerEvents.AfterAccess triggers.

public bool

Exists(SearchOptions options = null)

Determines whether the component exists. If options is set to null, then it uses SearchOptions.Safely().

public bool

Missing(SearchOptions options = null)

Determines whether the component is missing. If options is set to null, then it uses SearchOptions.Safely().

public TOwner

Wait(Until until, WaitOptions options = null)

Waits until the specified component condition is met.

LoadingBlock.Wait(Until.Hidden);
// Or
ContentBlock.Wait(Until.Visible);

Control

Represents the base class for the controls.

Inherited from UIComponent.

Inherited class supports [ControlDefinition], [FindSettings], [TermFindSettings], [Format] and [Culture] settings attributes.

Syntax

[ControlDefinition(ComponentTypeName = "control")]
[ClicksUsingClickMethod]
[DoubleClicksUsingActions]
[RightClicksUsingActions]
[HoversUsingActions]
[FocusesUsingScript]
[BlursUsingScript]
[DragsAndDropsUsingActions]
[DragsAndDropsToOffsetUsingActions]
[ScrollsUsingScrollToElementAction]
public class Control<TOwner> : UIComponent<TOwner>, IControl<TOwner>
    where TOwner : PageObject<TOwner>

Properties

public ValueProvider<bool, TOwner>

IsEnabled { get; }

Gets the ValueProvider<bool, TOwner> for the value indicating whether the control is enabled.

Control.IsEnabled.Should.BeTrue();
Control.Should.BeEnabled();
bool isEnabled = Control.IsEnabled;
public ValueProvider<bool, TOwner>

IsFocused { get; }

Gets the ValueProvider<bool, TOwner> for the value indicating whether the control is focused.

Control.IsFocused.Should.BeTrue();
Control.Should.BeFocused();
bool isFocused = Control.IsFocused;

Methods

public TOwner

Click()

Clicks the control. Also executes TriggerEvents.BeforeClick and TriggerEvents.AfterClick triggers.

public TNavigateTo

ClickAndGo<TNavigateTo>(TNavigateTo navigateToPageObject = null, bool? temporarily = null)

where TNavigateTo : PageObject<TNavigateTo>

Clicks the control and performs the navigation to the page object of TNavigateTo type. Also executes TriggerEvents.BeforeClick and TriggerEvents.AfterClick triggers.

public TOwner

Hover()

Hovers the control. Also executes TriggerEvents.BeforeHover and TriggerEvents.AfterHover triggers.

public TOwner

Focus()

Focuses the control. Also executes TriggerEvents.BeforeFocus and TriggerEvents.AfterFocus triggers.

public TOwner

DoubleClick()

Double-clicks the control. Also executes TriggerEvents.BeforeClick and TriggerEvents.AfterClick triggers.

public TNavigateTo

DoubleClickAndGo<TNavigateTo>(TNavigateTo navigateToPageObject = null, bool? temporarily = null)

where TNavigateTo : PageObject<TNavigateTo>

Double-clicks the control and performs the navigation to the page object of TNavigateTo type. Also executes TriggerEvents.BeforeClick and TriggerEvents.AfterClick triggers.

public TOwner

RightClick()

Right-clicks the control. Also executes TriggerEvents.BeforeClick and TriggerEvents.AfterClick triggers.

public TOwner

DragAndDropTo(Func<TOwner, Control<TOwner>> targetSelector)

Drags and drops the control to the target control returned by targetSelector. By default uses DragAndDropUsingActionsAttribute. Also executes TriggerEvents.BeforeClick and TriggerEvents.AfterClick triggers.

public TOwner

DragAndDropTo(Control<TOwner> target)

Drags and drops the control to the target control. By default uses DragAndDropUsingActionsAttribute. Also executes TriggerEvents.BeforeClick and TriggerEvents.AfterClick triggers.

public TOwner

DragAndDropToOffset(int offsetX, int offsetY)

Drags and drops the control to the specified offset. Also executes TriggerEvents.BeforeClick and TriggerEvents.AfterClick triggers.

public TOwner

ScrollTo()

Scrolls to the control. By default uses ScrollsUsingScrollToElementActionAttribute behavior. Also executes TriggerEvents.BeforeScroll and TriggerEvents.AfterScroll triggers.

PageObject

Represents the base class for the page objects. Also executes TriggerEvents.Init and TriggerEvents.DeInit triggers.

Inherited from UIComponent.

Inherited class supports [PageObjectDefinition], [FindSettings], [TermFindSettings], [FormatSettings] and [Culture] settings attributes.

Syntax

public abstract class PageObject<TOwner> : UIComponent<TOwner>, IPageObject<TOwner>
    where TOwner : PageObject<TOwner>

Properties

public ValueProvider<string, TOwner>

PageTitle { get; }

Gets the ValueProvider instance for the title of the current HTML page.

PageObject.PageTitle.Should.StartWith("Some Title");
string title = PageObject.PageTitle;
public ValueProvider<string, TOwner>

PageUrl { get; }

Gets the ValueProvider instance for the URL of the current HTML page.

PageObject.PageUrl.Should.EndWith("/some-page?id=123987");
public ValueProvider<string, TOwner>

PageSource { get; }

Gets the ValueProvider instance for the source of the current HTML page.

string html = PageObject.PageSource;
public Control<TOwner>

ActiveControl { get; }

Gets the active control.

PageObject.ActiveControl.Attributes.Value.Should.Equal("123");

Methods

public virtual TOwner

RefreshPage()

Refreshes the current page.

public virtual TOther

GoBack<TOther>(TOther previousPageObject = null)

where TOther : PageObject<TOther>

Navigates back to the previous page.

public virtual TOther

GoForward<TOther>(TOther nextPageObject = null)

where TOther : PageObject<TOther>

Navigates forward to the next page.

public virtual void

CloseWindow()

Closes the current window.

public TFramePageObject

SwitchToFrame<TFramePageObject>(By frameBy, TFramePageObject framePageObject = null, bool temporarily = false)

where TFramePageObject : PageObject<TFramePageObject>

Switches to frame page object using By instance that represents the selector for <iframe> tag element.

public virtual TFramePageObject

SwitchToFrame<TFramePageObject>(IWebElement frameElement, TFramePageObject framePageObject = null, bool temporarily = false)

where TFramePageObject : PageObject<TFramePageObject>

Switches to frame page object using IWebElement instance that represents <iframe> tag element.

public virtual TPageObject

SwitchToRoot<TPageObject>(TPageObject rootPageObject = null)

where TPageObject : PageObject<TPageObject>

Switches to the root page using WebDriver’s SwitchTo().DefaultContent() method.

public TOwner

Press(string keys)

Presses the specified keystrokes.

public TOwner

PerformActions(Func<Actions, Actions> actionsBuilder)

Performs the specified set of actions.

public TOwner

Wait(TimeSpan time)

Waits the specified time.

public TOwner

Wait(double seconds)

Waits the specified time in seconds.

public TOwner

Do<TComponent>(Func<TOwner, TComponent> componentSelector, Action<TComponent> action)

Executes the action(s) passing specified parent’s component.

public TNavigateTo

Do<TComponent, TNavigateTo>(Func<TOwner, TComponent> componentSelector, Func<TComponent, TNavigateTo> navigationAction)

where TNavigateTo : PageObject<TNavigateTo>

Executes the navigation action(s) passing specified parent’s component.

public TOwner

Do(Action<TOwner> action)

Executes the action(s) passing current page object.

public TNavigateTo

Do<TNavigateTo>(Func<TOwner, TNavigateTo> navigationAction)

where TNavigateTo : PageObject<TNavigateTo>

Executes the navigation action(s) passing current page object.

Page

Represents the whole HTML page and is the main base class to inherit for the pages. Uses the <body> tag as a scope.

Inherited from PageObject.

Inherited class supports [PageObjectDefinition], [FindSettings], [TermFindSettings] and [Culture] settings attributes.

Syntax

[PageObjectDefinition(ComponentTypeName = "page", IgnoreNameEndings = "Page,PageObject")]
public class Page<TOwner> : PageObject<TOwner>
    where TOwner : Page<TOwner>

Example

using _ = SamplePage;

[VerifyTitle("Sample Page")]
[VerifyContent("Some inner text")]
[Url("some/page")]
public class SamplePage : Page<_>
{
}

PopupWindow

Represents the base class for the popup window page objects.

Inherited from PageObject.

Inherited class supports [PageObjectDefinition], [WindowTitleElementDefinition], [FindSettings], [TermFindSettings] and [Culture] settings attributes.

Syntax

[PageObjectDefinition(ComponentTypeName = "window", IgnoreNameEndings = "PopupWindow,Window,Popup")]
public abstract class PopupWindow<TOwner> : PageObject<TOwner>
    where TOwner : PopupWindow<TOwner>

Example

The example of popup component for Bootstrap’s Modal implemented in atata-framework/atata-bootstrap:

namespace Atata.Bootstrap;

[PageObjectDefinition("div", ContainingClass = "modal", ComponentTypeName = "modal", IgnoreNameEndings = "PopupWindow,Window,Popup,Modal")]
[WindowTitleElementDefinition(ContainingClass = TitleClassName)]
public abstract class BSModal<TOwner> : PopupWindow<TOwner>
    where TOwner : BSModal<TOwner>
{
    private const string TitleClassName = "modal-title";

    protected BSModal(params string[] windowTitleValues)
        : base(windowTitleValues)
    {
    }

    [FindByClass(TitleClassName)]
    public Text<TOwner> ModalTitle { get; private set; }
}

Implementation of the specific modal having the title “Some Modal”:

using _ = SampleModal;

[WindowTitle("Some Modal")]
public class SampleModal : BSModal<_>
{
}

FrameSetPage

Represents the frameset-based HTML page. Uses the root <frameset> tag as a scope.

Inherited from PageObject.

Inherited class supports [PageObjectDefinition], [FindSettings], [TermFindSettings] and [Culture] settings attributes.

Syntax

[PageObjectDefinition("frameset", ComponentTypeName = "page", IgnoreNameEndings = "Page,PageObject")]
public abstract class FrameSetPage<TOwner> : PageObject<TOwner>
    where TOwner : FrameSetPage<TOwner>

Field

Represents the base class for the field controls. It can be used for HTML elements containing content (like <h1>, <span>, etc.) representing content as a field value, as well as for <input> and other elements.

The only abstract member of Field<TValue, TOwner> is protected abstract TValue GetValue() method that is required to be overridden. Value of the field can be input’s value attribute, some other attribute, text content or a set of data.

Inherited class can support [Format], [Culture] and other settings attributes.

Syntax

public abstract class Field<TValue, TOwner> : Control<TOwner>, IEquatable<TValue>, IObjectProvider<TValue, TOwner>, IConvertsValueToString<TValue>
    where TOwner : PageObject<TOwner>

Properties

public TValue

Value { get; }

Gets the value. Also executes TriggerEvents.BeforeGet and TriggerEvents.AfterGet triggers.

Methods

public TOwner

Get(out T value)

Gets the value and records it to value parameter.

protected abstract TValue

GetValue()

Gets the value.

Example

The example of RadioButton<TOwner> control that is inherited from Field<TValue, TOwner>:

[ControlDefinition("input[@type='radio']")]
public class RadioButton<TOwner> : Field<bool, TOwner>
    where TOwner : PageObject<TOwner>
{
    public ValueProvider<bool, TOwner> IsChecked =>
        CreateValueProvider("checked state", () => Value);

    protected override bool GetValue() =>
        Scope.Selected;

    public TOwner Check()
    {
        OnCheck();

        return Owner;
    }

    protected virtual void OnCheck()
    {
        if (!IsChecked)
            Click();
    }
}

Usage

Go.To<SomePage>()
    .SomeTextField.Get(out string textFieldValue) // Read the field value to the variable.
    .SomeTextField.Should.Equal("some value") // Verify the field value.
    .SomeNumberField.Should.BeGreater(10) // Verify the field value.
    .SomeRadioButton.Check() // Check the radio button.
    .SomeRadioButton.IsChecked.Should.BeTrue(); // Verify the radio button is checked.

EditableField

Represents the base class for editable field controls. It can be used for controls like <input>, <select> and other editable controls.

Abstract methods of EditableField<TValue, TOwner> are: protected abstract TValue GetValue() and protected abstract void SetValue(TValue value).

Inherited from Field.

Inherited class can support [Format], [Culture] and other settings attributes.

Syntax

public abstract class EditableField<TValue, TOwner> : Field<TValue, TOwner>
    where TOwner : PageObject<TOwner>

Properties

public ValueProvider<bool, TOwner>

IsReadOnly { get; }

Gets the ValueProvider<bool, TOwner> instance for the value indicating whether the control is read-only. By default checks “readonly” attribute of scope element. Override GetIsReadOnly method to change the behavior.

Methods

public TOwner

Set(TValue value)

Sets the value. Also executes TriggerEvents.BeforeSet and TriggerEvents.AfterSet triggers.

public TOwner

SetRandom()

Sets the random value. For value generation uses randomization attributes, for example: RandomizeStringSettingsAttribute, RandomizeNumberSettingsAttribute, RandomizeIncludeAttribute, etc.

public TOwner

SetRandom(out TValue value)

Sets the random value and records it to value parameter. For value generation uses randomization attributes, for example: RandomizeStringSettingsAttribute, RandomizeNumberSettingsAttribute, RandomizeIncludeAttribute, etc.

public TOwner

SetRandom(Action<TValue> callback)

Sets the random value and invokes callback. For value generation uses randomization attributes, for example: RandomizeStringSettingsAttribute, RandomizeNumberSettingsAttribute, RandomizeIncludeAttribute, etc.

protected abstract void

SetValue(TValue value)

Sets the value.

Example

The example of CheckBox<TOwner> control that is inherited from EditableField<TValue, TOwner>:

[ControlDefinition("input[@type='checkbox']", ComponentTypeName = "checkbox")]
public class CheckBox<TOwner> : EditableField<bool, TOwner>
    where TOwner : PageObject<TOwner>
{
    public ValueProvider<bool, TOwner> IsChecked =>
        CreateValueProvider("checked state", () => Value);

    protected override bool GetValue() =>
        Scope.Selected;

    protected override void SetValue(bool value) =>
        Context.UIComponentAccessChainScopeCache.ExecuteWithin(() =>
        {
            if (GetValue() != value)
                OnClick();
        });

    public TOwner Check() =>
        Set(true);

    public TOwner Uncheck() =>
        Set(false);
}

Usage

string textFieldValue;

Go.To<SomePage>()
    .SomeTextField.Set("some value") // Set the value to the field.
    .SomeTextField.Should.Equal("some value") // Verify the field value.
    .SomeTextField.SetRandom(out textFieldValue) // Set the random value to the field.
    .SomeTextField.Should.Equal(textFieldValue) // Verify the field value.
    .SomeNumberField.Set(10); // Set the value to the field.

EditableTextField

Represents the editable text field control.

To set a value, executes an associated with the component ValueSetBehaviorAttribute that is SetsValueUsingClearAndTypeBehaviorsAttribute by default. To get a value, executes an associated with the component ValueGetBehaviorAttribute that is GetsValueFromValueAttribute by default.

Inherited from EditableField.

Syntax

[GetsValueFromValue]
[SetsValueUsingClearAndTypeBehaviors]
[ClearsValueUsingClearMethod]
[TypesTextUsingSendKeys]
public class EditableTextField<TValue, TOwner> : EditableField<TValue, TOwner>, IClearable
    where TOwner : PageObject<TOwner>

Methods

public TOwner

Type(string value)

Types (appends) the specified text value. Executes an associated with the component TextTypeBehaviorAttribute that is TypesTextUsingSendKeysAttribute by default. Also executes TriggerEvents.BeforeSet and TriggerEvents.AfterSet triggers.

public TOwner

Clear()

Clears the value. Executes an associated with the component ValueClearBehaviorAttribute that is ClearsValueUsingClearMethodAttribute by default. Also executes TriggerEvents.BeforeSet and TriggerEvents.AfterSet triggers.

UIComponent<TOwner> and IUIComponent<TOwner> have the following methods that allow a finding of controls dynamically:

public TControl Find<TControl>(params Attribute[] attributes)
    where TControl : Control<TOwner>;

public TControl Find<TControl>(string name, params Attribute[] attributes)
    where TControl : Control<TOwner>;

public ControlList<TControl, TOwner> FindAll<TControl>(params Attribute[] attributes)
    where TControl : Control<TOwner>;

public ControlList<TControl, TOwner> FindAll<TControl>(string name, params Attribute[] attributes)
    where TControl : Control<TOwner>;

Find - creates a control of the specified TControl type, optionally with name and additional attributes, that is a descendant of the current component. The control’s element will be found using either FindAttribute specified in attributes parameter, or the default/applied FindAttribute associated with the TControl type.

FindAll - creates a control list of the specified TControl type, optionally with name and additional attributes, that are descendants of the current component. Use ControlDefinitionAttribute to specialize the control element definition, instead of FindAttribute that doesn’t utilize here.

Usage

The methods can be used directly in tests:

Go.To<SomePage>()
    .Find<H1<SomePage>>().Should.Equal("Some Title")
    .FindAll<TextInput<SomePage>>().Should.HaveCount(4);

But it is recommended to use them inside page object methods, because the basic usage purpose of these methods is to allow a search of control by dynamic identifier/parameter.

public TextInput<_> FindTextInputByLabel(string label) =>
    Find<TextInput<_>>(new FindByLabelAttribute(label));

Input

Represents the input control (<input>). Default search is performed by the label.

Inherited from EditableTextField.

Syntax

[ControlDefinition("input[not(@type) or (@type!='button' and @type!='submit' and @type!='reset')]", ComponentTypeName = "input")]
[FindByLabel]
public class Input<TValue, TOwner> : EditableTextField<TValue, TOwner>
    where TOwner : PageObject<TOwner>

Properties

public ValueProvider<string, TOwner>

Placeholder { get; }

Gets the ValueProvider<string, TOwner> of the placeholder DOM property.

public ValueProvider<string, TOwner>

Pattern { get; }

Gets the ValueProvider<string, TOwner> of the pattern DOM property.

TextInput

Represents the text input control (<input type="text">). Default search is performed by the label. Handles any input element with type="text" or without the defined type attribute.

Inherited from Input.

Supports [Format] and [RandomizeStringSettings] settings attributes.

Syntax

[ControlDefinition("input[@type='text' or not(@type)]", ComponentTypeName = "text input")]
public class TextInput<TOwner> : Input<string, TOwner>
    where TOwner : PageObject<TOwner>

Example

<input type="text" id="first-name">
using _ = SamplePage;

public class SamplePage : Page<_>
{
    [FindById]
    public TextInput<_> FirstName { get; private set; }
}
Go.To<SamplePage>()
    .FirstName.Set("some text")
    .FirstName.Should.Equal("some text")
    .FirstName.Clear()
    .FirstName.Should.BeEmpty();

PasswordInput

Represents the password input control (<input type="password">). Default search is performed by the label.

Inherited from Input.

Supports [Format] and [RandomizeStringSettings] settings attributes.

Syntax

[ControlDefinition("input[@type='password']", ComponentTypeName = "password input")]
public class PasswordInput<TOwner> : Input<string, TOwner>
    where TOwner : PageObject<TOwner>

Example

<input type="password">
using _ = SamplePage;

public class SamplePage : Page<_>
{
    [FindFirst]
    public PasswordInput<_> Password { get; private set; }
}
string password;

Go.To<SamplePage>()
    .Password.SetRandom(out password)
    .Password.Should.Equal(password);

NumberInput

Represents the number input control. Default search is performed by the label. Handles any input element with type="number", type="text" or without the defined type attribute.

Inherited from Input.

Supports [Format], [Culture] and [RandomizeNumberSettings] settings attributes.

Syntax

[ControlDefinition("input[@type='number' or @type='text' or not(@type)]", ComponentTypeName = "number input")]
public class NumberInput<TOwner> : Input<decimal?, TOwner>
    where TOwner : PageObject<TOwner>

Example

<input type="number" id="amount">
using _ = SamplePage;

public class SamplePage : Page<_>
{
    [FindById]
    public NumberInput<_> Amount { get; private set; }
}
Go.To<SamplePage>()
    .Amount.Should.BeNull()
    .Amount.Set(25)
    .Amount.Should.Equal(25)
    .Amount.Should.BeInRange(20, 30);

DateInput

Represents the date input control. Default search is performed by the label. Handles any input element with type="date", type="text" or without the defined type attribute.

The default format is "d" (short date pattern, e.g., 6/15/2009).

Inherited from Input.

Syntax

[ControlDefinition("input[@type='text' or @type='date' or not(@type)]", ComponentTypeName = "date input")]
[Format("d")]
public class DateInput<TOwner> : Input<DateTime?, TOwner>
    where TOwner : PageObject<TOwner>

Example

<input type="date" id="birthday">
using _ = SamplePage;

public class SamplePage : Page<_>
{
    [FindById]
    public DateInput<_> Birthday { get; private set; }
}
DateTime birthday = new DateTime(1980, 7, 9);

Go.To<SamplePage>()
    .Birthday.Should.BeNull()
    .Birthday.Set(birthday)
    .Birthday.Should.Equal(birthday);

TimeInput

Represents the time input control. Default search is performed by the label. Handles any input element with type="time", type="text" or without the defined type attribute.

Inherited from Input.

Supports [Format] and [Culture] settings attributes.

Syntax

[ControlDefinition("input[@type='text' or @type='time' or not(@type)]", ComponentTypeName = "time input")]
public class TimeInput<TOwner> : Input<TimeSpan?, TOwner>
    where TOwner : PageObject<TOwner>

Example

<input type="time" id="eventTime">
using _ = SamplePage;

public class SamplePage : Page<_>
{
    [FindById(TermCase.Camel)]
    public TimeInput<_> EventTime { get; private set; }
}
TimeSpan time = TimeSpan.FromHours(11.5);

Go.To<SamplePage>()
    .EventTime.Should.BeNull()
    .EventTime.Set(time)
    .EventTime.Should.Equal(time);

LocalDateTimeInput

Represents the local date/time input control (<input type="datetime-local">). Default search is performed by the label.

The default format is "yyyy-MM-ddTHH:mm".

Inherited from Input.

Syntax

[ControlDefinition("input[@type='datetime-local']", ComponentTypeName = "local date/time input")]
[Format("g")]
[ValueGetFormat("yyyy-MM-ddTHH:mm")]
[ValueSetFormat("yyyy-MM-ddTHH:mm")]
[SetsValueUsingScript]
public class LocalDateTimeInput<TOwner> : Input<DateTime?, TOwner>
    where TOwner : PageObject<TOwner>

Example

<input type="datetime-local" id="time">
using _ = SamplePage;

public class SamplePage : Page<_>
{
    [FindById]
    public DateInput<_> Time { get; private set; }
}
DateTime someTime = new DateTime(2023, 7, 9, 17, 59, 0);

Go.To<SamplePage>()
    .Birthday.Set(someTime)
    .Birthday.Should.Equal(someTime);

FileInput

Represents the file input control (<input type="file">). Default search is performed by the label.

Inherited from Input.

Supports [Format] settings attribute.

Syntax

[ControlDefinition("input[@type='file']", Visibility = Visibility.Any, ComponentTypeName = "file input")]
[SetsValueUsingSendKeys]
[ClearsValueUsingClearMethodOrScript]
public class FileInput<TOwner> : Input<string, TOwner>
    where TOwner : PageObject<TOwner>

Properties

public ValueProvider<string, TOwner>

Accept { get; }

Gets the ValueProvider<string, TOwner> of the accept DOM property.

Example

<input type="file" id="some-file">
using _ = SamplePage;

public class SamplePage : Page<_>
{
    [FindById]
    public FileInput<_> SomeFile { get; private set; }
}
Go.To<SamplePage>()
    .SomeFile.Set(@"d:\some\file\path.txt");

HiddenInput

Represents the hidden input control (<input type="hidden">). Default search finds the first occurring <input type="hidden"> element.

Inherited from Input.

Supports [Format] and [Culture] settings attributes.

Syntax

[ControlDefinition("input[@type='hidden']", Visibility = Visibility.Hidden, ComponentTypeName = "hidden input")]
[FindFirst]
public class HiddenInput<TValue, TOwner> : Input<TValue, TOwner>
    where TOwner : PageObject<TOwner>
public class HiddenInput<TOwner> : HiddenInput<string, TOwner>
    where TOwner : PageObject<TOwner>

Example

<input type="hidden" id="some-hidden" value="somedata">
using _ = SamplePage;

public class SamplePage : Page<_>
{
    public HiddenInput<_> SomeHidden { get; private set; }
}
Go.To<SamplePage>()
    .SomeHidden.Get(out string hiddenValue) // Gets value and sets to variable.
    .SomeHidden.Should.Equal("somedata"); // Verifies value.

CheckBox

Represents the checkbox control (<input type="checkbox">). Default search is performed by the label.

Inherited from EditableField.

Syntax

[ControlDefinition("input[@type='checkbox']", ComponentTypeName = "checkbox", IgnoreNameEndings = "Checkbox,CheckBox,Option")]
[FindByLabel]
public class CheckBox<TOwner> : EditableField<bool, TOwner>, ICheckable<TOwner>
    where TOwner : PageObject<TOwner>

Properties

public ValueProvider<bool, TOwner>

IsChecked { get; }

Gets the ValueProvider<bool, TOwner> instance of the checked state value.

Methods

public TOwner

Check()

Checks the control. Also executes TriggerEvents.BeforeSet and TriggerEvents.AfterSet triggers.

public TOwner

Uncheck()

Unchecks the control. Also executes TriggerEvents.BeforeSet and TriggerEvents.AfterSet triggers.

Example

<label class="checkbox-inline">
  <input type="checkbox" value="option1">Option 1
</label>
<label class="checkbox-inline">
  <input type="checkbox" value="option2" checked>Option 2
</label>
using _ = SamplePage;

public class SamplePage : Page<_>
{
    [FindByLabel]
    public CheckBox<_> Option1 { get; private set; }

    [FindByLabel]
    public CheckBox<_> Option2 { get; private set; }
}
Go.To<SamplePage>()
    .Option1.Check()
    .Option1.Should.BeChecked()
    .Option2.Uncheck()
    .Option2.Should.Not.BeChecked();

CheckBoxList

Represents the checkbox list control (a set of <input type="checkbox">). Default search is performed by the name. Specific checkbox items can be found by label or value. By default items are searched by label using FindItemByLabelAttribute. Use FindItemByValueAttribute to find items by value. Currently as a data type supports only enum (with [Flags]) types.

Inherited from EditableField.

Supports attributes: [FindItemByLabel], [FindItemByValue], [FindItemByParentContent], [FindItemByPrecedingSiblingContent], [FindItemByFollowingSiblingContent], [FindItemByRelativeElementContent], [Format], [Culture].

Syntax

[ControlDefinition("input[@type='checkbox']", ComponentTypeName = "checkbox list", IgnoreNameEndings = "CheckBoxes,CheckBoxList,CheckBoxGroup,Options,OptionGroup")]
[FindByName]
[FindItemByLabel]
public class CheckBoxList<TValue, TOwner> : OptionList<TValue, TOwner>
    where TOwner : PageObject<TOwner>

Methods

public TOwner

Check(T value)

Checks the checkbox by specified value. Also executes TriggerEvents.BeforeSet and TriggerEvents.AfterSet triggers.

public TOwner

Uncheck(T value)

Unchecks the checkbox by specified value. Also executes TriggerEvents.BeforeSet and TriggerEvents.AfterSet triggers.

Example

<label class="checkbox-inline">
    <input type="checkbox" name="options" value="OptionA">
    Option A
</label>
<label class="checkbox-inline">
    <input type="checkbox" name="options" value="OptionB">
    Option B
</label>
<label class="checkbox-inline">
    <input type="checkbox" name="options" value="OptionC">
    Option C
</label>
[Flags]
public enum SomeOptions
{
    None = 0,         // C#7: 0b0000
    OptionA = 1,      // C#7: 0b0001
    OptionB = 1 << 1, // C#7: 0b0010
    OptionC = 1 << 2  // C#7: 0b0100
}

Don’t forget to mark the enumeration with [Flags] attribute and specify proper numeric values.

using _ = SamplePage;

public class SamplePage : Page<_>
{
    [FindByName]
    public CheckBoxList<SomeOptions, _> Options { get; private set; }
}
Go.To<SamplePage>()
    .Options.Should.Equal(SomeOptions.None)
    .Options.Check(SomeOptions.OptionB | SomeOptions.OptionC)
    .Options.Should.Equal(SomeOptions.OptionB | SomeOptions.OptionC)
    .Options.Uncheck(SomeOptions.OptionB)
    .Options.Should.Equal(SomeOptions.OptionB)
    .Options.Should.Not.HaveChecked(SomeOptions.OptionC);

RadioButton

Represents the radio button control (<input type="radio">). Default search is performed by the label.

Inherited from Field.

Syntax

[ControlDefinition("input[@type='radio']", IgnoreNameEndings = "RadioButton,Radio,Button,Option", ComponentTypeName = "radio button")]
[FindByLabel]
public class RadioButton<TOwner> : Field<bool, TOwner>, ICheckable<TOwner>
    where TOwner : PageObject<TOwner>

Properties

public ValueProvider<bool, TOwner>

IsChecked { get; }

Gets the ValueProvider<bool, TOwner> of the value indicating whether the control is checked.

Methods

public TOwner

Check()

Checks the control. Also executes TriggerEvents.BeforeClick and TriggerEvents.AfterClick triggers.

Example

<label class="radio-inline">
  <input type="radio" name="radios" id="radio1"
         value="option1" checked> Option 1
</label>
<label class="radio-inline">
  <input type="radio" name="radios" id="radio2"
         value="option2"> Option 2
</label>
using _ = SamplePage;

public class SamplePage : Page<_>
{
    [FindById(TermCase.LowerMerged)]
    public RadioButton<_> Option1 { get; private set; }

    [FindById(TermCase.LowerMerged)]
    public RadioButton<_> Option2 { get; private set; }
}
Go.To<SamplePage>()
    .Option1.Should.BeChecked()
    .Option2.Check()
    .Option1.Should.BeUnchecked()
    .Option2.Should.BeChecked();

RadioButtonList

Represents the radio button list control (a set of <input type="radio">). Default search is performed by the name. Specific radio button items can be found by label or value. By default items are searched by label using FindItemByLabelAttribute. Use FindItemByValueAttribute to find items by value. As a data type supports enum, string, numeric and other types.

Inherited from EditableField.

Supports attributes: [FindItemByLabel], [FindItemByValue], [FindItemByParentContent], [FindItemByPrecedingSiblingContent], [FindItemByFollowingSiblingContent], [FindItemByRelativeElementContent], [Format], [Culture].

Syntax

[ControlDefinition("input[@type='radio']", IgnoreNameEndings = "RadioButtons,RadioButtonList,Radios,RadioGroup,Buttons,ButtonList,Options,OptionGroup", ComponentTypeName = "radio button list")]
[FindByName]
[FindItemByLabel]
public class RadioButtonList<TValue, TOwner> : OptionList<TValue, TOwner>
    where TOwner : PageObject<TOwner>

Methods

public TOwner

ToggleRandom()

Sets random unselected value.

Example #1: Using Enum

<label class="radio-inline">
    <input type="radio" name="options" value="OptionA">
    Option A
</label>
<label class="radio-inline">
    <input type="radio" name="options" value="OptionB">
    Option B
</label>
<label class="radio-inline">
    <input type="radio" name="options" value="OptionC">
    Option C
</label>
public enum SomeOption
{
    OptionA,
    OptionB,
    OptionC
}
using _ = SamplePage;

public class SamplePage : Page<_>
{
    [FindByName]
    public RadioButtonList<SomeOption?, _> Options { get; private set; }
}
Go.To<SamplePage>()
    .Options.Should.Equal(null)
    .Options.Set(SomeOptions.OptionB)
    .Options.Should.Equal(SomeOptions.OptionB);

Example #2: Using String

<label class="radio-inline">
    <input type="radio" name="options" value="OptionA">
    Option A
</label>
<label class="radio-inline">
    <input type="radio" name="options" value="OptionB">
    Option B
</label>
<label class="radio-inline">
    <input type="radio" name="options" value="OptionC">
    Option C
</label>
using _ = SamplePage;

public class SamplePage : Page<_>
{
    [FindByName]
    [FindItemByValue]
    public RadioButtonList<string, _> Options { get; private set; }
}
Go.To<SamplePage>()
    .Options.Should.Equal(null)
    .Options.Set("OptionB")
    .Options.Should.Equal("OptionB");

EmailInput

Represents the email input control (input type="email"). Default search is performed by the label.

Inherited from Input.

Supports [Format] and [RandomizeStringSettings] settings attributes.

Syntax

[ControlDefinition("input[@type='email']", ComponentTypeName = "email input")]
public class EmailInput<TOwner> : Input<string, TOwner>
    where TOwner : PageObject<TOwner>

Example

<input type="email" id="email">
using _ = SamplePage;

public class SamplePage : Page<_>
{
    [FindById]
    public EmailInput<_> Email { get; private set; }
}
Go.To<SamplePage>()
    .Email.Set("some@mail.com");

TelInput

Represents the telephone number input control (<input type="tel">). Default search is performed by the label.

Inherited from Input.

Supports [Format] and [RandomizeStringSettings] settings attributes.

Syntax

[ControlDefinition("input[@type='tel']", ComponentTypeName = "telephone input")]
public class TelInput<TOwner> : Input<string, TOwner>
    where TOwner : PageObject<TOwner>

Example

<input type="tel" id="phone">
using _ = SamplePage;

public class SamplePage : Page<_>
{
    [FindById]
    public TelInput<_> Phone { get; private set; }
}
Go.To<SamplePage>()
    .Phone.Set("+1234567890");

UrlInput

Represents the URL input control (<input type="url">). Default search is performed by the label.

Inherited from Input.

Supports [Format] and [RandomizeStringSettings] settings attributes.

Syntax

[ControlDefinition("input[@type='url']", ComponentTypeName = "URL input")]
public class UrlInput<TOwner> : Input<string, TOwner>
    where TOwner : PageObject<TOwner>

Example

<input type="url" id="some-url">
using _ = SamplePage;

public class SamplePage : Page<_>
{
    [FindById]
    public UrlInput<_> SomeUrl { get; private set; }
}
Go.To<SamplePage>()
    .SomeUrl.Set("http://someurl.com");

SearchInput

Represents the search input control (<input type="search">). Default search is performed by the label.

Inherited from Input.

Supports [Format] and [RandomizeStringSettings] settings attributes.

Syntax

[ControlDefinition("input[@type='search']", ComponentTypeName = "search input")]
public class SearchInput<TOwner> : Input<string, TOwner>
    where TOwner : PageObject<TOwner>

Example

<input type="search" id="search-query">
using _ = SamplePage;

public class SamplePage : Page<_>
{
    [FindById]
    public SearchInput<_> SearchQuery { get; private set; }
}
Go.To<SamplePage>()
    .SearchQuery.Set("some text");

TextArea

Represents the text area control (<textarea>). Default search is performed by the label.

Inherited from EditableTextField.

Syntax

[ControlDefinition("textarea", IgnoreNameEndings = "TextArea", ComponentTypeName = "text area")]
[FindByLabel]
public class TextArea<TOwner> : EditableTextField<string, TOwner>
    where TOwner : PageObject<TOwner>

Properties

public ValueProvider<string, TOwner>

Placeholder { get; }

Gets the ValueProvider<string, TOwner> of the placeholder DOM property.

Example

<textarea name="description">
</textarea>
using _ = SamplePage;

public class SamplePage : Page<_>
{
    [FindByName]
    public TextArea<_> Description { get; private set; }
}
Go.To<SamplePage>()
    .Description.Set("some")
    .Description.Type(" text")
    .Description.Should.Equal("some text")
    .Description.Clear()
    .Description.Should.BeEmpty();

ContentEditor

Represents the content editor control (any element with contenteditable='true' or contenteditable='' attribute). This control is good to use for WYSIWYG editors.

Inherited from EditableTextField.

Syntax

[ControlDefinition("*[@contenteditable='' or @contenteditable='true']", ComponentTypeName = "content editor")]
[GetsValueFromContent]
public class ContentEditor<TOwner> : EditableTextField<string, TOwner>
    where TOwner : PageObject<TOwner>

Example

Check out Custom Rich Text Editor Based on contenteditable.

FrameWrappedContentEditor

Represents the frame-wrapped content editor control. This control is good to use for iframe-based WYSIWYG editors.

Inherited from EditableTextField.

Syntax

[ControlDefinition("iframe", ComponentTypeName = "frame-wrapped content editor")]
public class FrameWrappedContentEditor<TOwner> : EditableTextField<string, TOwner>
    where TOwner : PageObject<TOwner>

Represents the select control (<select>). Default search is performed by the label. Option selection is configured via SelectOptionBehaviorAttribute. Possible selection behavior attributes are: SelectByTextAttribute, SelectByValueAttribute, SelectByLabelAttribute and SelectByAttribute. Default option selection is performed by text using SelectByTextAttribute.

Inherited from EditableField.

Supports attributes: [SelectsOptionByText], [SelectsOptionByValue], [SelectsOptionByLabelAttribute], [SelectsOptionByAttribute], [Format], [Culture].

Syntax

[ControlDefinition("select", IgnoreNameEndings = "Select", ComponentTypeName = "select")]
[FindByLabel]
[SelectsOptionByText]
public class Select<TValue, TOwner> : EditableField<TValue, TOwner>
    where TOwner : PageObject<TOwner>

Properties

public ControlList<Option<T, TOwner>, TOwner>

Options { get; }

Gets the options’ ControlList<TItem, TOwner> instance.

public Option<T, TOwner>

SelectedOption { get; }

Gets the selected option.

public ValueProvider<int, TOwner>

SelectedIndex { get; }

Gets the index of the selected option.

There are different approaches to configure Select control using different types of data.

Methods

public Option<TValue, TOwner>

GetOption(TValue value)

Gets the option by the associated value.

Example #1: Select Using Enum

<select id="brand">
  <option value="">--select--</option>
  <option value="volvo">Volvo</option>
  <option value="saab">Saab</option>
  <option value="mercedes">Mercedes</option>
  <option value="audi">Audi</option>
</select>

The above select can be described with the following enum:

public enum CarBrand
{
    [Term("--select--")]
    None,
    Volvo,
    Saab,
    Mercedes,
    Audi
}

Select By Text

using _ = SamplePage;

public class SamplePage : Page<_>
{
    [FindById]
    public Select<CarBrand, _> Brand { get; private set; }
}
Go.To<SamplePage>()
    .Brand.Should.Equal(CarBrand.None)
    .Brand.Set(CarBrand.Audi)
    .Brand.Should.Equal(CarBrand.Audi);

Select By Value

You just need to mark the select property with [SelectByValue] attribute and optionally set settings like Case and Format.

using _ = SamplePage;

public class SamplePage : Page<_>
{
    [FindById]
    [SelectByValue(TermCase.Lower)]
    public Select<CarBrand, _> Brand { get; private set; }
}

TermCase.Lower is defined in SelectByValueAttribute because option values are lowercase in this example (e.g. “volvo”).

Example #2: Select Using String

<select id="brand">
  <option value="">--select--</option>
  <option value="volvo">Volvo</option>
  <option value="saab">Saab</option>
  <option value="mercedes">Mercedes</option>
  <option value="audi">Audi</option>
</select>

Don’t pass data generic type argument to use string variant of control, simply use Select<_> (or alternatively Select<string, _>).

using _ = SamplePage;

public class SamplePage : Page<_>
{
    [FindById]
    public Select<_> Brand { get; private set; }
}
Go.To<SamplePage>()
    .Brand.Set("Audi")
    .Brand.Should.Equal("Audi");

Example #3: Select Using Int

It is also possible to select an option by int and other types. The following sample shows how to select using int type together with the formatting.

<select id="priority">
  <option value="1">Priority 1</option>
  <option value="2">Priority 2</option>
  <option value="3">Priority 3</option>
  <option value="4">Priority 4</option>
  <option value="5">Priority 5</option>
</select>
using _ = SamplePage;

public class SamplePage : Page<_>
{
    [FindById]
    [Format("Priority {0}")]
    public Select<int, _> Priority { get; private set; }
}
Go.To<SamplePage>()
    .Priority.Set(3)
    .Priority.Should.Equal(3);

Option

Represents the option control (<option>). Default search finds the first occurring <option> element.

Inherited from Field.

Syntax

[ControlDefinition("option", IgnoreNameEndings = "Option", ComponentTypeName = "option")]
[FindFirst]
public class Option<TValue, TOwner> : Field<TValue, TOwner>
    where TOwner : PageObject<TOwner>

Properties

public ValueProvider<bool, TOwner>

IsSelected { get; }

Gets the ValueProvider<bool, TOwner> instance for the value indicating whether the component is selected.

Methods

public TOwner

Select()

Selects the option. Also executes TriggerEvents.BeforeClick and TriggerEvents.AfterClick triggers.

Represents the button control. Default search is performed by the content and value (button by content text and input by value attribute). Handles any input element with type="button", type="submit", type="reset" or button element.

<button>Save</button>

or

<input type="button" value="Save">

Supports [GoTemporarily] settings attribute.

Button Control

using _ = SamplePage;

public class SamplePage : Page<_>
{
    public Button<_> Save { get; private set; }
}
Go.To<SamplePage>()
    .Save.Click();

Button Delegate

It is recommended to use Button delegate as it simplifies the use by eliminating Click and ClickAndGo methods.

using _ = SamplePage;

public class SamplePage : Page<_>
{
    public ButtonDelegate<_> Save { get; private set; }
}
Go.To<SamplePage>()
    .Save();

As it is a delegate type, the use of Should, Content and IsEnabled properties should be performed like methods (extensions), e.g. Save.Should().BePresent().

Navigation

It is possible to pass another generic argument of PageObject type, meaning that after the click on the button the navigation to this PageObject is performed. It works the same way for the control and delegate.

using _ = SamplePage1;

public class SamplePage1 : Page<_>
{
    public ButtonDelegate<SamplePage2, _> Save { get; private set; }
}
using _ = SamplePage2;

public class SamplePage2 : Page<_>
{
    public Button<SamplePage1, _> GoBack { get; private set; }
}
Go.To<SamplePage1>()
    .Save()
    .GoBack.ClickAndGo();

Note that Save delegate property is used as the method that returns the instance of SamplePage2 class. But for GoBack property it is required to call ClickAndGo method as it is a property of Button class type.

Methods

public static TNavigateTo

ClickAndGo<TNavigateTo, TOwner>(this INavigable<TNavigateTo, TOwner> navigableControl)

where TNavigateTo : PageObject<TNavigateTo> where TOwner : PageObject<TOwner>

Clicks the control and performs the navigation to the page object of TNavigateTo type.

Represents the <a> link control. Default search is performed by the content.

<a href="/items/create">Create</a>

Supports [GoTemporarily] settings attribute.

Link Control

using _ = SamplePage;

public class SamplePage : Page<_>
{
    public Link<_> Create { get; private set; }
}
Go.To<SamplePage>()
    .Create.Click();

Link Delegate

It is recommended to use Link delegate as it simplifies the usage by refusing Click and ClickAndGo methods.

using _ = SamplePage;

public class SamplePage : Page<_>
{
    public LinkDelegate<_> Create { get; private set; }
}
Go.To<SamplePage>()
    .Create();

As it is a delegate type, the use of Should, Content and IsEnabled properties should be performed like methods (extensions), e.g. Create.Should().BePresent().

Navigation

It is possible to pass another generic argument of PageObject type, meaning that after the click the navigation to this PageObject should be performed. Works the same way for the control and delegate.

using _ = ItemsPage;

public class ItemsPage : Page<_>
{
    public LinkDelegate<ItemCreationPage, _> Create { get; private set; }
}
using _ = ItemCreationPage;

public class ItemCreationPage : Page<_>
{
    public Link<ItemsPage, _> GoBack { get; private set; }
}
Go.To<SamplePage1>()
    .Create()
    .GoBack.ClickAndGo();

Note that Create delegate property is being used as the method that returns the instance of ItemCreationPage class. But for GoBack property it is needed to call ClickAndGo method as it is a property of Link class type.

Methods

public static TNavigateTo

ClickAndGo<TNavigateTo, TOwner>(this INavigable<TNavigateTo, TOwner> navigableControl)

where TNavigateTo : PageObject<TNavigateTo> where TOwner : PageObject<TOwner>

Clicks the control and performs the navigation to the page object of TNavigateTo type.

Represents any HTML element. Default search finds the first occurring element.

<div id="open-button">Open</div>

Supports [GoTemporarily] settings attribute.

Clickable Control

using _ = SamplePage;

public class SamplePage : Page<_>
{
    [FindById("open-button")]
    public Clickable<_> OpenButton { get; private set; }
}
Go.To<SamplePage>()
    .OpenButton.Click();

Clickable Delegate

using _ = SamplePage;

public class SamplePage : Page<_>
{
    [FindById("open-button")]
    public ClickableDelegate<_> Open { get; private set; }
}
Go.To<SamplePage>()
    .Open();

As it is a delegate type, the use of Should, Content and IsEnabled properties should be performed like methods (extensions), e.g. Open.Should().BePresent().

Navigation

It is possible to pass another gereric argument of PageObject type, meaning that after the click the navigation to this PageObject should be performed. Works the same way for the control and delegate.

using _ = ItemsPage;

public class ItemsPage : Page<_>
{
    public ClickableDelegate<ItemPage, _> Open { get; private set; }
}
using _ = ItemPage;

public class ItemPage : Page<_>
{
    public Clickable<ItemsPage, _> GoBack { get; private set; }
}
Go.To<SamplePage1>()
    .Open()
    .GoBack.ClickAndGo();

Note that Open delegate property is being used as the method that returns the instance of ItemPage class. But for GoBack property it is needed to call ClickAndGo method as it is a property of Clickable class type.

Methods

public static TNavigateTo

ClickAndGo<TNavigateTo, TOwner>(this INavigable<TNavigateTo, TOwner> navigableControl)

where TNavigateTo : PageObject<TNavigateTo> where TOwner : PageObject<TOwner>

Clicks the control and performs the navigation to the page object of TNavigateTo type.

Represents the image control (<img>). Default search is performed by alt attribute using FindByAltAttribute.

Syntax

[ControlDefinition("img")]
public class Image<TOwner> : Control<TOwner>
    where TOwner : PageObject<TOwner>

Properties

public ValueProvider<string, TOwner>

Source { get; }

Gets the ValueProvider<string, TOwner> instance for the src attribute.

Component.Source.Should.EndWith("/images/300x50.png");
public ValueProvider<bool, TOwner>

IsLoaded { get; }

Gets the ValueProvider<bool, TOwner> instance for the value indicating whether the image file is loaded.

Component.IsLoaded.Should.BeTrue();

Example

<img id="some-image" src="/assets/images/300x50.png"
     alt="Some image">
Some image
using _ = SamplePage;

public class SamplePage : Page<_>
{
    [FindById]
    public Image<_> SomeImage { get; private set; }
}
Go.To<SamplePage>()
    .SomeImage.Source.Should.EndWith("/images/300x50.png")
    .SomeImage.IsLoaded.Should.BeTrue();

Represents the table control (<table>). Default search finds the first occurring <table> element.

Inherited from Control.

Syntax

[ControlDefinition("table", IgnoreNameEndings = "Table")]
public class Table<THeader, TRow, TOwner> : Control<TOwner>
    where THeader : TableHeader<TOwner>
    where TRow : TableRow<TOwner>
    where TOwner : PageObject<TOwner>
public class Table<TRow, TOwner> : Table<TableHeader<TOwner>, TRow, TOwner>
    where TRow : TableRow<TOwner>
    where TOwner : PageObject<TOwner>
public class Table<TOwner> : Table<TableHeader<TOwner>, TableRow<TOwner>, TOwner>
    where TOwner : PageObject<TOwner>

Properties

public ControlList<THeader, TOwner>

Headers { get; }

Gets the headers list.

Table.Headers.Should.ContainHavingContent(TermMatch.Equals, "Name", "Amount");
public TableRowList<TRow, TOwner>

Rows { get; }

Gets the rows list.

Table.Rows.Should.HaveCount(2);
Table.Rows[0].Should.BePresent();
Table.Rows[x => x.Content == "some content"].Click();

Example

<table id="products" class="table">
    <thead>
        <tr>
            <th>Name</th>
            <th>Amount</th>
            <th>Actions</th>
        </tr>
    </thead>
    <tbody>
        <tr>
            <td>Item 1</td>
            <td>5</td>
            <td><button>Delete</button></td>
        </tr>
        <tr>
            <td>Item 2</td>
            <td>10</td>
            <td><button>Delete</button></td>
        </tr>
    </tbody>
</table>
Name Amount Actions
Item 1 5
Item 2 10
using _ = SamplePage;

public class SamplePage : Page<_>
{
    [FindById]
    public Table<ProductTableRow, _> Products { get; private set; }

    public class ProductTableRow : TableRow<_>
    {
        public Text<_> Name { get; private set; }

        public Number<_> Amount { get; private set; }

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

Default search of the properties of type Content and inherited (e.g. Name and Amount) that are declared in the class inherited from TableRow is performed by the column header.

Go.To<SamplePage>()
    .Products.Rows[x => x.Name == "Item 1"].Amount.Should.Equal(5)
    .Products.Rows[x => x.Name == "Item 1"].Delete()
    .Products.Rows[x => x.Name == "Item 1"].Should.Not.BePresent();

Represents any HTML element containing content. Default search finds the first occurring element (except the ones declared in a class inherited from TableRow, then by column header).

Enum Content

The following sample checks the status of span element.

<span id="status">Success</span>

For example, span can contain “Success” or “Failure” status. Available options can be described with enum:

public enum Status
{
    Success,
    Failure
}
using _ = SamplePage;

public class SamplePage : Page<_>
{
    [FindById]
    public Content<Status, _> Status { get; private set; }
}
Go.To<SamplePage>()
    .Status.Should.Equal(Status.Success);

Supports [Format] and [Culture] settings attributes.

Text

Represents any element containing text content. Default search finds the first occurring element.

<p id="description">Some description text</p>
using _ = SamplePage;

public class SamplePage : Page<_>
{
    [FindById]
    public Text<_> Description { get; private set; }
}
Go.To<SamplePage>()
    .Description.Should.BePresent()
    .Description.Should.Contain("description text");

Supports [Format] settings attribute.

H1-H6

Represents the <h1>-<h6> heading elements. Default search finds the first occurring element.

<h1>Some header</h1>
<h2>Another header</h2>
using _ = SamplePage;

public class SamplePage : Page<_>
{
    public H1<_> Header { get; private set; }

    public H2<_> SecondaryHeader { get; private set; }
}
Go.To<SamplePage>()
    .Header.Should.Equal("Some header")
    .SecondaryHeader.Should.Contain("Another");

Supports [Format] settings attribute.

Label

Represents the <label> element. Default search is performed by the content.

<label for="first-name">First Name</p>
using _ = SamplePage;

public class SamplePage : Page<_>
{
    public Label<_> FirstNameLabel { get; private set; }
}
Go.To<SamplePage>()
    .FirstNameLabel.Should.Equal("First Name")
    .FirstNameLabel.Attributes.For.Should.Equal("first-name");

Supports [Format] settings attribute.

Number

Represents any element containing number content. Default search finds the first occurring element.

<span id="amount">15</span>
using _ = SamplePage;

public class SamplePage : Page<_>
{
    [FindById]
    public Number<_> Amount { get; private set; }
}
Go.To<SamplePage>()
    .Amount.Should.Equal(15);

Supports [Format] and [Culture] settings attributes.

Currency

Represents any element containing currency content. Default search finds the first occurring element. The default format is "C2" (e.g. $123.45).

<span id="price">$1,054.50</span>
using _ = SamplePage;

public class SamplePage : Page<_>
{
    [FindById]
    public Currency<_> Price { get; private set; }
}
Go.To<SamplePage>()
    .Price.Should.Equal(1054.50m);

Supports [Format] and [Culture] settings attributes.

Date

Represents any element containing date content. Default search finds the first occurring element. The default format is "d" (short date pattern, e.g. 6/15/2009).

<span id="date">6/15/2009</span>
using _ = SamplePage;

public class SamplePage : Page<_>
{
    [FindById]
    public Date<_> Date { get; private set; }
}
Go.To<SamplePage>()
    .Date.Should.Equal(new DateTime(2016, 6, 15));

Supports [Format] and [Culture] settings attributes.

Time

Represents any element containing time content. Default search finds the first occurring element.

<span id="time-of-day">2:45 PM</span>
using _ = SamplePage;

public class SamplePage : Page<_>
{
    [FindById]
    [Format("h:mm tt")]
    public Time<_> TimeOfDay { get; private set; }
}
Go.To<SamplePage>()
    .TimeOfDay.Should.Equal(new TimeSpan(14, 45, 0));

Supports [Format] and [Culture] settings attributes.

DateTime

Represents any element containing date and time content. Default search finds the first occurring element. The default format is "g" (general date/time pattern (short time), e.g. 6/15/2009 1:45 PM).

<span id="date-time">5/15/2016 1:45 PM</span>
using _ = SamplePage;

public class SamplePage : Page<_>
{
    [FindById]
    public DateTime<_> DateTime { get; private set; }
}
Go.To<SamplePage>()
    .DateTime.Should.Equal(new DateTime(2016, 5, 15, 13, 45, 0));

Supports [Format] and [Culture] settings attributes.

There are several classes/controls for interaction with the list of controls.

ControlList

Represents the list of controls of TItem type.

Syntax

public class ControlList<TItem, TOwner> : UIComponentPart<TOwner>, ISupportsMetadata, IEnumerableProvider<TItem, TOwner>, IClearsCache
    where TItem : Control<TOwner>
    where TOwner : PageObject<TOwner>

Properties

public ValueProvider<int, TOwner>

Count { get; }

Gets the ValueProvider<int, TOwner> instance for the controls count.

int count = Items.Count.Value;
Items.Count.Should.Equal(5);
public ValueProvider<IEnumerable<string>, TOwner>

Contents { get; }

Gets the ValueProvider<IEnumerable<string>, TOwner> instance for the controls contents.

Items.Contents.Should.EqualSequence("Item 1", "Item 2");
Items.Contents.Should.Contain("Item 1");
public DataVerificationProvider<IEnumerable<TItem>, TOwner>

Should { get; }

Gets the verification provider that gives a set of verification extension methods.

Items.Should.HaveCount(5);
Items.Should.BeEmpty();
Items.Should.BeEquivalent("Item 1", "Item 2");

Indexers

public TItem this

[int index] { get; }

Gets the control at the specified index.

Items[0].Should.BePresent();
Items[1].Should.Equal(5);
Items[2].Content.Should.Equal("Item 1");
public TItem this

[Expression<Func<TItem, bool>> predicateExpression] { get; }

Gets the control that matches the conditions defined by the specified predicate expression.

Items[x => x.Title == "Product 1"].Should.BePresent();
Items[x => x.Content == "Some content"].Should.Not.BePresent();

Methods

public ValueProvider<int, TOwner>

IndexOf(Expression<Func<TItem, bool>> predicateExpression)

Searches for the item that matches the conditions defined by the specified predicate expression and returns the zero-based index of the first occurrence.

public TItem

GetByXPathCondition(string itemName, string xPathCondition)

Gets the control that matches the specified XPath condition.

Items.GetByXPathCondition("Having some attribute", "@some-attr='some value'");
public ValueProvider<IEnumerable<TData>, TOwner>

SelectData<TData>(Expression<Func<TItem, TData>> selector)

Selects the specified data (property) set of each control. Data can be a sub-control, an instance of ValueProvider<TData, TOwner>, etc.

Example

<div>
    <div class="product">
        <h5>Product 1</h5>
        <span class="amount">5</span>
    </div>
    <div class="product">
        <h5>Product 2</h5>
        <span class="amount">10</span>
    </div>
</div>
Product 1
5
Product 2
10
using _ = SamplePage;

public class SamplePage : Page<_>
{
    public ControlList<ProductItem, _> Products { get; private set; }

    [ControlDefinition("div", ContainingClass = "product")]
    public class ProductItem : Control<_>
    {
        public H5<_> Title { get; private set; }

        [FindByClass]
        public Number<_> Amount { get; private set; }
    }
}
Go.To<SamplePage>()
    .Products.Count.Should.Equal(2)
    .Products[0].Title.Should.Equal("Product 1")
    .Do(_ => _.Products[1], x =>
    {
        x.Title.Should.Equal("Product 2");
        x.Amount.Should.Equal(10);
    })
    .Products[x => x.Title == "Product 1"].Amount.Should.Equal(5)
    .Products[x => x.Title == "Product 3"].Should.Not.BePresent()
    .Products.IndexOf(x => x.Title == "Product 2").Should.Equal(1)
    .SelectData(x => x.Title).Should.EqualSequence("Product 1", "Product 2");

ItemsControl

Represents the items control (a control containing a set of any control of TItem type). Default search finds the first occurring element.

Inherited from Control.

Syntax

[ControlDefinition(ComponentTypeName = "items control", IgnoreNameEndings = "ItemsControl,Control")]
public class ItemsControl<TItem, TOwner> : Control<TOwner>
    where TItem : Control<TOwner>
    where TOwner : PageObject<TOwner>

Properties

public ControlList<TItem, TOwner>

Items { get; }

Gets the items’ ControlList<TItem, TOwner> instance.

ItemsControl.Items.Should.HaveCount(2);

Indexers

public TItem this

[int index] { get; }

Gets the item at the specified index.

ItemsControl[0].Should.BePresent();
ItemsControl[1].Should.Equal(5);
ItemsControl[2].Content.Should.Equal("Item 1");
public TItem this

[Expression<Func<TItem, bool>> predicateExpression] { get; }

Gets the item that matches the conditions defined by the specified predicate expression.

ItemsControl[x => x.Title == "Product 1"].Should.BePresent();
ItemsControl[x => x.Content == "Some content"].Should.Not.BePresent();

Example

<div id="products" class="product-list">
    <div class="product">
        <h5>Product 1</h5>
        <span>Some description</span>
    </div>
    <div class="product">
        <h5>Product 2</h5>
        <span>Some description</span>
    </div>
</div>
Product 1
Some description
Product 2
Some description
using _ = SamplePage;

public class SamplePage : Page<_>
{
    [FindById]
    public ItemsControl<ProductItem, _> Products { get; private set; }

    [ControlDefinition("div", ContainingClass = "product", ComponentTypeName = "product item")]
    public class ProductItem : Control<_>
    {
        public H5<_> Title { get; private set; }

        [FindByXPath("span")]
        public Text<_> Description { get; private set; }
    }
}
Go.To<SamplePage>()
    .Products.Attributes.Class.Should.Contain("product-list")
    .Products.Items.Count.Should.Equal(2)
    .Products.Items[0].Title.Should.Equal("Product 1")
    .Do(_ => _.Products.Items[1], x =>
    {
        x.Title.Should.Equal("Product 2");
        x.Description.Should.Equal("Some description");
    });

ListItem

Represents the list item control (<li>). Default search finds the first occurring <li> element. Recommended to use with UnorderedList and OrderedList controls. Can be inherited, if <li> element contains separate components.

Inherited from Control.

Syntax

[ControlDefinition("li", ComponentTypeName = "list item")]
public class ListItem<TOwner> : Control<TOwner>
    where TOwner : PageObject<TOwner>

Example

<div>
    <ul>
        <li>Item 1</li>
        <li>Item 2</li>
    </ul>
    <ol>
        <li>Item 1</li>
        <li>Item 2</li>
    </ol>
</div>
  • Item 1
  • Item 2
  1. Item 1
  2. Item 2
using _ = SamplePage;

public class SamplePage : Page<_>
{
    public UnorderedList<ListItem<_>, _> UnorderedList { get; private set; }

    public OrderedList<ListItem<_>, _> OrderedList { get; private set; }
}
Go.To<SamplePage>()
    .UnorderedList.Items.Count.Should.Equal(2)
    .UnorderedList.Items[0].Content.Should.Equal("Item 1")

    .OrderedList.Items.Should.Not.BeEmpty()
    .OrderedList.Items.Contents.Should.EqualSequence("Item 1", "Item 2");

See also UnorderedList and OrderedList controls for more usage samples.

UnorderedList

Represents the unordered list control (<ul>). Default search finds the first occurring <ul> element.

Inherited from ItemsControl.

Syntax

[ControlDefinition("ul", ComponentTypeName = "unordered list")]
[FindSettings(OuterXPath = "./", TargetName = nameof(Items))]
public class UnorderedList<TItem, TOwner> : ItemsControl<TItem, TOwner>
    where TItem : Control<TOwner>
    where TOwner : PageObject<TOwner>

Example

<div>
    <ul id="simple">
        <li>Item 1</li>
        <li>Item 2</li>
    </ul>
    <ul id="product-list">
        <li>
            <span>Phone</span> - <span>20</span>
        </li>
        <li>
            <span>Book</span> - <span>30</span>
        </li>
        <li>
            <span>Table</span> - <span>40</span>
        </li>
    </ul>
</div>
  • Item 1
  • Item 2
  • Phone - 20
  • Book - 30
  • Table - 40
using _ = SamplePage;

public class SamplePage : Page<_>
{
    [FindById("simple")]
    public UnorderedList<ListItem<_>, _> SimpleUnorderedList { get; private set; }

    [FindById]
    public UnorderedList<ProductItem, _> ProductList { get; private set; }

    public class ProductItem : ListItem<_>
    {
        [FindByIndex(0)]
        public Text<_> Name { get; private set; }

        [FindByIndex(1)]
        public Number<_> Amount { get; private set; }
    }
}
Go.To<SamplePage>()
    .SimpleUnorderedList.Items.Count.Should.Equal(2)
    .SimpleUnorderedList.Items[0].Content.Should.Equal("Item 1")
    .SimpleUnorderedList.Items.Contents.Should.EqualSequence("Item 1", "Item 2")

    .ProductList.Items.Count.Should.Equal(3)
    .ProductList.Items[0].Name.Should.Equal("Phone")
    .ProductList.Items[0].Amount.Should.Equal(20)
    .ProductList.Items[x => x.Name == "Book"].Amount.Should.Equal(30)
    .ProductList.Items.SelectData(x => x.Name).Should.EqualSequence("Phone", "Book", "Table");

OrderedList

Represents the ordered list control (<ol>). Default search finds the first occurring <ol> element.

Inherited from ItemsControl.

Syntax

[ControlDefinition("ol", ComponentTypeName = "ordered list")]
[FindSettings(OuterXPath = "./", TargetName = nameof(Items))]
public class OrderedList<TItem, TOwner> : ItemsControl<TItem, TOwner>
    where TItem : Control<TOwner>
    where TOwner : PageObject<TOwner>

Example

<div>
    <ol id="simple">
        <li>Item 1</li>
        <li>Item 2</li>
    </ol>
    <ol id="product-list">
        <li>
            <strong>Phone</strong>
            <span>5%</span>
            <button>Delete</button>
        </li>
        <li>
            <strong>Book</strong>
            <span>10%</span>
            <button>Delete</button>
        </li>
        <li>
            <strong>Table</strong>
            <span>15%</span>
            <button>Delete</button>
        </li>
    </ol>
</div>
  1. Item 1
  2. Item 2
  1. Phone 5%
  2. Book 10%
  3. Table 15%
using _ = SamplePage;

public class SamplePage : Page<_>
{
    [FindById("simple")]
    public OrderedList<ListItem<_>, _> SimpleOrderedList { get; private set; }

    [FindById]
    public OrderedList<ProductItem, _> ProductList { get; private set; }

    public class ProductItem : ListItem<_>
    {
        [FindByXPath("strong")]
        public Text<_> Name { get; private set; }

        [FindByIndex(1)]
        [Format("p")]
        public Number<_> Percent { get; private set; }

        public Button<_> Delete { get; private set; }
    }
}
Go.To<SamplePage>()
    .SimpleOrderedList.Items.Count.Should.Equal(2)
    .SimpleOrderedList.Items[0].Content.Should.Equal("Item 1")
    .SimpleOrderedList.Items.Contents.Should.EqualSequence("Item 1", "Item 2")

    .ProductList.Items.Count.Should.Equal(3)
    .ProductList.Items[0].Name.Should.Equal("Phone")
    .ProductList.Items[0].Percent.Should.Equal(0.05m)
    .ProductList.Items[x => x.Name == "Book"].Percent.Should.Equal(0.10m)
    .ProductList.Items.SelectData(x => x.Name).Should.EqualSequence("Phone", "Book", "Table")
    .ProductList.Items[x => x.Name == "Table"].Delete.Click()
    .ProductList.Items[x => x.Name == "Table"].Should.Not.BePresent()
    .ProductList.Items.Count.Should.Equal(2);

There are several controls for interaction with the hierarchical/structural/tree controls.

HierarchicalControl

Represents the hierarchical control (a control containing structured hierarchy of controls of TItem type). Default search finds the first occurring element.

Inherited from Control.

Syntax

[FindSettings(OuterXPath = "./", TargetName = nameof(Children))]
public class HierarchicalControl<TItem, TOwner> : Control<TOwner>
    where TItem : HierarchicalItem<TItem, TOwner>
    where TOwner : PageObject<TOwner>

Properties

public ControlList<TItem, TOwner>

Children { get; }

Gets the children ControlList<TItem, TOwner> instance.

Control.Children.Count.Should.Equal(5);
public ControlList<TItem, TOwner>

Descendants { get; }

Gets the descendants (all items at any level of hierarchy) ControlList<TItem, TOwner> instance.

Control.Descendants[x => x.Name == "Item 2.2"].Click();

Indexers

public TItem this

[int index] { get; }

Gets the child item at the specified index.

Control[0].Should.BePresent();
Control[1].Name.Should.Equal("Item 2");
public TItem this

[Expression<Func<TItem, bool>> predicateExpression] { get; }

Gets the child item that matches the conditions defined by the specified predicate expression.

Control[x => x.Name == "Item 1"].Should.BePresent();

HierarchicalItem

Represents the hierarchical item control (a control containing structured hierarchy of controls of TItem type). Can have parent control of TItem type. Default search finds the first occurring element.

Inherited from HierarchicalControl.

Syntax

public class HierarchicalItem<TItem, TOwner> : HierarchicalControl<TItem, TOwner>
    where TItem : HierarchicalItem<TItem, TOwner>
    where TOwner : PageObject<TOwner>

Properties

public ValueProvider<bool, TOwner>

HasParent { get; }

Gets the ValueProvider<TData, TOwner> instance for the value indicating whether the control has parent.

Item.HasParent.Should.BeTrue();
public TItem

Parent { get; }

Gets the parent control of TItem type.

Item.Parent.Name.Should.Equal("Item 1");

HierarchicalListItem

Represents the hierarchical list item control (<li>). Default search finds the first occurring <li> element. It is recommended to use with HierarchicalUnorderedList<TItem, TOwner> and HierarchicalOrderedList<TItem, TOwner>.

Inherited from HierarchicalItem.

Syntax

[ControlDefinition("li", ComponentTypeName = "list item")]
[FindSettings(OuterXPath = "(./ul | ./ol)/", TargetName = nameof(Children))]
public class HierarchicalListItem<TItem, TOwner> : HierarchicalItem<TItem, TOwner>
    where TItem : HierarchicalListItem<TItem, TOwner>
    where TOwner : PageObject<TOwner>

HierarchicalUnorderedList

Represents the hierarchical unordered list control (<ul>). Default search finds the first occurring <ul> element.

Inherited from HierarchicalControl.

Syntax

[ControlDefinition("ul", ComponentTypeName = "unordered list")]
public class HierarchicalUnorderedList<TItem, TOwner> : HierarchicalControl<TItem, TOwner>
    where TItem : HierarchicalItem<TItem, TOwner>
    where TOwner : PageObject<TOwner>

Example

<ul id="some-tree">
    <li>
        <span>Item 1</span>
        <ul>
            <li>
                <span>Item 1.1</span>
            </li>
            <li>
                <span>Item 1.2</span>
            </li>
        </ul>
    </li>
    <li>
        <span>Item 2</span>
        <ul>
            <li>
                <span>Item 2.1</span>
                <ul>
                    <li>
                        <span>Item 2.1.1</span>
                    </li>
                    <li>
                        <span>Item 2.1.2</span>
                    </li>
                </ul>
            </li>
            <li>
                <span>Item 2.2</span>
            </li>
        </ul>
    </li>
</ul>
  • Item 1
    • Item 1.1
    • Item 1.2
  • Item 2
    • Item 2.1
      • Item 2.1.1
      • Item 2.1.2
    • Item 2.2
using _ = TreePage;

[Url("TreePage.html")]
public class TreePage : Page<_>
{
    [FindById("some-tree")]
    public HierarchicalUnorderedList<TreeItem, _> Tree { get; private set; }

    public class TreeItem : HierarchicalListItem<TreeItem, _>
    {
        [FindByXPath("./span[1]")]
        public Text<_> Name { get; private set; }
    }
}
Go.To<TreePage>()
    .Tree.Children.Count.Should.Equal(2)
    .Tree.Descendants.Count.Should.Equal(8)
    .Tree[x => x.Name == "Item 1"][x => x.Name == "Item 1.1"].Should.BePresent()
    .Tree.Descendants.Should.Contain(x => x.Name == "Item 2.1.1")
    .Tree[1][0][1].Name.Should.Equal("Item 2.1.2")
    .Tree.Descendants.SelectData(x => x.Name).Should.Contain("Item 1.1", "Item 2.1", "Item 2.2");

HierarchicalOrderedList

Represents the hierarchical ordered list control (<ol>). Default search finds the first occurring <ol> element.

Inherited from HierarchicalControl.

Syntax

[ControlDefinition("ol", ComponentTypeName = "ordered list")]
public class HierarchicalOrderedList<TItem, TOwner> : HierarchicalControl<TItem, TOwner>
    where TItem : HierarchicalItem<TItem, TOwner>
    where TOwner : PageObject<TOwner>

Example

<ol id="some-tree">
    <li>
        <span>Item 1</span>
        <ol>
            <li>
                <span>Item 1.1</span>
            </li>
            <li>
                <span>Item 1.2</span>
            </li>
        </ol>
    </li>
    <li>
        <span>Item 2</span>
        <ol>
            <li>
                <span>Item 2.1</span>
                <ol>
                    <li>
                        <span>Item 2.1.1</span>
                    </li>
                    <li>
                        <span>Item 2.1.2</span>
                    </li>
                </ol>
            </li>
            <li>
                <span>Item 2.2</span>
            </li>
        </ol>
    </li>
</ol>
  1. Item 1
    1. Item 1.1
    2. Item 1.2
  2. Item 2
    1. Item 2.1
      1. Item 2.1.1
      2. Item 2.1.2
    2. Item 2.2
using _ = TreePage;

[Url("TreePage.html")]
public class TreePage : Page<_>
{
    [FindById("some-tree")]
    public HierarchicalOrderedList<TreeItem, _> Tree { get; private set; }

    public class TreeItem : HierarchicalListItem<TreeItem, _>
    {
        [FindByXPath("./span[1]")]
        public Text<_> Name { get; private set; }
    }
}
Go.To<TreePage>()
    .Tree.Children.Count.Should.Equal(2)
    .Tree.Descendants.Count.Should.Equal(8)
    .Tree[x => x.Name == "Item 1"][x => x.Name == "Item 1.1"].Should.BePresent()
    .Tree.Descendants.Should.Contain(x => x.Name == "Item 2.1.1")
    .Tree[1][0][1].Name.Should.Equal("Item 2.1.2")
    .Tree.Descendants.SelectData(x => x.Name).Should.Contain("Item 1.1", "Item 2.1", "Item 2.2");

Represents the frame control (<iframe> or <frame>). Default search finds the first occurring <iframe> or <frame> element.

Frame<TOwner>

Recommended to use for the cases when the frame page can be different in parent page.

Inherited from Control.

Supports [GoTemporarily] settings attribute.

Syntax

[ControlDefinition("*[self::iframe or self::frame]", ComponentTypeName = "frame")]
public class Frame<TOwner> : Control<TOwner>
    where TOwner : PageObject<TOwner>

Methods

public virtual TFramePageObject

SwitchTo<TFramePageObject>(TFramePageObject framePageObject = null, bool? temporarily = null)

where TFramePageObject : PageObject<TFramePageObject>

Switches to the frame page object represented by the instance of TFramePageObject type. If temporarily is to true, navigates temporarily preserving current page object state. If temporarily is not set, checks GoTemporarilyAttribute.

public TOwner

DoWithin<TFramePageObject>(Action<TFramePageObject> action, bool? temporarily = null)

where TFramePageObject : PageObject<TFramePageObject>

Switches to the frame page object, executes action(s) in scope of frame and switches back to the owner page object. If temporarily is to true, navigates temporarily preserving current page object state. If temporarily is not set, checks GoTemporarilyAttribute.

Example

<div>
    <iframe src="...">
        <html>
            <body>
                <input type="text" id="text-box">
            </body>
        </html>
    </iframe>
</div>
using _ = SamplePage;

public class SamplePage : Page<_>
{
    public Frame<_> ContentFrame { get; private set; }
}
using _ = FramePage;

public class FramePage : Page<_>
{
    [FindById]
    public TextInput<_> TextBox { get; private set; }
}
Go.To<SamplePage>()
    .ContentFrame.SwitchTo<FramePage>(temporarily: true)
        .TextBox.Set("abc")
        .SwitchToRoot<SamplePage>()
    // Or use DoWithin method
    .ContentFrame.DoWithin<FramePage>(x => x
        .TextBox.Should.Equal("abc"));

Frame<TFramePageObject, TOwner>

Recommended to use for the cases when the frame page is the same in parent page.

Inherited from Frame.

Supports [GoTemporarily] settings attribute.

Syntax

public class Frame<TFramePageObject, TOwner> : Frame<TOwner>
    where TOwner : PageObject<TOwner>
    where TFramePageObject : PageObject<TFramePageObject>

Methods

public TFramePageObject

SwitchTo(TFramePageObject framePageObject = null, bool? temporarily = null)

Switches to the frame page object represented by the instance of TFramePageObject type. If temporarily is to true, navigates temporarily preserving current page object state. If temporarily is not set, checks GoTemporarilyAttribute.

public TOwner

DoWithin(Action<TFramePageObject> action, bool? temporarily = null)

Switches to the frame page object, executes action(s) in scope of frame and switches back to the owner page object. If temporarily is to true, navigates temporarily preserving current page object state. If temporarily is not set, checks GoTemporarilyAttribute.

Example

<div>
    <iframe src="...">
        <html>
            <body>
                <input type="text" id="text-box">
            </body>
        </html>
    </iframe>
</div>
using _ = SamplePage;

public class SamplePage : Page<_>
{
    public Frame<FramePage, _> ContentFrame { get; private set; }
}
using _ = FramePage;

public class FramePage : Page<_>
{
    [FindById]
    public TextInput<_> TextBox { get; private set; }

    public SamplePage SwitchBack() =>
        SwitchToRoot<SamplePage>();
}
Go.To<SamplePage>()
    .ContentFrame.SwitchTo()
        .TextBox.Set("abc")
        .SwitchBack()
    // Or use DoWithin method
    .ContentFrame.DoWithin(x => x
        .TextBox.Should.Equal("abc"));