Components

Atata Framework contains the 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

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 IWebElement

Scope { get; }

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

Component.Scope.SendKeys("some text");
public UIComponentAttributeProvider<TOwner>

Attributes { get; }

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

Component.Attributes.Class.Should.Contain("some-class");
Component.Attributes["data-value"].Should.Equal("val");
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 DataProvider<bool, TOwner>

IsVisible { get; }

Gets the DataProvider<bool, TOwner> instance for the value indicating whether the control is visible.

Component.IsVisible.Should.BeTrue();
public DataProvider<string, TOwner>

Content { get; }

Gets the DataProvider<string, TOwner> instance for the text content.

Component.Content.Should.Contain("some value");
public UIComponentVerificationProvider<UIComponent<TOwner>, TOwner>

Should { get; }

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

Component.Should.Exist();
Component.Should.Not.BeHidden();
Component.Should.BeDisabled();
public UIComponentTriggerSet<TOwner>

Triggers { get; }

Gets the set of triggers. Provides the functionality to get/add/remove triggers dynamically.

Component.Triggers.Add(new WaitAttribute(2));
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);

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], [ControlFinding], [FindSettings], [TermFindSettings], [Format] and [Culture] settings attributes.

Syntax

[ControlDefinition("*", ComponentTypeName = "control")]
public class Control<TOwner> : UIComponent<TOwner>, IControl<TOwner>
    where TOwner : PageObject<TOwner>

Properties

public DataProvider<bool, TOwner>

IsEnabled { get; }

Gets the DataProvider instance for the value indicating whether the control is enabled.

Control.IsEnabled.Should.BeTrue();
bool isEnabled = Control.IsEnabled;

Methods

public TOwner

Click()

Clicks the control. 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 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 ScrollUsingMoveToElementAttribute 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], [ControlFinding], [FindSettings], [TermFindSettings], [FormatSettings] and [Culture] settings attributes.

Syntax

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

Properties

public DataProvider<string, TOwner>

PageTitle { get; }

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

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

PageUrl { get; }

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

