protected void RunSelenium(MainForm form, List <Action> actionsList) { form.SetLogText(""); Stopwatch sw = new Stopwatch(); Stopwatch sw_internal = new Stopwatch(); Action.StartActions(); IWebDriver browser = null; try { // READ! !Make sure to add the path to where you extracting the chromedriver.exe: // If missing - download from here: http://chromedriver.chromium.org/downloads browser = new ChromeDriver(@"E:\RegScore\RegScoreCalc-Ding\RegScoreDev-branch\WebAppTest\chromedriver_win32"); Thread.Sleep(5 * 1000); { form.EnablePaneAction(false); for (int i = 0; i < _args.RunTimes; i++) { Log.WriteLog(">>Started " + (i + 1).ToString() + " iteration.", Color.Blue); int actionIndex = 0; foreach (var action in actionsList) { action.RestoreState(); //Append new line Log.WriteLog("", Color.White); form.SetPaneAction(actionIndex++); if (GlobalSettings.Instance.SaveScreenShots) { string before_img_name = System.Environment.CurrentDirectory + "\\" + "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, _args.URL); sw_internal.Stop(); if (GlobalSettings.Instance.SaveScreenShots) { string after_img_name = System.Environment.CurrentDirectory + "\\" + "TestScreen_.jpg".AppendTimeStamp(); browser.CaptureWebPageToFile(after_img_name); Log.WriteLog("After Image Name: " + after_img_name, Color.Blue); } if (result == Action.Result.StopAndCloseBrowser) { CloseBrowserIfNeeded(browser); break; } else if (result == Action.Result.Stop) { break; } System.Threading.Thread.Sleep(1500); } //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(); } } } } catch (Exception ex) { LogTask logMsg = new LogTask { message = ex.Message, status = TaskCompletionStatus.Error, TaskName = "ActionRunner class", TimeNetto = sw.Elapsed }; Log.WriteLog(logMsg); } finally { if (browser != null) { CloseBrowserIfNeeded(browser, true); } } }
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); }