public void StopDriver()
        {
            MyLog.Write("StopDriver - Entered");
            view.DisableDriverStartButton();

            view.DriverIsStopping();

            Exception threadException;

            UIActions.PerformSlowOperation(
                "Operation: Stop WebDriver instance",
                () =>
            {
                Presenters.SwdMainPresenter.StopVisualSearch();
                SwdBrowser.CloseDriver();
            },
                out threadException,
                null,
                TimeSpan.FromMinutes(10)
                );

            if (threadException != null)
            {
                MyLog.Exception(threadException);
            }

            view.EnableDriverStartButton();

            wasBrowserStarted = false;
            MyLog.Write("StopDriver - Exited");
        }
        public void RefreshFramesList()
        {
            Exception outException;
            bool      isOk = false;

            isOk = UIActions.PerformSlowOperation(
                "Operation: Refresh All Frames List",
                () =>
            {
                BrowserPageFrame rootFrame           = SwdBrowser.GetPageFramesTree();
                BrowserPageFrame[] currentPageFrames = rootFrame.ToList().ToArray();
                SwdBrowser.SwitchToDefaultContent();
                view.UpdatePageFramesList(currentPageFrames);
            },
                out outException,
                null,
                TimeSpan.FromMinutes(1)
                );

            if (!isOk)
            {
                MyLog.Error("Failed to refresh All Frames List");
                MyLog.Exception(outException);
                if (outException != null)
                {
                    throw outException;
                }
            }
        }
        public void RefreshWindowsList()
        {
            Exception outException;
            bool      isOk = false;

            isOk = UIActions.PerformSlowOperation(
                "Operation: Refresh All Windows List",
                () =>
            {
                BrowserWindow[] currentWindows = SwdBrowser.GetBrowserWindows();
                string currentWindowHandle     = SwdBrowser.GetCurrentWindowHandle();
                view.UpdateBrowserWindowsList(currentWindows, currentWindowHandle);
            },
                out outException,
                null,
                TimeSpan.FromMinutes(1)
                );

            if (!isOk)
            {
                MyLog.Error("Failed to refresh All Windows List");
                if (outException != null)
                {
                    throw outException;
                }
            }
        }
        internal void RunScript()
        {
            string scriptFromEditor = view.GetJavaScriptCodeFromEditor();

            Exception outException;
            bool      isOk   = false;
            object    result = null;

            isOk = UIActions.PerformSlowOperation(
                "Operation: RunScript() / Executing JavaScript Snippet",
                () =>
            {
                result = SwdBrowser.ExecuteJavaScript(scriptFromEditor);
            },
                out outException,
                null,
                TimeSpan.FromMinutes(1)
                );

            if (!isOk)
            {
                MyLog.Error("RunScript() Failed to execute JavaScript snippet");
                MyLog.Exception(outException);
                if (outException != null)
                {
                    throw outException;
                }
            }

            string consoleOut = DumpObject(result);

            view.AppendConsole(consoleOut);
        }
        public void StartDriver(WebDriverOptions browserOptions, bool shouldMaximizeBrowserWindow)
        {
            MyLog.Write("StartDriver - Entered");

            wasBrowserStarted = false;

            view.DisableDriverStartButton();

            Exception threadException;

            bool isSuccessful = UIActions.PerformSlowOperation(
                "Operation: Start new WebDriver instance",
                () =>
            {
                SwdBrowser.Initialize(browserOptions);
                wasBrowserStarted = true;

                if (shouldMaximizeBrowserWindow)
                {
                    SwdBrowser.Maximize();
                }
            },
                out threadException,
                null,
                TimeSpan.FromMinutes(10)
                );

            view.EnableDriverStartButton();

            if (isSuccessful)
            {
                SetDesiredCapabilities(browserOptions);
                view.DriverWasStarted();
            }
            else if (threadException != null)
            {
                throw threadException;
            }

            MyLog.Write("StartDriver - Exited");
        }
        public void StartNewBrowser(WebDriverOptions browserOptions, bool startSeleniumServerIfNotStarted, bool shouldMaximizeBrowserWindow)
        {
            if (wasBrowserStarted)
            {
                StopDriver();
            }
            else
            {
                if (startSeleniumServerIfNotStarted &&
                    !SeleniumServerProcess.IsRunning(browserOptions.RemoteUrl))
                {
                    Exception outException;
                    bool      isOk = UIActions.PerformSlowOperation(
                        "Operation: Start local RemoteWebDriver Server",
                        () =>
                    {
                        SeleniumServerProcess.Launch("start_selenium_server.bat");
                        TestRemoteHub(browserOptions.RemoteUrl);
                    },
                        out outException,
                        null,
                        TimeSpan.FromMinutes(2)
                        );

                    if (!isOk)
                    {
                        MyLog.Error("Failed to start local Selenium Server");
                        if (outException != null)
                        {
                            throw outException;
                        }
                    }
                }

                StartDriver(browserOptions, shouldMaximizeBrowserWindow);
            }
        }