Created
November 23, 2018 20:29
-
-
Save YevgeniyShunevych/4744a14cdb36b509e3543bf4a066b5d0 to your computer and use it in GitHub Desktop.
Atata approach to get associated label container elements
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 LabelContainerList<TOwner> : ControlList<Text<TOwner>, TOwner> | |
where TOwner : PageObject<TOwner> | |
{ | |
public Text<TOwner> this[Func<TOwner, Control<TOwner>> controlSelector] | |
{ | |
get { return For(controlSelector); } | |
} | |
public Text<TOwner> For(Func<TOwner, Control<TOwner>> controlSelector) | |
{ | |
Control<TOwner> targetControl = controlSelector(Component.Owner); | |
return CreateAssociatedControl(targetControl); | |
} | |
private Text<TOwner> CreateAssociatedControl(Control<TOwner> control) | |
{ | |
string id = control.Attributes.Id; | |
return Component.Controls.Create<Text<TOwner>>( | |
control.ComponentName, | |
new ControlDefinitionAttribute { ComponentTypeName = "container" }, | |
new FindByXPathAttribute($"div[label[@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
<div class="form-group"> | |
<label for="text-input">Text Input</label> | |
<input id="text-input" type="text" class="form-control" /> | |
+ DIV content | |
</div> |
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; } | |
public LabelContainerList<_> LabelContainers { 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>(). | |
LabelContainers[x => x.TextInput].Should.ContainAll("Text Input", "+ DIV content"); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment