Esempio n. 1
0
        public static By SeleniumSelector(ISelector selector)
        {
            switch (selector.SelectorType)
            {
            case SelectorType.Name:
                return(By.Name(selector.SelectorValue));

            case SelectorType.Id:
                return(By.Id(selector.SelectorValue));

            case SelectorType.ElementType:
                return(By.TagName(selector.SelectorValue));

            case SelectorType.LinkText:
                return(By.LinkText(selector.SelectorValue));

            case SelectorType.CssSelector:
                return(By.CssSelector(selector.SelectorValue));

            case SelectorType.XPath:
                return(By.XPath(selector.SelectorValue));

            default:
                throw new ArgumentOutOfRangeException();
            }
        }
Esempio n. 2
0
        public OpenQA.Selenium.IWebElement FindElement(OpenQA.Selenium.By by)
        {
            if (Tag == null)
            {
                throw new NullReferenceException("You can't call GetElement on a block without first initializing Tag.");
            }

            return(Tag.FindElement(by));
        }
Esempio n. 3
0
        /// <summary>
        /// Display EnterText - Enter text into field one character at a time.
        /// </summary>
        /// <param name="by">Field to enter text to.</param>
        /// <param name="searchString">Text to enter.</param>
        /// <param name="sendEnter">If true, send 'Enter' after text string.</param>
        private static void DisplayEnterText(OpenQA.Selenium.By by, string searchString, bool sendEnter = false)
        {
            String ENTER = OpenQA.Selenium.Keys.Enter;

            WebActions.EnterText(by, "");
            foreach (char key in searchString.ToCharArray())
            {
                WebActions.AppendText(by, "" + key, 100);
            }
            Thread.Sleep(1000);

            if (sendEnter)
            {
                WebActions.AppendText(by, ENTER, 100);
            }
        }
Esempio n. 4
0
        // ************ DATE 10/16/2020 ************
        // All the Builders used till date.
        // ***** IMPORTANT: This Builder return a new class of type By from OpenQA.Selenium
        // ************ --------------- ************
        #region BUILDERS


        /// <summary>
        /// Builds a By object using the enum pass
        /// </summary>
        /// <param name="by">Represents the Enum in Share class.</param>
        /// <param name="value">Value used to find the element.</param>
        /// <param name="element">The element type.</param>
        /// <param name="isWidget">True if it is a widget, false if it is a View.</param>
        public static By BuildBy(Share.By by, Share.Element element, bool isWidget = true)
        {
            var attribute = Misc.BuildElement(isWidget, element);
            By  _by       = null;

            switch (by)
            {
            case Share.By.ClassName:
                _by = By.ClassName(attribute);
                break;

            case Share.By.CssSelector:
                _by = By.CssSelector(attribute);
                break;

            case Share.By.Id:
                _by = By.Id(attribute);
                break;

            case Share.By.LinkText:
                _by = By.LinkText(attribute);
                break;

            case Share.By.Name:
                _by = By.Name(attribute);
                break;

            case Share.By.PartialLinkText:
                _by = By.PartialLinkText(attribute);
                break;

            case Share.By.TagName:
                _by = By.TagName(attribute);
                break;

            case Share.By.XPath:
                _by = By.XPath(attribute);
                break;
            }
            return(_by);
        }
Esempio n. 5
0
 public static OpenQA.Selenium.IWebElement FindElement(
     this OpenQA.Selenium.IWebDriver driver,
     OpenQA.Selenium.By by,
     int timeoutInSeconds,
     bool waitForClickable = false)
 {
     if (timeoutInSeconds > 0)
     {
         var wait = new OpenQA.Selenium.Support.UI.WebDriverWait(driver, TimeSpan.FromSeconds(timeoutInSeconds));
         wait.PollingInterval = TimeSpan.FromMilliseconds(500);
         wait.IgnoreExceptionTypes(typeof(OpenQA.Selenium.ElementNotInteractableException), typeof(OpenQA.Selenium.NoSuchElementException), typeof(OpenQA.Selenium.WebDriverTimeoutException));
         wait.Until(drv =>
         {
             var elemList = drv.FindElements(by);
             return((!waitForClickable && elemList.Count == 1) ||
                    (waitForClickable && elemList.Count == 1 && elemList[0].Displayed && elemList[0].Enabled));
         }
                    );
     }
     return(driver.FindElement(by));
 }
Esempio n. 6
0
        public static By ToSeleniumBy(this QAAcademyDemo.TestFramework.Core.Drivers.By by)
        {
            var result = default(By);

            switch (by.SearchCriteria)
            {
            case SearchCriteria.Id:
                result = By.Id(by.SearchCriteriaValue);
                break;

            case SearchCriteria.XPath:
                result = By.XPath(by.SearchCriteriaValue);
                break;

            case SearchCriteria.ClassName:
                result = By.ClassName(by.SearchCriteriaValue);
                break;

            default:
                break;
            }
            return(result);
        }
Esempio n. 7
0
 public void JQueryByCanBeImplicitlyCastToSeleniumBy()
 {
     OpenQA.Selenium.By implicitCast = By.jQuery(".test");
     implicitCast.ShouldNotBeNull();
     implicitCast.ShouldBeOfType <JavaScriptBy>();
 }
 public void ShouldCreateSelector(SeleniumBy sut) => sut.Should().NotBeNull();
 public void ShouldCreateSelector(OpenQA.Selenium.By sut) => sut.Should().NotBeNull();
Esempio n. 10
0
 public static string Xpath(this OpenQA.Selenium.By by)
 => by.ToString().Substring("By.XPath: ".Length);
Esempio n. 11
0
 public static bool IsXpath(this OpenQA.Selenium.By by)
 => by != null && by.ToString().StartsWith("By.XPath: ");
Esempio n. 12
0
 private By(OpenQA.Selenium.By by)
 {
     this._by = by;
 }
Esempio n. 13
0
 private By(OpenQA.Selenium.By by) {
     this._by = by;
 }