コード例 #1
0
        public static PageElementCollection GetElementCollectionByAlias(PageCore page, PageElement currentElement, string groupAlias)
        {
            if (page == null)
            {
                throw new ArgumentException("Страница на которой происходит поиск не может иметь пустое значение");
            }

            PageElementCore element = null;

            if (currentElement != null && currentElement.TryFindElementByAlias(groupAlias, out element))
            {
                PageElementCollection collection = element as PageElementCollection;
                if (collection != null)
                {
                    return(collection);
                }
            }
            if (page.TryFindElementByAlias(groupAlias, out element))
            {
                PageElementCollection collection = element as PageElementCollection;
                if (collection != null)
                {
                    return(collection);
                }
            }

            string xPath = Alias.ResolveAsString(groupAlias);

            return(page.FindElementCollection(xPath));
        }
コード例 #2
0
ファイル: PageElementCore.cs プロジェクト: shamanhex/OmSU
        public static PageElement GetElementByAlias(PageCore page, PageElement currentElement, string alias)
        {
            if (page == null)
            {
                throw new ArgumentException("Страница на которой происходит поиск не может иметь пустое значение");
            }

            PageElementCore elementCore = null;

            if (currentElement != null && currentElement.TryFindElementByAlias(alias, out elementCore))
            {
                PageElement element = elementCore as PageElement;
                if (element != null)
                {
                    return(element);
                }
            }

            if (page.TryFindElementByAlias(alias, out elementCore))
            {
                PageElement element = elementCore as PageElement;
                if (element != null)
                {
                    return(element);
                }
            }

            string xPath = Alias.ResolveAsString(alias);

            return(page.FindElement(xPath));
        }
コード例 #3
0
 public static void SetCurrent(this ScenarioContext context, PageElementCore elementCore)
 {
     if (elementCore is PageElement)
     {
         context.SetElement(elementCore as PageElement);
     }
     else if (elementCore is PageElementCollection)
     {
         context.SetElementGroup(elementCore as PageElementCollection);
     }
 }
コード例 #4
0
        public void InitElements()
        {
            // init start url
            object[] startUrlAttrs = this.GetType().GetCustomAttributes(typeof(StartUrlAttribute), true);
            if (startUrlAttrs != null && startUrlAttrs.Length > 0)
            {
                this.StartUrl = Alias.ResolveAsString(((StartUrlAttribute)startUrlAttrs[0]).PageAlias);
            }

            TimeSpan classWaitSpan = GetPageTimeoutSpan();

            // init properties
            foreach (PropertyInfo prop in this.GetType().GetProperties())
            {
                if (!prop.CanWrite)
                {
                    continue;
                }

                object[] findAsAttrs = prop.GetCustomAttributes(typeof(FindAsAttribute), true);

                if (findAsAttrs == null || findAsAttrs.Length == 0)
                {
                    continue;
                }
                FindAsAttribute findAsAttr = (FindAsAttribute)findAsAttrs[0];

                Type elementType = findAsAttr.ElementType;

                if (elementType == null)
                {
                    elementType = prop.PropertyType;
                }

                PageElementCore element = FindElement(findAsAttr.XPath, elementType);

                object[] waitAttrs = prop.GetCustomAttributes(typeof(WaitAttribute), true);

                if (waitAttrs != null && waitAttrs.Length > 0)
                {
                    element.WaitTimeout = ((WaitAttribute)waitAttrs[0]).Timeout;
                }
                else
                {
                    element.WaitTimeout = classWaitSpan;
                }

                prop.GetSetMethod().Invoke(this, new object[] { element });
            }
        }
コード例 #5
0
        public bool TryFindElementByAlias(string alias, out PageElementCore element)
        {
            element = null;

            foreach (PropertyInfo prop in this.GetType().GetProperties())
            {
                if (!prop.HasAlias(alias))
                {
                    continue;
                }

                element = prop.GetGetMethod().Invoke(this, null) as PageElementCore;

                if (element != null)
                {
                    return(true);
                }
            }

            return(false);
        }