예제 #1
0
        public string GetAttribute(string attributeName)
        {
            var stopwatch = new Stopwatch();

            stopwatch.Start();

            while (stopwatch.Elapsed < _seleniumBrowser.GetElementWaitTimeSpan())
            {
                var attribute = GetWebElement().GetAttribute(attributeName);

                if (!string.IsNullOrEmpty(attribute))
                {
                    return(attribute);
                }

                if (attribute == null)
                {
                    continue;
                }

                return(attribute);
            }

            throw new InvalidOperationException(
                      string.Format("The attribute [{0}] does not exist on element with locator [{1}].",
                                    attributeName, By));
        }
예제 #2
0
        public override void Fill(string inputValue)
        {
            var stopwatch = new Stopwatch();

            stopwatch.Start();

            while (stopwatch.Elapsed < SeleniumBrowser.GetElementWaitTimeSpan())
            {
                try
                {
                    Clear();
                    GetWebElement().SendKeys(inputValue);

                    if (GetValue() == inputValue)
                    {
                        return;
                    }
                }

                catch (InvalidElementStateException)
                {
                }
            }

            throw new Exception(string.Format(
                                    "After multiple attempts to fill The element with locator: [{0}], " +
                                    "the actual value: [{1}] returned by the element " +
                                    "did not match the expected fill value: [{2}]", By,
                                    GetValue(), inputValue));
        }
예제 #3
0
        public SeleniumElement Create(IWebDriver webdriver, By by, SeleniumBrowser seleniumBrowser)
        {
            var tagName = SeleniumHelper.FindWebElement(webdriver, by, seleniumBrowser.GetElementWaitTimeSpan()).TagName;

            switch (tagName)
            {
            case "button":
            {
                return(new SeleniumButtonElement(webdriver, by, seleniumBrowser));
            }

            case "input":
            {
                return(CreateInputElement(webdriver, by, seleniumBrowser));
            }

            case "select":
            {
                return(new SeleniumSelectElement(webdriver, by, seleniumBrowser));
            }

            default:
            {
                return(new SeleniumGenericElement(webdriver, by, seleniumBrowser));
            }
            }
        }
예제 #4
0
        protected SeleniumElement(IWebDriver driver, By by, SeleniumBrowser seleniumBrowser)
        {
            Driver           = driver;
            By               = by;
            _seleniumBrowser = seleniumBrowser;

            Wait = new WebDriverWait(Driver, _seleniumBrowser.GetElementWaitTimeSpan());

            if (_seleniumBrowser.IsElementHighlighterEnabled())
            {
                _elementHighlighter = new ElementHighlighter(Driver, By, seleniumBrowser.GetElementWaitTimeSpan());
                _elementHighlighter.HighlightElementBackground();
            }
        }
예제 #5
0
        public override string GetValue()
        {
            var stopwatch = new Stopwatch();

            while (stopwatch.Elapsed < SeleniumBrowser.GetElementWaitTimeSpan())
            {
                var elementValue = GetWebElement().GetAttribute("value");

                if (string.IsNullOrEmpty(elementValue))
                {
                    continue;
                }
                return(elementValue);
            }
            return(string.Empty);
        }
        public override string GetText()
        {
            var stopwatch = new Stopwatch();

            while (stopwatch.Elapsed < SeleniumBrowser.GetElementWaitTimeSpan())
            {
                var elementText = GetWebElement().Text;

                if (string.IsNullOrEmpty(elementText))
                {
                    continue;
                }

                return(elementText);
            }
            return(string.Empty);
        }
예제 #7
0
        private static SeleniumElement CreateInputElement(IWebDriver webdriver, By by, SeleniumBrowser seleniumBrowser)
        {
            var elementType =
                SeleniumHelper.FindWebElement(webdriver, by, seleniumBrowser.GetElementWaitTimeSpan())
                .GetAttribute("type");

            switch (elementType)
            {
            case "button":
            {
                return(new SeleniumButtonElement(webdriver, by, seleniumBrowser));
            }

            case "checkbox":
            {
                return(new SeleniumCheckboxElement(webdriver, by, seleniumBrowser));
            }

            case "password":
            {
                return(new SeleniumPasswordElement(webdriver, by, seleniumBrowser));
            }

            case "radio":
            {
                return(new SeleniumRadioElement(webdriver, by, seleniumBrowser));
            }

            case "text":
            {
                return(new SeleniumTextElement(webdriver, by, seleniumBrowser));
            }

            default:
                throw new Exception(
                          string.Format("Input elements of type [{0}] are not yet supported" +
                                        "by the SweetPotatoUI framework. The currently supported element types are: " +
                                        "['button', 'checkbox', 'password', 'radio', 'text']",
                                        elementType));
            }
        }
예제 #8
0
 private SelectElement GetSelectElement()
 {
     return(new SelectElement(SeleniumHelper.FindWebElement(Driver, By,
                                                            SeleniumBrowser.GetElementWaitTimeSpan())));
 }
        private static SeleniumElement CreateInputElement(IWebDriver webdriver, By by, SeleniumBrowser seleniumBrowser)
        {
            var elementType =
                SeleniumHelper.FindWebElement(webdriver, by, seleniumBrowser.GetElementWaitTimeSpan())
                .GetAttribute("type");

            switch (elementType)
            {
            case "button":
            {
                return(new SeleniumButtonElement(webdriver, by, seleniumBrowser));
            }

            case "checkbox":
            {
                return(new SeleniumCheckboxElement(webdriver, by, seleniumBrowser));
            }

            case "password":
            {
                return(new SeleniumPasswordElement(webdriver, by, seleniumBrowser));
            }

            case "radio":
            {
                return(new SeleniumRadioElement(webdriver, by, seleniumBrowser));
            }

            case "submit":
            {
                return(new SeleniumSubmitElement(webdriver, by, seleniumBrowser));
            }

            case "textarea":
            case "text":
            {
                return(new SeleniumTextElement(webdriver, by, seleniumBrowser));
            }

            //html 5 elements...
            case "color":
            {
                return(new SeleniumColorElement(webdriver, by, seleniumBrowser));
            }

            case "date":
            {
                return(new SeleniumDateElement(webdriver, by, seleniumBrowser));
            }

            case "datetime-local":
            {
                return(new SeleniumDateTimeLocalElement(webdriver, by, seleniumBrowser));
            }

            case "email":
            {
                return(new SeleniumEmailElement(webdriver, by, seleniumBrowser));
            }

            case "month":
            {
                return(new SeleniumMonthElement(webdriver, by, seleniumBrowser));
            }

            case "number":
            {
                return(new SeleniumNumberElement(webdriver, by, seleniumBrowser));
            }

            case "range":
            {
                return(new SeleniumRangeElement(webdriver, by, seleniumBrowser));
            }

            case "reset":
            {
                return(new SeleniumResetElement(webdriver, by, seleniumBrowser));
            }

            case "search":
            {
                return(new SeleniumSearchElement(webdriver, by, seleniumBrowser));
            }

            case "tel":
            {
                return(new SeleniumTelElement(webdriver, by, seleniumBrowser));
            }

            case "time":
            {
                return(new SeleniumTimeElement(webdriver, by, seleniumBrowser));
            }

            case "url":
            {
                return(new SeleniumUrlElement(webdriver, by, seleniumBrowser));
            }

            case "week":
            {
                return(new SeleniumWeekElement(webdriver, by, seleniumBrowser));
            }

            default:
            {
                return(new SeleniumGenericElement(webdriver, by, seleniumBrowser));
            }
            }
        }