ExecuteAutomation

Creating generic method for control with Generic in Coded UI

In the last post we discussed creating custom methods for Html controls in C# for Coded UI testing, but we saw, there were some moving parts like But, we can make our controls even more generic using Generic in C# HtmlEdit/HtmlTextArea Control Generic control method Here is the code
public void EnterText(PropertyType type, string propertyvalue, string text) where T : HtmlControl
{
    HtmlControl genericControl = (T)Activator.CreateInstance(typeof(T), new object[] { ParentWindow });
    if (type == PropertyType.Name)
        genericControl.SearchProperties[HtmlControl.PropertyNames.Name] = propertyvalue;
    else if (type == PropertyType.Id)
        genericControl.SearchProperties[HtmlControl.PropertyNames.Id] = propertyvalue;
    //Type in the UI
    Keyboard.SendKeys(genericControl, text);
}
Calling the above method To call the above methods use the code snippets below
EnterText(PropertyType.Name, "UserName", "Karthik"); 

Thanks for reading the post and watching the video !!! Please leave your comments and let me know if there is anything to improve in this post !!! Thanks, Karthik KK