예제 #1
0
        /// <summary>
        /// Finds the element.
        /// </summary>
        /// <param name="webDriver">The web driver.</param>
        /// <param name="method">The method.</param>
        /// <param name="elementName">Name of the element.</param>
        /// <returns></returns>
        /// <exception cref="System.ArgumentException">Invalid driver.</exception>
        public static IWebElement FindElement(this IWebDriver webDriver, ElementLocatorMethods method, string elementName)
        {
            if (!(webDriver is RemoteWebDriver driver))
            {
                throw new ArgumentException("Invalid driver.");
            }

            if (string.IsNullOrEmpty(elementName))
            {
                throw new ArgumentNullException(nameof(elementName));
            }

            switch (method)
            {
            case ElementLocatorMethods.ID:
                return(driver.FindElementById(elementName));

            case ElementLocatorMethods.ClassName:
                return(driver.FindElementByClassName(elementName));

            case ElementLocatorMethods.CssSelector:
                return(driver.FindElementByCssSelector(elementName));

            case ElementLocatorMethods.LinkText:
                return(driver.FindElementByLinkText(elementName));

            case ElementLocatorMethods.Name:
                return(driver.FindElementByName(elementName));

            case ElementLocatorMethods.None:
                return(null);

            case ElementLocatorMethods.PartialLinkText:
                return(driver.FindElementByPartialLinkText(elementName));

            case ElementLocatorMethods.TagName:
                return(driver.FindElementByTagName(elementName));

            case ElementLocatorMethods.XPath:
                return(driver.FindElementByXPath(elementName));
            }

            return(null);
        }
예제 #2
0
        /// <summary>
        /// Initializes a new instance of the <see cref="ClickActivity" /> class.
        /// </summary>
        /// <param name="step">The step.</param>
        /// <param name="reporter"></param>
        /// <param name="driver"></param>
        /// <exception cref="System.ArgumentNullException">Element</exception>
        /// <exception cref="System.ArgumentException">Invalid value specified. - ElementLocator</exception>
        public ClickActivity(
            ITestStep step,
            IReporter reporter,
            IAutomationDriver driver)
            : base(step, reporter, driver)
        {
            if (string.IsNullOrEmpty(step.Element))
            {
                throw new ArgumentNullException(nameof(step.Element));
            }

            if (step.ElementLocator == ElementLocatorMethods.None)
            {
                throw new ArgumentException("Invalid value specified.", nameof(step.ElementLocator));
            }

            _element        = step.Element;
            _elementLocator = step.ElementLocator;
        }
예제 #3
0
        /// <summary>
        /// Initializes a new instance of the <see cref="SetValueActivity" /> class.
        /// </summary>
        /// <param name="step">The step.</param>
        /// <param name="reporter">The reporter.</param>
        /// <param name="driver">The driver.</param>
        /// <exception cref="System.ArgumentNullException">Element or Argument</exception>
        /// <exception cref="System.InvalidOperationException"></exception>
        public SetValueActivity(ITestStep step, IReporter reporter, IAutomationDriver driver)
            : base(step, reporter, driver)
        {
            if (string.IsNullOrEmpty(step.Element))
            {
                throw new ArgumentNullException(nameof(step.Element));
            }

            if (step.ElementLocator == ElementLocatorMethods.None)
            {
                throw new InvalidOperationException($"Invalid ElementLocator: {step.ElementLocator}");
            }

            if (string.IsNullOrEmpty(step.Argument))
            {
                throw new ArgumentNullException(nameof(step.Argument));
            }

            _element        = step.Element;
            _argument       = step.Argument;
            _elementLocator = step.ElementLocator;
        }