/// <summary>
        /// Executes the command.
        /// </summary>
        /// <param name="environment">The <see cref="CommandEnvironment"/> to use in executing the command.</param>
        /// <param name="parameters">The <see cref="Dictionary{string, object}"/> containing the command parameters.</param>
        /// <returns>The JSON serialized string representing the command response.</returns>
        public override Response Execute(CommandEnvironment environment, Dictionary <string, object> parameters)
        {
            WebBrowserNavigationMonitor monitor = new WebBrowserNavigationMonitor(environment);

            monitor.MonitorNavigation(() =>
            {
                environment.Browser.Dispatcher.BeginInvoke(() =>
                {
                    if (environment.Browser.CanGoBack)
                    {
                        environment.Browser.GoBack();
                    }
                    else
                    {
                        monitor.SetNavigationSuccessful();
                    }
                });
            });

            if (monitor.IsNavigationTimedOut)
            {
                return(Response.CreateErrorResponse(WebDriverStatusCode.Timeout, "Timed out loading page"));
            }

            environment.FocusedFrame = string.Empty;

            return(Response.CreateSuccessResponse());
        }
Esempio n. 2
0
        /// <summary>
        /// Executes the command.
        /// </summary>
        /// <param name="environment">The <see cref="CommandEnvironment"/> to use in executing the command.</param>
        /// <param name="parameters">The <see cref="Dictionary{string, object}"/> containing the command parameters.</param>
        /// <returns>The JSON serialized string representing the command response.</returns>
        public override Response Execute(CommandEnvironment environment, Dictionary <string, object> parameters)
        {
            WebBrowserNavigationMonitor monitor = new WebBrowserNavigationMonitor(environment);

            monitor.MonitorNavigation(() =>
            {
                string refreshScript = "window.location.reload(true);";
                this.EvaluateAtom(environment, WebDriverAtoms.ExecuteScript, refreshScript, new object[] { }, environment.CreateFrameObject());
            });

            if (monitor.IsNavigationTimedOut)
            {
                return(Response.CreateErrorResponse(WebDriverStatusCode.Timeout, "Timed out loading page"));
            }

            environment.FocusedFrame = string.Empty;

            return(Response.CreateSuccessResponse());
        }
Esempio n. 3
0
        /// <summary>
        /// Executes the command.
        /// </summary>
        /// <param name="environment">The <see cref="CommandEnvironment"/> to use in executing the command.</param>
        /// <param name="parameters">The <see cref="Dictionary{string, object}"/> containing the command parameters.</param>
        /// <returns>The JSON serialized string representing the command response.</returns>
        public override Response Execute(CommandEnvironment environment, Dictionary <string, object> parameters)
        {
            object url;

            if (!parameters.TryGetValue("url", out url))
            {
                return(Response.CreateMissingParametersResponse("url"));
            }

            Uri targetUri = null;

            if (!Uri.TryCreate(url.ToString(), UriKind.Absolute, out targetUri))
            {
                return(Response.CreateErrorResponse(WebDriverStatusCode.UnhandledError, string.Format(CultureInfo.InvariantCulture, "Could not create valie URL from {0}", url.ToString())));
            }

            int timeoutInMilliseconds = environment.PageLoadTimeout;

            if (timeoutInMilliseconds < 0)
            {
                timeoutInMilliseconds = 15000;
            }
            else
            {
                // If a page load timeout has been set, don't retry the page load.
                this.retryCount = 1;
            }

            WebBrowserNavigationMonitor monitor = new WebBrowserNavigationMonitor(environment);

            for (int retries = 0; retries < this.retryCount; retries++)
            {
                monitor.MonitorNavigation(() =>
                {
                    /*environment.Browser.Dispatcher.BeginInvoke(() =>
                     * {
                     *  environment.Browser.Navigate(targetUri);
                     * });*/
                });

                if ((monitor.IsSuccessfullyNavigated && monitor.IsLoadCompleted) || monitor.IsNavigationError)
                {
                    break;
                }
            }

            if (monitor.IsNavigationTimedOut)
            {
                return(Response.CreateErrorResponse(WebDriverStatusCode.Timeout, "Timed out loading page"));
            }

            if (!monitor.IsNavigationError)
            {
                environment.FocusedFrame = string.Empty;
            }

            if (this.handleAlerts)
            {
                this.EvaluateAtom(environment, AlertHandler);
            }

            return(Response.CreateSuccessResponse());
        }