PageObject.PageUrl.Should.EndWith("/some-page?id=123987");

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

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], [ControlFinding], [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 Atata;

namespace SampleApp.Tests
{
    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], [ControlFinding], [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 Atata;

namespace SampleApp.Tests
{
    using _ = SampleModal;

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

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`2 is protected abstract T 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<T, TOwner> : Control<TOwner>, IEquatable<T>, IDataProvider<T, TOwner>
    where TOwner : PageObject<TOwner>

Properties

public T

Value { get; }

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

Methods

public T

Get(out T value)

Gets the value and records it to value parameter.

protected abstract T

GetValue()

Gets the value.

Example

The example of RadioButton`1 control that is inherited from Field`2:

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

    protected override bool GetValue()
    {
        return Scope.Selected;
    }

    public TOwner Check()
    {
        return Click();
    }
}

Usage

string textFieldValue;

Go.To<SomePage>().
    SomeTextField.Get(out 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`2 are: protected abstract T GetValue() and protected abstract void SetValue(T value).

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

Syntax

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

Properties

public DataProvider<bool, TOwner>

IsReadOnly { get; }

Gets the DataProvider<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(T 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 T value)

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

protected abstract void

SetValue(T value)

Sets the value.

Example

The example of CheckBox`1 control that is inherited from EditableField`2:

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

    protected override bool GetValue()
    {
        return Scope.Selected;
    }

    protected override void SetValue(bool value)
    {
        IWebElement element = Scope;
        if (element.Selected != value)
            element.Click();
    }

    public TOwner Check()
    {
        return Set(true);
    }

    public TOwner Uncheck()
    {
        return 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.

TextInput

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

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

namespace SampleApp
{
    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.BeNull();

Supports [Format] and [RandomizeStringSettings] settings attributes.

PasswordInput

Represents the password input control. Default search is performed by the label.

<input type="password">
using Atata;
using _ = SampleApp.SamplePage;

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

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

Supports [Format] and [RandomizeStringSettings] settings attributes.

NumberInput

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

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

namespace SampleApp
{
    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);

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

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

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

namespace SampleApp
{
    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);

Supports [Format] and [Culture] settings attributes.

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.

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

namespace SampleApp
{
    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);

Supports [Format] and [Culture] settings attributes.

HiddenInput

Represents the hidden input control. Default search finds the first occurring element.

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

namespace SampleApp
{
    public class SamplePage : Page<_>
    {
        public HiddenInput<_> SomeHidden { get; private set; }
    }
}
string hiddenValue;

Go.To<SamplePage>().
    HiddenInput.Get(out hiddenValue).
    HiddenInput.Should.Equal("somedata");

Supports [Format] and [Culture] settings attributes.

CheckBox

Represents the checkbox control. Default search is performed by the label.

<label class="checkbox-inline">
  <input type="checkbox" id="inlineCheckbox1" value="option1"> Option 1
</label>
<label class="checkbox-inline">
  <input type="checkbox" id="inlineCheckbox2" value="option1" checked> Option 2
</label>
using Atata;
using _ = SampleApp.SamplePage;

namespace SampleApp
{
    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();

Properties

public DataProvider<bool, TOwner>

IsChecked { get; }

Gets the DataProvider<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.

CheckBoxList

Represents the checkbox list control (a set of <input type="checkbox">). Default search is performed by the name.

Specified checkbox items can be found by the label or value. By default finds the items by the name. Use [FindItemByValue] attribute to find the items by the value.

<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,
    OptionA = 1 << 0,
    OptionB = 1 << 1,
    OptionC = 1 << 2
}

Do not forget to mark the enumeration with the [Flags] attribute.

using Atata;
using _ = SampleApp.SamplePage;

namespace SampleApp
{
    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);

Supports [Format], [Culture], [FindItemByLabel] and [FindItemByValue] settings attributes.

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.

RadioButton

Represents the radio button control. Default search is performed by the label.

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

namespace SampleApp
{
    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();

Properties

public DataProvider<bool, TOwner>

IsChecked { get; }

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

Methods

public TOwner

Check()

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

RadioButtonList

Represents the radio button list control (a set of <input type="radio">). Default search is performed by the name.

Specified radio button items can be found by the label or value. By default finds the items by the label. Use [FindItemByValue] attribute to find the items by the value.

Supports [Format], [Culture], [FindItemByLabel] and [FindItemByValue] settings attributes.

<label>
    <input type="radio" name="options" value="OptionA" />Option A
</label>
<label>
    <input type="radio" name="options" value="OptionB" />Option B
</label>
<label>
    <input type="radio" name="options" value="OptionC" />Option C
</label>

Using Enum

public enum SomeOption
{
    OptionA,
    OptionB,
    OptionC
}
using Atata;
using _ = SampleApp.SamplePage;

namespace SampleApp
{
    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);

Using String

using Atata;
using _ = SampleApp.SamplePage;

namespace SampleApp
{
    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");

Represents the select control. By default is being searched by the label. It is possible to select an option by the text or value. Default selection is performed by text.

Supports [SelectByText], [SelectByValue], [Format] and [Culture] settings attributes.

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

There are different approaches to configure Select control.

Select Using Enum

The above select can be described with the following enum:

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

Select By Text

using Atata;
using _ = SampleApp.SamplePage;

namespace SampleApp
{
    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 or Format.

using Atata;
using _ = SampleApp.SamplePage;

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

TermCase.Lower is defined in SelectByValue attribute because option values are lowercase in this example (e.g. volvo).

Select Using String

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

using Atata;
using _ = SampleApp.SamplePage;

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

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 Atata;
using _ = SampleApp.SamplePage;

namespace SampleApp
{
    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);

Represents the text area control. Default search is performed by the label.

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

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

Supports [Format] and [RandomizeStringSettings] settings attributes.

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 Atata;
using _ = SampleApp.SamplePage;

namespace SampleApp
{
    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 Atata;
using _ = SampleApp.SamplePage;

namespace SampleApp
{
    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().Exist().

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 Atata;
using _ = SampleApp.SamplePage1;

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

namespace SampleApp
{
    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 Atata;
using _ = SampleApp.SamplePage;

namespace SampleApp
{
    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 Atata;
using _ = SampleApp.SamplePage;

namespace SampleApp
{
    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().Exist().

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 Atata;
using _ = SampleApp.ItemsPage;

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

namespace SampleApp
{
    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 Atata;
using _ = SampleApp.SamplePage;

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

Clickable Delegate

using Atata;
using _ = SampleApp.SamplePage;

namespace SampleApp
{
    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().Exist().

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 Atata;
using _ = SampleApp.ItemsPage;

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

namespace SampleApp
{
    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 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.Exist();
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 Atata;

namespace SampleApp.Tests
{
    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.Exist();

Represents any HTML element containing content. Default search finds the first occurring element (if is declared in the 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 Atata;
using _ = SampleApp.SamplePage;

namespace SampleApp
{
    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 Atata;
using _ = SampleApp.SamplePage;

namespace SampleApp
{
    public class SamplePage : Page<_>
    {
        [FindById]
        public Text<_> Description { get; private set; }
    }
}
Go.To<SamplePage>().
    Description.Should.Exist().
    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 Atata;
using _ = SampleApp.SamplePage;

namespace SampleApp
{
    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 Atata;
using _ = SampleApp.SamplePage;

namespace SampleApp
{
    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 Atata;
using _ = SampleApp.SamplePage;

namespace SampleApp
{
    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 Atata;
using _ = SampleApp.SamplePage;

namespace SampleApp
{
    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 Atata;
using _ = SampleApp.SamplePage;

namespace SampleApp
{
    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 Atata;
using _ = SampleApp.SamplePage;

namespace SampleApp
{
    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 Atata;
using _ = SampleApp.SamplePage;

namespace SampleApp
{
    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>, IDataProvider<IEnumerable<TItem>, TOwner>, IEnumerable<TItem>, ISupportsMetadata
    where TItem : Control<TOwner>
    where TOwner : PageObject<TOwner>

Properties

public DataProvider<int, TOwner>

Count { get; }

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

Items.Count.Get();
Items.Count.Should.Equal(5);
public DataProvider<IEnumerable<string>, TOwner>

Contents { get; }

Gets the DataProvider<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.Exist();
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.Exist();
Items[x => x.Content == "Some content"].Should.Not.Exist();

Methods

public DataProvider<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 DataProvider<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 DataProvider<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 Atata;

namespace SampleApp.Tests
{
    using _ = SamplePage;

    public class SamplePage : Page<_>
    {
        [FindById]
        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.Exist().
    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.Exist();
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.Exist();
ItemsControl[x => x.Content == "Some content"].Should.Not.Exist();

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

namespace SampleApp.Tests
{
    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 Atata;

namespace SampleApp.Tests
{
    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 = "./")]
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 Atata;

namespace SampleApp.Tests
{
    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 = "./")]
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 Atata;

namespace SampleApp.Tests
{
    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.Exist().
    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.Exist();
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.Exist();

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 DataProvider<bool, TOwner>

HasParent { get; }

Gets the DataProvider<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 Atata;

namespace SampleApp.Tests
{
    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.Exist().
    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 Atata;

namespace SampleApp.Tests
{
    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.Exist().
    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 inline frame control (<iframe>). Default search finds the first occurring <iframe> element.

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

Supports [GoTemporarily] settings attribute.

Frame<TOwner>

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

using Atata;
using _ = SampleApp.SamplePage;

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

namespace SampleApp
{
    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"));

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.

Frame<TFramePageObject, TOwner>

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

using Atata;
using _ = SampleApp.SamplePage;

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

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

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

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.