Exemplo n.º 1
0
        public Rectangle GetElementRectangle(SETestObject seTestObject)
        {
            Rectangle rect = seTestObject.absolutePageRect;

            rect.X += (int)_toobarAutoElement.Current.BoundingRectangle.X;

            rect.Y += ((int)_toobarAutoElement.Current.BoundingRectangle.TopLeft.Y + (int)_toobarAutoElement.Current.BoundingRectangle.Height);

            return(rect);
        }
Exemplo n.º 2
0
        public TestObjectNurse ToNurseObject()
        {
            string cssSelector    = string.Empty;//"css=";
            int    indexofelement = -1;
            //WebPage - Browser

            //check whether the element is unique or not.
            ReadOnlyCollection <IWebElement> elements = null; //_webElement.WrappedDriver.FindElements(By.Id(_webElement.TagName));
            string tagName; this._properties.TryGetValue(WebControlKeys.TagName, out tagName);

            Debug.Assert(!string.IsNullOrEmpty(tagName), "DOM element doesn't have tag!!!!!! Unbelievable!!!!!!");
            cssSelector += tagName;
            string className; this._properties.TryGetValue(WebControlKeys.Class, out className);

            //By class
            if (string.IsNullOrEmpty(className))
            {
                cssSelector += className.Replace(' ', '.');
            }

            //By mandatory attributes
            foreach (KeyValuePair <string, string> pair in this.SelectedProperties)
            {
                if (string.IsNullOrEmpty(pair.Value))
                {
                    continue;
                }
                if (pair.Key.Equals(WebControlKeys.TagName) ||
                    pair.Key.Equals(WebControlKeys.BoundingRectangle) ||
                    pair.Key.Equals(WebControlKeys.Type))
                {
                    continue;
                }
                cssSelector += string.Format("[{0}='{1}']", pair.Key.Equals(WebControlKeys.AttrType) ? "type" : pair.Key, pair.Value);
            }

            //By ID
            string webelementID = _properties[WebControlKeys.ID];

            if (!string.IsNullOrEmpty(webelementID))
            {
                cssSelector = "#" + webelementID;
            }
            //locate element
            elements = _webElement.WrappedDriver.FindElements(By.CssSelector(cssSelector));
            int countofElements = elements.Count;
            int i = 0;

            if (1 < countofElements)
            {
                //By assistant attributes
                foreach (KeyValuePair <string, string> pair in this.OtherProperties)
                {
                    if (string.IsNullOrEmpty(pair.Value))
                    {
                        continue;
                    }
                    if (pair.Key.Equals(WebControlKeys.TagName) ||
                        pair.Key.Equals(WebControlKeys.BoundingRectangle) ||
                        pair.Key.Equals(WebControlKeys.Type))
                    {
                        continue;
                    }
                    cssSelector += string.Format("[{0}='{1}']", pair.Key.Equals(WebControlKeys.AttrType) ? "type" : pair.Key, pair.Value);
                }
            }
            else if (1 == countofElements)
            {
                goto Found;
            }
            //locate element again
            elements        = _webElement.WrappedDriver.FindElements(By.CssSelector(cssSelector));
            countofElements = elements.Count;
            if (1 < elements.Count)
            {
                for (i = 0; i < countofElements; ++i)
                {
                    RemoteWebElement element = elements[i] as RemoteWebElement;

                    /*if (element.Location.X == _webElement.Location.X && element.Location.Y == _webElement.Location.Y)
                     * {
                     *  indexofelement = i;
                     * // cssSelector += string.Format("[{0}]", i);
                     *  goto Found;
                     * }*/

                    if (element.Equals(_webElement))
                    {
                        indexofelement = i;
                        goto Found;
                    }
                }
            }
            else if (1 == countofElements)
            {
                goto Found;
            }
            //By XPath
            return(null);


Found:

            SETestObject testObject = new SETestObject();

            foreach (KeyValuePair <string, string> pair in this.Properties)
            {
                testObject.Properties.Add(pair.Key, pair.Value);
            }

            testObject.SEWebElement = _webElement;

            testObject.Cssselector = cssSelector;
            testObject.Properties.Add(WebControlKeys.CssSelector, cssSelector);
            testObject.NodeName = this.Name;
            if (indexofelement != -1)
            {
                testObject.IndexofTags = indexofelement;
                testObject.Properties.Add(WebControlKeys.IndexofTags, indexofelement.ToString());
            }

            TestObjectNurse testNurse = new TestObjectNurse(testObject);

            foreach (KeyValuePair <string, string> pair in NoneEmptyProperties)
            {
                testNurse.CachedProperties.Add(pair.Key, pair.Value);
            }
            return(testNurse);
        }