示例#1
0
        public void RefreshWindowsList()
        {
            Exception outException;
            bool      isOk = false;

            isOk = UIActions.PerformSlowOperation(
                "Operation: Refresh All Windows List",
                () =>
            {
                BrowserWindow[] currentWindows = WebSpyBrowser.GetBrowserWindows();
                string currentWindowHandle     = WebSpyBrowser.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;
                }
            }
        }
示例#2
0
        public void RefreshFramesList()
        {
            Exception outException;
            bool      isOk = false;

            isOk = UIActions.PerformSlowOperation(
                "Operation: Refresh All Frames List",
                () =>
            {
                BrowserPageFrame rootFrame           = WebSpyBrowser.GetPageFramesTree();
                BrowserPageFrame[] currentPageFrames = rootFrame.ToList().ToArray();
                WebSpyBrowser.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 StopDriver()
        {
            MyLog.Write("StopDriver - Entered");
            view.DisableDriverStartButton();

            view.DriverIsStopping();

            Exception threadException;

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

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

            view.EnableDriverStartButton();

            wasBrowserStarted = false;
            MyLog.Write("StopDriver - Exited");
        }
        internal void RunScript()
        {
            string scriptFromEditor = view.GetJavaScriptCodeFromEditor();

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

            isOk = UIActions.PerformSlowOperation(
                "Operation: RunScript() / Executing JavaScript Snippet",
                () =>
            {
                result = WebSpyBrowser.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",
                () =>
            {
                WebSpyBrowser.Initialize(browserOptions);
                wasBrowserStarted = true;

                if (shouldMaximizeBrowserWindow)
                {
                    WebSpyBrowser.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);
            }
        }