/// <summary>
        /// Since kendo events aren't compatible with native js events use this
        /// method to listen for kendo events.
        /// </summary>
        /// <param name="eventName">Name of the event to listen for.</param>
        protected virtual PromiseBody GetPromiseForKendoEvent(
            string eventName)
        {
            var script =
                "var callback = {resolve};" +
                "var $el = $({args}[0]);" +
                "var dropdown = $el.data().kendoDropDownList;" +
                "var unbindCallback = function () {" +
                $"dropdown.unbind('{eventName}', unbindCallback);" +
                "callback();" +
                "};" +
                $"dropdown.bind('{eventName}', unbindCallback);";

            var promise = new PromiseBody(WrappedDriver)
            {
                Arguments = new JavaScriptValue[]
                {
                    new JavaScriptValue(WrappedElement)
                },
                Script = script
            };

            promise.Execute(WrappedDriver.JavaScriptExecutor());

            return(promise);
        }
        /// <summary>
        /// Creates an activated SeleniumJavaScriptPromiseBody and returns it.
        /// NOTE: Don't call CreateScript(...) on the returned object as it has
        /// already been called.
        /// </summary>
        /// <param name="element">The element.</param>
        /// <param name="eventName">Name of the event.</param>
        /// <returns></returns>
        /// <exception cref="ArgumentNullException">eventName</exception>
        public static PromiseBody GetEventWaiter(
            this IWebElement element,
            string eventName)
        {
            if (element == null)
            {
                throw new ArgumentNullException(nameof(element));
            }

            var el = element.UnWrapEventFiringWebElement();

            if (String.IsNullOrEmpty(eventName))
            {
                throw new ArgumentNullException(nameof(eventName));
            }

            var waiter = new PromiseBody(el.GetDriver())
            {
                Arguments = new[] { new JavaScriptValue(el) },
                Script    =
                    "var el = {args}[0];" +
                    "var callback = {resolve};" +
                    "var eventListener = el.addEventListener('" + eventName + "'," +
                    "function(e) {" +
                    "el.removeEventListener('" + eventName + "', eventListener);" +
                    "callback();" +
                    "});"
            };

            waiter.Execute(el.GetDriver().JavaScriptExecutor());

            return(waiter);
        }
        private void WaitForInitalization()
        {
            var wait      = WrappedDriver.Wait(TimeSpan.FromSeconds(10));
            var timeoutMS = wait.Timeout.TotalMilliseconds;
            var pollingMS = wait.PollingInterval.TotalMilliseconds;

            var script =
                AddTinyMCEUtilities(String.Empty) +
                "var el = {args}[0];" +
                "var editor = tinyMCEUtilities.getEditor(el);" +
                "tinyMCEUtilities.waitForInitialization(editor," +
                $"{timeoutMS}," +
                $"{pollingMS}," +
                "{resolve}," +
                "{reject});";

            script = JavaScript.RemoveComments(script);
            script = JavaScript.Clean(script);

            var waiter = new PromiseBody(WrappedDriver)
            {
                Arguments = new[] { new JavaScriptValue(WrappedElement) },
                Script    = script
            };

            // Condense the script.
            waiter.Format();

            waiter.Execute(WrappedDriver.JavaScriptExecutor());
            wait.Until(d => waiter.Finished);
            waiter.Wait(TimeSpan.FromSeconds(10));
        }
Example #4
0
        public static void CreatePointAtCurrentMousePosition(this IWebDriver driver)
        {
            var js = new PromiseBody(driver)
            {
                Script = Resources.createPointAtCurrentMousePosition
            };

            js.Execute(driver.JavaScriptExecutor());

            driver.CreateActions()
            .MoveByOffset(1, 1)
            .MoveByOffset(-1, -1)
            .Perform();

            js.Wait(TimeSpan.FromSeconds(2));
        }