Exemple #1
0
        protected void RunSelenium_(List <Action> actionsList)
        {
            SetLogText("");
            Stopwatch sw          = new Stopwatch();
            Stopwatch sw_internal = new Stopwatch();

            Action.StartActions();

            if (txtRootURL.Text == "")
            {
                MessageBox.Show("Please provide root url!", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                return;
            }
            IWebDriver browser = null;

            try
            {
                browser = new FirefoxDriver();
                Thread.Sleep(5 * 1000);
                {
                    EnablePaneAction(false);

                    for (int i = 0; i < txtRunTimes.Value; i++)
                    {
                        if (backgroundWorker1.CancellationPending)
                        {
                            break;
                        }

                        Log.WriteLog(">> Started " + (i + 1).ToString() + " iteration.", Color.Blue);
                        int actionIndex = 0;

                        foreach (var action in actionsList)
                        {
                            if (backgroundWorker1.CancellationPending)
                            {
                                break;
                            }

                            action.RestoreState();

                            //Append new line
                            Log.WriteLog("", Color.White);

                            SetPaneAction(actionIndex++);

                            if (GlobalSettings.Instance.SaveScreenShots)
                            {
                                string before_img_name = LogDir + "\\" + "TestScreen_.jpg".AppendTimeStamp();
                                browser.CaptureWebPageToFile(before_img_name);
                                Log.WriteLog("Before Image Name: " + before_img_name, Color.Blue);
                            }

                            Action theAction = (Action)action;
                            sw_internal.Restart();
                            Action.Result result = theAction.Run(browser, sw, txtRootURL.Text);
                            sw_internal.Stop();

                            if (GlobalSettings.Instance.SaveScreenShots)
                            {
                                string after_img_name = LogDir + "\\" + "TestScreen_.jpg".AppendTimeStamp();
                                browser.CaptureWebPageToFile(after_img_name);
                                Log.WriteLog("After Image Name: " + after_img_name, Color.Blue);
                            }

                            Log.WriteLog("### Time Elapsed:" + sw_internal.Elapsed.ToString(), Color.Green);

                            if (result == Action.Result.StopAndCloseBrowser)
                            {
                                CloseBrowserIfNeeded(browser);
                                break;
                            }
                            else if (result == Action.Result.Stop)
                            {
                                break;
                            }
                            //Append new line
                            Log.WriteLog("", Color.White);

                            System.Threading.Thread.Sleep(1500);
                        }
                        //Append new line
                        Log.WriteLog("", Color.White);
                        //New iteration
                        Log.WriteLog("@@@@@ Finished " + (i + 1).ToString() + " iteration.", Color.Blue);
                        //Append new line
                        Log.WriteLog("", Color.White);

                        foreach (var action in actionsList)
                        {
                            action.OnTestEnd();
                        }
                    }
                    Log.WriteLog("Finished running actions.", Color.Blue);
                    if (!String.IsNullOrEmpty(this.TestFileName))
                    {
                        Log.Dump(this.TestFileName);
                    }
                }
            }
            catch (Exception ex)
            {
                Log.WriteLog(ex.Message, Color.Red);
            }
            finally
            {
                if (browser != null)
                {
                    CloseBrowserIfNeeded(browser, true);
                }
            }

            EnablePaneAction(true);

            ShowNotification(false);
        }