Skip to content

Instantly share code, notes, and snippets.

@YevgeniyShunevych
Created November 23, 2018 19:28
Show Gist options
  • Save YevgeniyShunevych/4fedb2146bb24734c4b6ffe42cc64ec5 to your computer and use it in GitHub Desktop.
Save YevgeniyShunevych/4fedb2146bb24734c4b6ffe42cc64ec5 to your computer and use it in GitHub Desktop.
Atata approach to get associated labels
using System;
namespace Atata
{
public class LabelList<TOwner> : ControlList<Label<TOwner>, TOwner>
where TOwner : PageObject<TOwner>
{
public Label<TOwner> this[Func<TOwner, Control<TOwner>> controlSelector]
{
get { return For(controlSelector); }
}
public Label<TOwner> For(Func<TOwner, Control<TOwner>> controlSelector)
{
Control<TOwner> targetControl = controlSelector(Component.Owner);
return CreateAssociatedControl(targetControl);
}
private Label<TOwner> CreateAssociatedControl(Control<TOwner> control)
{
string id = control.Attributes.Id;
return Component.Controls.Create<Label<TOwner>>(control.ComponentName, new FindByAttributeAttribute("for", id));
}
}
}
using Atata;
namespace SomeApp.UITests
{
using _ = SamplePage;
public class SamplePage : Page<_>
{
[FindById("text-input")]
public TextInput<_> TextInput { get; private set; }
[FindByLabel("URL Input")]
public UrlInput<_> UrlInput { get; private set; }
public LabelList<_> Labels { get; private set; }
}
}
using Atata;
using NUnit.Framework;
namespace SampleApp.UITests
{
public class LabelListTests : UITestFixture
{
[Test]
public void LabelList()
{
Go.To<SomePage>().
Labels[x => x.TextInput].Should.Equal("Text Input");
Labels[x => x.UrlInput].Should.Equal("URL Input");
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment