diff --git a/src/Unicorn.UI.Core/Controls/Interfaces/IHasValue.cs b/src/Unicorn.UI.Core/Controls/Interfaces/IHasValue.cs new file mode 100644 index 0000000..c265c35 --- /dev/null +++ b/src/Unicorn.UI.Core/Controls/Interfaces/IHasValue.cs @@ -0,0 +1,13 @@ +namespace Unicorn.UI.Core.Controls.Interfaces +{ + /// + /// Interface for controls which have a value. + /// + public interface IHasValue + { + /// + /// Gets value as a + /// + string Value { get; } + } +} diff --git a/src/Unicorn.UI.Core/Matchers/ControlMatchers.cs b/src/Unicorn.UI.Core/Matchers/ControlMatchers.cs index 6498447..dfbd77c 100644 --- a/src/Unicorn.UI.Core/Matchers/ControlMatchers.cs +++ b/src/Unicorn.UI.Core/Matchers/ControlMatchers.cs @@ -88,6 +88,14 @@ public ControlHasValidationErrorMatcher HasValidationError() => public HasTitleMatcher HasTitle(string expectedTitle) => new HasTitleMatcher(expectedTitle); + /// + /// Gets matcher to check if control has specified value. + /// + /// expected control value + /// matcher instance + public InputHasValueMatcher HasValue(string expectedValue) => + new InputHasValueMatcher(expectedValue); + /// /// Gets matcher to check if control contains specified sub-items. /// diff --git a/src/Unicorn.UI.Core/Matchers/TypifiedMatchers/InputHasValueMatcher.cs b/src/Unicorn.UI.Core/Matchers/TypifiedMatchers/InputHasValueMatcher.cs index d2ea67b..a18b463 100644 --- a/src/Unicorn.UI.Core/Matchers/TypifiedMatchers/InputHasValueMatcher.cs +++ b/src/Unicorn.UI.Core/Matchers/TypifiedMatchers/InputHasValueMatcher.cs @@ -1,13 +1,14 @@ using System; using Unicorn.Taf.Core.Verification.Matchers; +using Unicorn.UI.Core.Controls.Interfaces; using Unicorn.UI.Core.Controls.Interfaces.Typified; namespace Unicorn.UI.Core.Matchers.TypifiedMatchers { /// - /// Matcher to check if UI control has specified value. + /// Matcher to check if UI control has specified value. /// - public class InputHasValueMatcher : TypeSafeMatcher + public class InputHasValueMatcher : TypeSafeMatcher { private readonly string _expectedValue; @@ -25,11 +26,11 @@ public InputHasValueMatcher(string isChecked) public override string CheckDescription => $"has value '{_expectedValue}'"; /// - /// Checks if text input has specified value. + /// Checks if control has specified value. /// /// UI control under check - /// true - if text input has expected value; otherwise - false - public override bool Matches(ITextInput actual) + /// true - if control has expected value; otherwise - false + public override bool Matches(IHasValue actual) { if (actual == null) { @@ -39,12 +40,12 @@ public override bool Matches(ITextInput actual) var actualValue = actual.Value; - string mismatch = Reverse ? - actualValue : + string mismatch = Reverse ? + actualValue : Environment.NewLine + MatchersUtils.GetStringsDiff(_expectedValue, actualValue); DescribeMismatch(mismatch); - + return actualValue.Equals(_expectedValue); } }