Created
November 23, 2018 19:28
-
-
Save YevgeniyShunevych/4fedb2146bb24734c4b6ffe42cc64ec5 to your computer and use it in GitHub Desktop.
Atata approach to get associated labels
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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)); | |
} | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; } | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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