Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Value set behavior functionality #425

Closed
YevgeniyShunevych opened this issue Nov 17, 2020 · 0 comments
Closed

Value set behavior functionality #425

YevgeniyShunevych opened this issue Nov 17, 2020 · 0 comments
Assignees
Labels
Milestone

Comments

@YevgeniyShunevych
Copy link
Member

YevgeniyShunevych commented Nov 17, 2020

Implement the behavior functionality for control value set. Execute behavior inside SetValue method of Input<T, TOwner> and TextArea<TOwner>.

ValueSetBehaviorAttribute

The base behavior class for an implementation of control value set.

public abstract class ValueSetBehaviorAttribute : MulticastAttribute
{
    public abstract void Execute<TOwner>(IUIComponent<TOwner> component, string value)
        where TOwner : PageObject<TOwner>;
}

ValueSetUsingClearAndSendKeysAttribute

The behavior for control value set by invoking IWebElement.Clear() and IWebElement.SendKeys(string) methods. IWebElement.SendKeys(string) method is invoked only when the value is not null or empty.

The default behavior.

public class ValueSetUsingClearAndSendKeysAttribute : ValueSetBehaviorAttribute
{
    public override void Execute<TOwner>(IUIComponent<TOwner> component, string value)
    {
        var scopeElement = component.Scope;

        scopeElement.Clear();

        if (!string.IsNullOrEmpty(value))
            scopeElement.SendKeys(value);
    }
}

ValueSetUsingSendKeysAttribute

The behavior for control value set by IWebElement.SendKeys(string) method. IWebElement.SendKeys(string) method is invoked only when the value is not null or empty.

public class ValueSetUsingSendKeysAttribute : ValueSetBehaviorAttribute
{
    public override void Execute<TOwner>(IUIComponent<TOwner> component, string value)
    {
        if (!string.IsNullOrEmpty(value))
            component.Scope.SendKeys(value);
    }
}

ValueSetUsingScriptAttribute

The behavior for control value set by executing HTMLElement.value = '{value}'; HTMLElement.dispatchEvent(new Event('change')); JavaScript.

public class ValueSetUsingScriptAttribute : ValueSetBehaviorAttribute
{
    public override void Execute<TOwner>(IUIComponent<TOwner> component, string value)
    {
        component.Script.SetValueAndDispatchChangeEvent(value);
    }
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Development

No branches or pull requests

1 participant