コード例 #1
0
        /// <summary>
        /// Finds the first <see cref="IWebElement"/> within the current context using the given mechanism.
        /// </summary>
        /// <param name="e">This <see cref="IWebElement"/> under which to find the elements.</param>
        /// <param name="byFactory"><see cref="ByFactory"/> instance by which to create locator from <see cref="ActionRule"/></param>
        /// <param name="actionRule">Action rule by which to perform search and build conditions.</param>
        /// <returns>An <see cref="IWebElement"/> interface through which the user controls elements on the page.</returns>
        public static IWebElement GetElementByActionRule(this IWebElement e, ByFactory byFactory, ActionRule actionRule, TimeSpan timeout)
        {
            // on-element conditions
            var isOnElement = e != default && string.IsNullOrEmpty(actionRule.ElementToActOn);

            if (isOnElement)
            {
                return(e);
            }

            // get locator
            var by = byFactory.Get(actionRule.Locator, actionRule.ElementToActOn);

            // setup conditions
            var isAbsolutePath = actionRule.Locator == LocatorType.Xpath && actionRule.ElementToActOn.StartsWith("/");

            // find on page level
            if (isAbsolutePath)
            {
                return(((IWrapsDriver)e).WrappedDriver.GetElement(by, timeout));
            }

            // on element level
            return(e.FindElement(by));
        }
コード例 #2
0
        /// <summary>
        /// Finds all <see cref="IWebElement"/> within the current context using the given mechanism.
        /// </summary>
        /// <param name="e">This <see cref="IWebElement"/> under which to find the elements.</param>
        /// <param name="byFactory"><see cref="ByFactory"/> instance by which to create locator from <see cref="ActionRule"/></param>
        /// <param name="actionRule">Action rule by which to perform search and build conditions.</param>
        /// <returns>A collection of all <see cref="IWebElement"/> matching the current criteria, or an empty list if nothing matches.</returns>
        public static ReadOnlyCollection <IWebElement> FindElementsByActionRule(this IWebElement e, ByFactory byFactory, ActionRule actionRule)
        {
            // on-element conditions
            var isOnElement = e != default && !string.IsNullOrEmpty(actionRule.ElementToActOn);

            if (isOnElement)
            {
                return(new ReadOnlyCollection <IWebElement>(new List <IWebElement> {
                    e
                }));
            }

            // get locator
            var by = byFactory.Get(actionRule.Locator, actionRule.ElementToActOn);

            // setup conditions
            var isAbsolutePath = actionRule.Locator == LocatorType.Xpath && actionRule.ElementToActOn.StartsWith("/");

            // find on page level
            if (isAbsolutePath)
            {
                return(((IWrapsDriver)e).WrappedDriver.FindElements(by));
            }

            // on element level
            return(e.FindElements(by));
        }
コード例 #3
0
        // executes a child process with elements listener
        private void DoListener(ActionRule actionRule)
        {
            // get arguments
            ProcessArguments(actionRule.Argument);

            // setup
            var interval   = (int)GetTimeSapnFromArgument(Interval).TotalMilliseconds;
            var expiration = (int)GetTimeSapnFromArgument(ListenerTimout).TotalMilliseconds;
            var by         = ByFactory.Get(actionRule.Locator, actionRule.ElementToActOn);

            // publish action rule to execute on the found elements
            var childActionRule = new ActionRule
            {
                ActionType = arguments[ActionToPerform],
                Argument   = childActionArgument,
                Actions    = actionRule.Actions
            };

            // execute listener
            var expire = 0;

            while (WebDriver != null && expire <= expiration)
            {
                // execute heartbeat
                DoListenerHeartbeat(childActionRule, by, interval);

                // set expiration time
                expire += interval;
            }
        }
コード例 #4
0
        /// <summary>
        /// Finds the first <see cref="IWebElement"/> within the current context using the given mechanism.
        /// </summary>
        /// <param name="d">This <see cref="IWebDriver"/> under which to find the elements.</param>
        /// <param name="byFactory"><see cref="ByFactory"/> instance by which to create locator from <see cref="ActionRule"/></param>
        /// <param name="actionRule">Action rule by which to perform search and build conditions.</param>
        /// <param name="timeout">The timeout value indicating how long to wait for the condition (element exists).</param>
        /// <returns>An <see cref="IWebElement"/> interface through which the user controls elements on the page.</returns>
        /// <remarks>This method waits until the elements exists in the DOM.</remarks>
        public static IWebElement GetElementByActionRule(this IWebDriver d, ByFactory byFactory, ActionRule actionRule, TimeSpan timeout)
        {
            // get locator
            var by = byFactory.Get(actionRule.Locator, actionRule.ElementToActOn);

            // get elements
            return(d.GetElement(by, timeout));
        }
コード例 #5
0
        /// <summary>
        /// Finds all <see cref="IWebElement"/> within the current context using the given mechanism.
        /// </summary>
        /// <param name="d">This <see cref="IWebDriver"/> under which to find the elements.</param>
        /// <param name="byFactory"><see cref="ByFactory"/> instance by which to create locator from <see cref="ActionRule"/></param>
        /// <param name="actionRule">Action rule by which to perform search and build conditions.</param>
        /// <returns>A collection of all <see cref="IWebElement"/> matching the current criteria, or an empty list if nothing matches.</returns>
        public static ReadOnlyCollection <IWebElement> FindElementsByActionRule(this IWebDriver d, ByFactory byFactory, ActionRule actionRule)
        {
            // get locator
            var by = byFactory.Get(actionRule.Locator, actionRule.ElementToActOn);

            // get elements
            return(d.FindElements(by));
        }
コード例 #6
0
 public OpenQA.Selenium.By GetBy(params string[] placeholders)
 {
     return(ByFactory.Get(byType, expression, placeholders));
 }