Пример #1
0
        /// <summary>
        /// Gets the attribute value for an AppiumWebElement.
        /// </summary>
        /// <returns>The attribute value.</returns>
        /// <param name="element">Element.</param>
        /// <param name="attribute">Attribute.</param>
        public static string GetAttributeValue(AppiumWebElement element, eGUIElementAttribute attribute)
        {
            string attributeVal = string.Empty;

            switch (attribute)
            {
            case eGUIElementAttribute.Name:
                attributeVal = element.GetAttribute("name");
                break;

            case eGUIElementAttribute.Label:
                attributeVal = element.GetAttribute("label");
                break;

            case eGUIElementAttribute.Value:
                attributeVal = element.GetAttribute("value");
                break;

            case eGUIElementAttribute.Displayed:
                attributeVal = element.Displayed.ToString().ToLower();
                break;

            case eGUIElementAttribute.Enabled:
                attributeVal = element.Enabled.ToString().ToLower();
                break;

            default:
                Console.WriteLine("Unknonwn attribute : " + attribute.ToString());
                break;
            }
            return(attributeVal);
        }
Пример #2
0
        /// <summary>
        /// Waits for attribute value to be attained.
        /// </summary>
        /// <returns><c>true</c>, if for attribute value was waited, <c>false</c> otherwise.</returns>
        /// <param name="bySelector">Selector.</param>
        /// <param name="attribute">Attribute.</param>
        /// <param name="value">Value.</param>
        /// <param name="timeoutMS">Timeout ms.</param>
        public static bool WaitForAttributeValue(By bySelector, eGUIElementAttribute attribute, string value, int timeoutMS)
        {
            DefaultWait <AppiumDriver <AppiumWebElement> > wait = new DefaultWait <AppiumDriver <AppiumWebElement> >(AppManager.CurrentAppDriver);

            wait.PollingInterval = TimeSpan.FromMilliseconds(250);
            wait.Timeout         = TimeSpan.FromMilliseconds(timeoutMS);
            wait.IgnoreExceptionTypes(typeof(NoSuchElementException));
            wait.IgnoreExceptionTypes(typeof(TimeoutException));

            bool isSuccessful = false;

            try
            {
                isSuccessful = wait.Until <bool>((d) =>
                {
                    AppiumWebElement element = d.FindElement(bySelector);
                    if (GetAttributeValue(element, attribute).Equals(value))
                    {
                        return(true);
                    }
                    else
                    {
                        throw new TimeoutException();
                    }
                });
            }
            catch (Exception e)
            {
                PrintException(e);
            }

            return(isSuccessful);
        }
Пример #3
0
        /// <summary>
        /// This method gets the XPath including the attribute filter.
        /// </summary>
        /// <returns>The XPath.</returns>
        /// <param name="elementType">Element type.</param>
        /// <param name="attributeFilterType">Attribute type.</param>
        /// <param name="attributeFilterVal">Attribute name.</param>
        public static string GetXPath(eGUIElementType elementType, eGUIElementAttribute attributeFilterType, string attributeFilterVal)
        {
            string xpath = string.Empty;

            xpath = GetXPath(elementType) + GetXPathAttributeFilterText(attributeFilterType, attributeFilterVal);
            Console.WriteLine("xpath = " + xpath);

            return(xpath);
        }
Пример #4
0
        /// <summary>
        /// This method gets the XPath attribute filter text.
        /// </summary>
        /// <returns>The XPath attribute filter text.</returns>
        /// <param name="attributeType">Attribute type.</param>
        /// <param name="attributeVal">Attribute value.</param>
        public static string GetXPathAttributeFilterText(eGUIElementAttribute attributeType, string attributeVal)
        {
            string xpathAttributeFilterText = string.Empty;

            switch (attributeType)
            {
            case eGUIElementAttribute.Label:
                xpathAttributeFilterText = "[@label='" + attributeVal + "']";
                break;

            case eGUIElementAttribute.Name:
                xpathAttributeFilterText = "[@name='" + attributeVal + "']";
                break;

            case eGUIElementAttribute.None:
                //No filter applied.
                break;

            default:
                Console.WriteLine("ERROR: Unknown attributeType: " + attributeType.ToString());
                break;
            }
            return(xpathAttributeFilterText);
        }
Пример #5
0
        public static void VerifyProperty(AppiumDriver <AppiumWebElement> appDriver, By selector, eGUIElementAttribute attribute, string expAttributeVal, params string[] reqTags)
        {
            AppiumWebElement element         = SupportLib.FindElement(selector);
            string           actAttributeVal = SupportLib.GetAttributeValue(element, attribute);

            VerifyString(actAttributeVal, expAttributeVal, reqTags);
        }