Пример #1
0
        private static void SetUpDropdownFromAnnotation(WebBaseElement instance, FieldInfo field)
        {
            var jMenu = field.GetAttribute <JMenuAttribute>();

            if (jMenu == null || !typeof(IMenu).IsAssignableFrom(field.FieldType))
            {
                return;
            }
            SetUpMenu((Menu)instance, jMenu);
        }
Пример #2
0
        private static void SetUpMenuFromAnnotation(WebBaseElement instance, FieldInfo field)
        {
            var jDropdown = field.GetAttribute <JDropdownAttribute>();

            if (jDropdown == null || !typeof(IDropDown).IsAssignableFrom(field.FieldType))
            {
                return;
            }
            SetUpDropdown((Dropdown)instance, jDropdown);
        }
Пример #3
0
        private static void SetUpTableFromAnnotation(WebBaseElement instance, FieldInfo field)
        {
            var jTable = field.GetAttribute <JTableAttribute>();

            if (jTable == null || !typeof(ITable).IsAssignableFrom(field.FieldType))
            {
                return;
            }
            SetUpTable((Table)instance, jTable);
        }
Пример #4
0
 public WebBaseElement(By byLocator = null, IWebElement webElement = null,
                       List <IWebElement> webElements = null, WebBaseElement element = null)
 {
     Invoker         = new ActionInvoker(this);
     GetElementClass = new GetElementClass(this);
     Actions         = new ElementsActions(this);
     WebAvatar       = new GetElementModule(this, byLocator)
     {
         WebElement = webElement, WebElements = webElements
     };
     if (element != null)
     {
         WebAvatar.DriverName = element.WebAvatar.DriverName;
         Parent = element.Parent;
     }
 }
Пример #5
0
        private WebBaseElement GetElementInstance(FieldInfo field, string driverName)
        {
            var type       = field.FieldType;
            var fieldName  = field.Name;
            var newLocator = GetNewLocator(field);

            return(ActionWithException(() =>
            {
                WebBaseElement instance = null;
                if (type == typeof(List <>))
                {
                    throw Exception($"Can't init element {fieldName} with type 'List<>'. Please use 'IList<>' or 'Elements<>' instead");
                }
                if (typeof(IList).IsAssignableFrom(type))
                {
                    var elementClass = type.GetGenericArguments()[0];
                    if (elementClass != null)
                    {
                        instance = (WebBaseElement)Activator.CreateInstance(typeof(Elements <>)
                                                                            .MakeGenericType(elementClass));
                    }
                }
                else
                {
                    if (type.IsInterface)
                    {
                        type = MapInterfaceToElement.ClassFromInterface(type);
                    }
                    if (type != null)
                    {
                        instance = (WebBaseElement)Activator.CreateInstance(type);
                        instance.WebAvatar.ByLocator = newLocator;
                    }
                }
                if (instance == null)
                {
                    throw Exception("Unknown interface: " + type +
                                    ". Add relation interface -> class in VIElement.InterfaceTypeMap");
                }
                instance.Avatar.DriverName = driverName;
                return instance;
            }, ex => $"Error in getElementInstance for field {fieldName}' with type '{type.Name + ex.FromNewLine()}'"));
        }
Пример #6
0
        protected override IBaseElement GetElementsRules(FieldInfo field, string driverName, Type type, string fieldName)
        {
            var            newLocator = GetNewLocator(field);
            WebBaseElement instance   = null;

            if (type == typeof(List <>))
            {
                throw Exception($"Can't init element {fieldName} with type 'List<>'. Please use 'IList<>' or 'Elements<>' instead");
            }
            if (typeof(IList).IsAssignableFrom(type))
            {
                var elementClass = type.GetGenericArguments()[0];
                if (elementClass != null)
                {
                    instance = (WebBaseElement)Activator.CreateInstance(typeof(Elements <>)
                                                                        .MakeGenericType(elementClass));
                }
            }
            else
            {
                if (type.IsInterface)
                {
                    type = MapInterfaceToElement.ClassFromInterface(type);
                }
                if (type != null)
                {
                    instance = (WebBaseElement)Activator.CreateInstance(type);
                    if (newLocator != null)
                    {
                        instance.WebAvatar.ByLocator = newLocator;
                    }
                }
            }
            if (instance == null)
            {
                throw Exception("Unknown interface: " + type +
                                ". Add relation interface -> class in VIElement.InterfaceTypeMap");
            }
            instance.Avatar.DriverName = driverName;
            return(instance);
        }
Пример #7
0
 public GetElementType(By locator, WebBaseElement element)
 {
     _locator = locator;
     _avatar  = element.WebAvatar;
 }
Пример #8
0
 private static void FillFromAnnotation(WebBaseElement instance, FieldInfo field)
 {
     SetUpTableFromAnnotation(instance, field);
     SetUpMenuFromAnnotation(instance, field);
     SetUpDropdownFromAnnotation(instance, field);
 }