Skip to content

Commit

Permalink
#273 Add FindItemByParentContentAttribute; Add RadioButtonList_String…
Browse files Browse the repository at this point in the history
…_FindItemByParentContentAttribute test
  • Loading branch information
YevgeniyShunevych committed May 24, 2019
1 parent d572cf7 commit 4d1af58
Show file tree
Hide file tree
Showing 4 changed files with 66 additions and 0 deletions.
16 changes: 16 additions & 0 deletions src/Atata.TestApp/Pages/RadioButtonList.cshtml
Expand Up @@ -52,6 +52,22 @@
<input type="radio" name="decimal-items" value="Option4" />$4,310.10
</label>
</fieldset>
<br>
<fieldset id="text-in-parent-items">
<legend>Text is in the Parent</legend>
<span class="radio-inline">
<input type="radio" name="radio-options" value="OptionA" />Option A
</span>
<span class="radio-inline">
<input type="radio" name="radio-options" value="OptionB" />Option B
</span>
<span class="radio-inline">
<input type="radio" name="radio-options" value="OptionC" />Option C
</span>
<span class="radio-inline">
<input type="radio" name="radio-options" value="OptionD" />Option D
</span>
</fieldset>
</div>
</div>
<div class="col-md-2">
Expand Down
4 changes: 4 additions & 0 deletions src/Atata.Tests/Components/RadioButtonListPage.cs
Expand Up @@ -50,6 +50,10 @@ public enum ByValue
[Format("C")]
public RadioButtonList<decimal?, _> DecimalItems { get; private set; }

[FindById]
[FindItemByParentContent]
public RadioButtonList<string, _> TextInParentItems { get; private set; }

[FindByName(TermCase.Kebab)]
[FindItemByLabel]
public RadioButtonList<string, _> VerticalItems { get; private set; }
Expand Down
16 changes: 16 additions & 0 deletions src/Atata.Tests/RadioButtonListTests.cs
Expand Up @@ -87,5 +87,21 @@ public void RadioButtonList_Decimal()
Assert.Throws<ArgumentNullException>(() =>
page.VerticalItems.Set(null));
}

[Test]
public void RadioButtonList_String_FindItemByParentContentAttribute()
{
var control = page.TextInParentItems;

control.Should.BeNull();

SetAndVerifyValues(control, "Option B", "Option C");

Assert.Throws<NoSuchElementException>(() =>
control.Set("Option Z"));

Assert.Throws<ArgumentNullException>(() =>
control.Set(null));
}
}
}
30 changes: 30 additions & 0 deletions src/Atata/Attributes/Behaviors/FindItemByParentContentAttribute.cs
@@ -0,0 +1,30 @@
namespace Atata
{
/// <summary>
/// Represents the behavior to find an item of <see cref="OptionList{T, TOwner}"/> control by parent element content using its XPath.
/// </summary>
public class FindItemByParentContentAttribute : FindItemByRelativeElementContentAttribute
{
public const string ParentElementXPath = "parent::*";

public FindItemByParentContentAttribute()
: base(ParentElementXPath)
{
}

public FindItemByParentContentAttribute(TermCase termCase)
: base(ParentElementXPath, termCase)
{
}

public FindItemByParentContentAttribute(TermMatch match)
: base(ParentElementXPath, match)
{
}

public FindItemByParentContentAttribute(TermMatch match, TermCase termCase)
: base(ParentElementXPath, match, termCase)
{
}
}
}

0 comments on commit 4d1af58

Please sign in to comment.