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");