Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions src/Unicorn.UI.Core/Matchers/ControlMatchers.cs
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,13 @@ public ControlEnabledMatcher Enabled() =>
public ControlVisibleMatcher Visible() =>
new ControlVisibleMatcher();

/// <summary>
/// Matcher to check if UI control exists (Works only for PageObject described controls!).
/// </summary>
/// <returns><see cref="ControlExistsMatcher"/> instance</returns>
public ControlExistsMatcher ExistsInPageObject() =>
new ControlExistsMatcher();

/// <summary>
/// Matcher to check if <see cref="ISelectable"/> UI control is selected.
/// </summary>
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
using Unicorn.Taf.Core.Verification.Matchers;
using Unicorn.UI.Core.Controls;
using Unicorn.UI.Core.PageObject;

namespace Unicorn.UI.Core.Matchers.IControlMatchers
{
/// <summary>
/// Matcher to check if UI control exists.
/// </summary>
public class ControlExistsMatcher : TypeSafeMatcher<IControl>
{
/// <summary>
/// Initializes a new instance of the <see cref="ControlExistsMatcher"/> class.
/// </summary>
public ControlExistsMatcher()
{
}

/// <summary>
/// Gets check description.
/// </summary>
public override string CheckDescription => "exists";

/// <summary>
/// Checks if UI control exists.
/// </summary>
/// <param name="actual">UI control under check</param>
/// <returns>true - if control exists; otherwise - false</returns>
public override bool Matches(IControl actual)
{
if (actual == null)
{
DescribeMismatch("null");
return Reverse;
}

bool exists = actual.ExistsInPageObject();
DescribeMismatch(exists ? "exists" : "does not exist");
return exists;
}
}
}
9 changes: 9 additions & 0 deletions src/Unicorn.UnitTests/FakeControls/HasValueControl.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
using Unicorn.UI.Core.Controls.Interfaces;

namespace Unicorn.UnitTests.FakeControls
{
class HasValueControl : IHasValue
{
public string Value => "some actual value";
}
}
24 changes: 24 additions & 0 deletions src/Unicorn.UnitTests/Tests/MatchersTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,14 @@ namespace Unicorn.UnitTests.Tests
internal class MatchersTests
{
private HasTitleControl iHasTitle;
private HasValueControl iHasValue;
private HasItemsControl iHasItems;

[BeforeSuite]
public void SetUp()
{
iHasTitle = new HasTitleControl();
iHasValue = new HasValueControl();
iHasItems = new HasItemsControl();
}

Expand All @@ -41,6 +43,28 @@ public void HasTitleTestNegative() =>

#endregion

#region HasValue

[Test]
public void HasValueReverseTestNegative() =>
Assert.Throws<AssertionException>(() =>
Assert.That(iHasValue, Is.Not(Ui.Control.HasValue("some actual value"))));

[Test]
public void HasValueTestPositive() =>
Assert.That(iHasValue, Ui.Control.HasValue("some actual value"));

[Test]
public void HasValueReverseTestPositive() =>
Assert.That(iHasValue, Is.Not(Ui.Control.HasValue("sofe actual value")));

[Test]
public void HasValueTestNegative() =>
Assert.Throws<AssertionException>(() =>
Assert.That(iHasValue, Ui.Control.HasValue("some atual value")));

#endregion

#region HasItems

[Test]
Expand Down
Loading