diff --git a/src/Unicorn.UI.Core/Matchers/ControlMatchers.cs b/src/Unicorn.UI.Core/Matchers/ControlMatchers.cs index dfbd77c..b11f9c9 100644 --- a/src/Unicorn.UI.Core/Matchers/ControlMatchers.cs +++ b/src/Unicorn.UI.Core/Matchers/ControlMatchers.cs @@ -42,6 +42,13 @@ public ControlEnabledMatcher Enabled() => public ControlVisibleMatcher Visible() => new ControlVisibleMatcher(); + /// + /// Matcher to check if UI control exists (Works only for PageObject described controls!). + /// + /// instance + public ControlExistsMatcher ExistsInPageObject() => + new ControlExistsMatcher(); + /// /// Matcher to check if UI control is selected. /// diff --git a/src/Unicorn.UI.Core/Matchers/IControlMatchers/ControlExistsMatcher.cs b/src/Unicorn.UI.Core/Matchers/IControlMatchers/ControlExistsMatcher.cs new file mode 100644 index 0000000..515262f --- /dev/null +++ b/src/Unicorn.UI.Core/Matchers/IControlMatchers/ControlExistsMatcher.cs @@ -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 +{ + /// + /// Matcher to check if UI control exists. + /// + public class ControlExistsMatcher : TypeSafeMatcher + { + /// + /// Initializes a new instance of the class. + /// + public ControlExistsMatcher() + { + } + + /// + /// Gets check description. + /// + public override string CheckDescription => "exists"; + + /// + /// Checks if UI control exists. + /// + /// UI control under check + /// true - if control exists; otherwise - false + 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; + } + } +} diff --git a/src/Unicorn.UnitTests/FakeControls/HasValueControl.cs b/src/Unicorn.UnitTests/FakeControls/HasValueControl.cs new file mode 100644 index 0000000..e4d2297 --- /dev/null +++ b/src/Unicorn.UnitTests/FakeControls/HasValueControl.cs @@ -0,0 +1,9 @@ +using Unicorn.UI.Core.Controls.Interfaces; + +namespace Unicorn.UnitTests.FakeControls +{ + class HasValueControl : IHasValue + { + public string Value => "some actual value"; + } +} diff --git a/src/Unicorn.UnitTests/Tests/MatchersTests.cs b/src/Unicorn.UnitTests/Tests/MatchersTests.cs index b2df761..6d4da27 100644 --- a/src/Unicorn.UnitTests/Tests/MatchersTests.cs +++ b/src/Unicorn.UnitTests/Tests/MatchersTests.cs @@ -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(); } @@ -41,6 +43,28 @@ public void HasTitleTestNegative() => #endregion + #region HasValue + + [Test] + public void HasValueReverseTestNegative() => + Assert.Throws(() => + 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(() => + Assert.That(iHasValue, Ui.Control.HasValue("some atual value"))); + + #endregion + #region HasItems [Test]