Friday, June 21, 2013

Finding Objects Dynamically with Coded UI

Mapping objects with visual studios coded UI can be cumbersome and hard to manage one way to make your fame work a little lighter is to make a class that does this for you and even better creating a more generic method that will handle all the objects for you. The way I accomplish this idea is with the following code snippets

   public T  GetControlGeneric<T>(string propertyValue, string property,  PropertyExpressionOperator propertyExpressionOperator = PropertyExpressionOperator.Contains) where T:WinControl
        {
            return GetControlGenericWithParent<T>(propertyValue, property, ThickClient, propertyExpressionOperator);
        }
        public T GetControlGenericWithParent<T>(string propertyValue, string property, UITestControl parent, PropertyExpressionOperator propertyExpressionOperator = PropertyExpressionOperator.Contains)where T:WinControl
        {
            T ctrl = (T)Activator.CreateInstance(typeof(T), new object[] { parent });
            ctrl.SearchProperties.Add(property, propertyValue, propertyExpressionOperator);
            return ctrl;
        }
-Sarah

No comments:

Post a Comment