Esempio n. 1
0
        public void EnterContext(string contextName)
        {
            CombinedWebElementInfo webContext = null;

            while (_contextStack.Count > 0)
            {
                var currentContext = _contextStack.Peek();
                webContext = FindContextInDescendants(currentContext, contextName);
                if (webContext == null)
                {
                    _contextStack.Pop();
                }
                else
                {
                    break;
                }
            }

            if (webContext == null)
            {
                webContext = _webElementRepository.GetWebContextOrDefault(contextName);
            }

            if (webContext == null)
            {
                throw new Exception($"Couldn't find WebContext with name: {contextName}");
            }

            _contextStack.Push(webContext);
        }
Esempio n. 2
0
        private List <WebElementInfo> FindElementInDescendants(CombinedWebElementInfo parent, string elementName)
        {
            var els           = new List <WebElementInfo>();
            var queue         = new Queue <CombinedWebElementInfo>();
            var childContexts = parent.GetChildContexts();

            foreach (var child in childContexts)
            {
                queue.Enqueue(child);
            }

            while (queue.Count > 0)
            {
                var currentContext = queue.Dequeue();
                var element        = currentContext.Elements.FirstOrDefault(e => e.Name == elementName);
                if (element != null)
                {
                    els.Add(element);
                }

                foreach (var child in currentContext.GetChildContexts())
                {
                    queue.Enqueue(child);
                }
            }

            return(els);
        }
Esempio n. 3
0
        private CombinedWebElementInfo FindContextInDescendants(CombinedWebElementInfo parent, string contextName)
        {
            var childContexts = parent.GetChildContexts();

            foreach (var child in childContexts)
            {
                if (child.Name == contextName)
                {
                    return(child);
                }
            }

            foreach (var child in childContexts)
            {
                var context = FindContextInDescendants(child, contextName);
                if (context != null)
                {
                    return(context);
                }
            }

            return(null);
        }