コード例 #1
0
        protected By GetNewLocatorFromField(FieldInfo field)
        {
            By  byLocator    = null;
            var locatorGroup = AppVersion;

            if (locatorGroup == null)
            {
                return(FindByAttribute.Locator(field) ?? field.GetFindsBy());
            }
            var jFindBy = field.GetAttribute <JFindByAttribute>();

            if (jFindBy != null && locatorGroup.Equals(jFindBy.Group))
            {
                byLocator = jFindBy.ByLocator;
            }
            return(byLocator ?? (FindByAttribute.Locator(field) ?? field.GetFindsBy()));
        }
コード例 #2
0
 private static By GetNewLocator(FieldInfo field)
 {
     return(ActionWithException(() =>
     {
         var locatorGroup = AppVersion;
         if (locatorGroup != null)
         {
             string groupName;
             By byLocator;
             JFindByAttribute.Get(field, out byLocator, out groupName);
             if (groupName != null && locatorGroup.Equals(groupName) && byLocator != null)
             {
                 return byLocator;
             }
         }
         return FindByAttribute.FindsByLocator(field) ?? FindByAttribute.Locator(field);
     }, ex => $"Error in get locator for type '{field.Name + ex.FromNewLine()}'"));
 }
コード例 #3
0
ファイル: Block.cs プロジェクト: Chathura1990/Kayak.TAF
        protected void InitializeFields()
        {
            Type findByType            = typeof(FindByAttribute);
            Type elementType           = typeof(Element);
            Type collectionType        = typeof(ElementCollection);
            Type genericCollectionType = typeof(ElementCollection <>);

            FieldInfo[] fields = GetType()
                                 .GetFields(BindingFlags.Public | BindingFlags.Instance);
            IEnumerable <FieldInfo> fieldsToInitialize = fields
                                                         .Where(prop =>
                                                                (
                                                                    elementType.IsAssignableFrom(prop.FieldType) ||
                                                                    collectionType.IsAssignableFrom(prop.FieldType) ||
                                                                    (prop.FieldType.IsGenericType && prop.FieldType.GetGenericTypeDefinition() == genericCollectionType)
                                                                ) &&
                                                                prop.GetCustomAttributes(findByType).Any());

            foreach (FieldInfo field in fieldsToInitialize)
            {
                FindByAttribute findByAttribute = (FindByAttribute)field.GetCustomAttributes(findByType).First();
                string          locator         = findByAttribute.Locator;

                Type actualFieldType = field.FieldType;

                if (elementType.IsAssignableFrom(actualFieldType))
                {
                    field.SetValue(this, Activator.CreateInstance(actualFieldType, locator, this));
                    continue;
                }

                if (collectionType.IsAssignableFrom(actualFieldType))
                {
                    field.SetValue(this, Activator.CreateInstance(actualFieldType, locator, this));
                    continue;
                }

                if (actualFieldType.IsGenericType && actualFieldType.GetGenericTypeDefinition() == genericCollectionType)
                {
                    field.SetValue(this, Activator.CreateInstance(actualFieldType, locator, this));
                }
            }
        }
コード例 #4
0
        internal static Locator ToLocator(this FindByAttribute attribute)
        {
            var locator = new Locator(attribute.How, attribute.Using);

            return(locator);
        }
コード例 #5
0
 internal static Locator ToLocator(this FindByAttribute attribute) => new Locator(attribute.By, attribute.Locator);