public void Run() { Mouse.DefaultMoveTime = 300; Keyboard.DefaultKeyPressTime = 100; Delay.SpeedFactor = 1.0; RanorexRepository repo = new RanorexRepository(); SpeechSynthesizer Speech = new SpeechSynthesizer(); fnPlayWavFile PlayWavFile = new fnPlayWavFile(); // System.DateTime DateTimeNow = System.DateTime.Now; // System.TimeSpan TimeNow = DateTimeNow.TimeOfDay; // Play error sound Global.WavFilePath = "Error.wav"; PlayWavFile.Run(); // Write out failure to error .csv file (Global.TempString contains text to be written) string TextToPrint = Global.RegisterName + "," + System.DateTime.Now.ToString() + "," + Global.CurrentIteration + "," + "Scenario: " + Global.CurrentScenario + "," + Global.TempErrorString; using (System.IO.StreamWriter file = new System.IO.StreamWriter(Global.ErrorFileName, Global.OpenFileForAppend)) { file.WriteLine(TextToPrint); } Global.ErrorsToday++; // PAL Status Monitor if (Global.SwitchQuitRunningOnError) { if (Global.DoRegisterSoundAlerts) { Speech.Speak("An error has occurred, aborting the run"); } Environment.Exit(0); } }
public void Run(string TempText) { Mouse.DefaultMoveTime = 300; Keyboard.DefaultKeyPressTime = 100; Delay.SpeedFactor = 1.0; RanorexRepository repo = new RanorexRepository(); fnWriteToLogFile WriteToLogFile = new fnWriteToLogFile(); fnPlayWavFile PlayWavFile = new fnPlayWavFile(); Global.LogFileIndentLevel++; Global.LogText = "IN fnParseSwitches"; WriteToLogFile.Run(); if (TempText.Contains("/")) { // Process switches if (TempText.Contains("N") | TempText.Contains("L")) { // if any of these are given then reset all and only use ones listed Global.SwitchPhoneNumbersNonLoyalty = false; Global.SwitchPhoneNumbersLoyalty = false; } if (TempText.Contains("P")) { Global.SwitchPauseBetweenScenariosOff = true; } if (TempText.Contains("N")) { Global.SwitchPhoneNumbersNonLoyalty = true; } if (TempText.Contains("L")) { Global.SwitchPhoneNumbersLoyalty = true; } if (TempText.Contains("A")) { Global.SwitchAllRegistersUseAllPhoneNumbers = true; } if (TempText.Contains("S")) { Global.SwitchScenario9Use40SKUs = true; } if (TempText.Contains("M")) { Global.SwitchMetricOverRide = true; } if (TempText.Contains("Q")) { Global.SwitchQuitRunningOnError = true; } if (TempText.Contains("U")) { Global.SwitchUploadOnly = true; Global.IsPerformanceTest = true; } if (TempText.Contains("X")) { Global.SwitchSkipCustomerLookup = true; if (Global.DoScenarioFlag[17] || Global.DoScenarioFlag[20] || Global.DoScenarioFlag[21] || Global.DoScenarioFlag[22] || Global.DoScenarioFlag[23] || Global.DoScenarioFlag[25]) { Global.WavFilePath = "SlashXSwitchSelections.wav"; PlayWavFile.Run(); } Global.DoScenarioFlag[17] = false; // the /X switch cannot override phone looku Global.DoScenarioFlag[20] = false; Global.DoScenarioFlag[21] = false; Global.DoScenarioFlag[22] = false; Global.DoScenarioFlag[23] = false; Global.DoScenarioFlag[25] = false; } } else if (TempText.Contains("-")) { // Process a range like 3-5 string[] RangeItems = TempText.Split('-'); for (int RangeOff = Convert.ToInt32(RangeItems[0]); RangeOff <= Convert.ToInt32(RangeItems[1]); RangeOff++) { Global.DoScenarioFlag[RangeOff] = true; } } else { // Process single item if (TempText != "") { Global.DoScenarioFlag[Convert.ToInt32(TempText)] = true; } } Global.LogText = "OUT fnParseSwitches"; WriteToLogFile.Run(); Global.LogFileIndentLevel--; }
public static int Main(string[] args) { // Uncomment the following 2 lines if you want to automate Windows apps // by starting the test executable directly //if (Util.IsRestartRequiredForWinAppAccess) // return Util.RestartWithUiAccess(); fnPlayWavFile PlayWavFile = new fnPlayWavFile(); fnWriteToLogFile WriteToLogFile = new fnWriteToLogFile(); fnWriteToErrorFile WriteToErrorFile = new fnWriteToErrorFile(); SpeechSynthesizer Speech = new SpeechSynthesizer(); Keyboard.AbortKey = System.Windows.Forms.Keys.Escape; int error = 0; // To autorun Scripts in directory <C: on reg1, D: on reg 2-n>/PAL/RanorexStudio Projects\Ranorex Automation\Alpha\bin\Debug // NOTE: autorun is assumed to be type Baseline // RanorexAutomation.exe auto [<iteratins-time> [<Scenario-list>] ] // <iteratins-time> = number iterations // <iteratins-time> = time to stop "6:00 am" // <iteratins-time> = time to start and stop "6:00 am to 3:00 PM" // <Scenario-list> = list if scenarios to run comma delited "3,4,6-20" // If neither <iteratins-time> or <Scenario-list> supplied will run using same paramaters as last run // Just auto <iterations-time> can be given, will ust last run scenario list // Get command line argumets Global.CommandLineArg0 = ""; Global.CommandLineArg1 = ""; Global.CommandLineArg2 = ""; Global.CommandLineArg3 = ""; string[] RanorexCmdLine = Environment.GetCommandLineArgs(); int Arguments = args.Length; switch (Arguments) { case 1: Global.CommandLineArg0 = RanorexCmdLine[0].ToUpper(); Global.CommandLineArg1 = RanorexCmdLine[1].ToUpper(); break; case 2: Global.CommandLineArg0 = RanorexCmdLine[0].ToUpper(); Global.CommandLineArg1 = RanorexCmdLine[1].ToUpper(); Global.CommandLineArg2 = RanorexCmdLine[2].ToUpper(); break; case 3: Global.CommandLineArg0 = RanorexCmdLine[0].ToUpper(); Global.CommandLineArg1 = RanorexCmdLine[1].ToUpper(); Global.CommandLineArg2 = RanorexCmdLine[2].ToUpper(); Global.CommandLineArg3 = RanorexCmdLine[3].ToUpper(); break; } // For debugging auto run // Global.CommandLineArg1 = "AUTO"; // Global.CommandLineArg2 = "1"; // Global.CommandLineArg3 = "3"; // Report.Log(ReportLevel.Info, "CommandLineStuff", // "\n" + "Arglen: " + Arguments + "\n" + // "Zero: " + Global.CommandLineArg0 + "\n" + // "One: " + Global.CommandLineArg1 + "\n" + // "Two: " + Global.CommandLineArg2 + "\n" + // "Three: " + Global.CommandLineArg3 + "\n" // , new RecordItemIndex(0)); // Thread.Sleep(10000); // Environment.Exit(0); // Onetime delay for Ranorex to setup instrumentation Thread.Sleep(5000); if (Global.CommandLineArg1 == "AUTO") { Global.AutoRun = true; } try { error = TestSuiteRunner.Run(typeof(Program), Environment.CommandLine); } catch (Exception e) { Report.Error("Unexpected exception occurred: " + e.ToString()); error = -1; Global.LogText = "Unexpected exception occurred: " + e.ToString(); WriteToLogFile.Run(); Global.TempErrorString = Global.LogText; WriteToErrorFile.Run(); Global.WavFilePath = "UnexpectedException.wav"; PlayWavFile.Run(); if (Global.DoRegisterSoundAlerts) { Speech.Speak("Register " + Global.RegisterNumber); } } fnTearDown Teardown = new fnTearDown(); Report.Log(ReportLevel.Info, "Main", "Starting Teardown", new RecordItemIndex(0)); TestModuleRunner.Run(Teardown); Report.Log(ReportLevel.Info, "Main", "Teardown Finished", new RecordItemIndex(0)); return(error); }
/// <summary> /// Performs the playback of actions in this module. /// </summary> /// <remarks>You should not call this method directly, instead pass the module /// instance to the <see cref="TestModuleRunner.Run(ITestModule)"/> method /// that will in turn invoke this method.</remarks> void ITestModule.Run() { if (!Global.SwitchUploadOnly) { Mouse.DefaultMoveTime = 300; Keyboard.DefaultKeyPressTime = 100; Delay.SpeedFactor = 1.0; Global.PhoneNumbertype = ""; // all types // Create the needed classes RanorexRepository repo = new RanorexRepository(); fnGetEndTime GetEndTime = new fnGetEndTime(); fnGetStartTime GetStartTime = new fnGetStartTime(); fnPlayWavFile PlayWavFile = new fnPlayWavFile(); fnWriteToLogFile WriteToLogFile = new fnWriteToLogFile(); fnDumpStats DumpStats = new fnDumpStats(); fnWriteToErrorFile WriteToErrorFile = new fnWriteToErrorFile(); SpeechSynthesizer Speech = new SpeechSynthesizer(); Global.LogFileIndentLevel++; Global.LogText = "IN fnDoScenarios"; WriteToLogFile.Run(); Global.CurrentIteration = 1; if (Global.TimeToStartExecution != "") { Global.LogText = "Waiting for start time - IN fnDoScenarios: " + Global.TimeToStartExecution; WriteToLogFile.Run(); Report.Log(ReportLevel.Info, "fnDoScenarios", "Waiting for start time: " + Global.TimeToStartExecution, new RecordItemIndex(0)); bool TimeToStart = false; while (!TimeToStart) { System.DateTime DateTimeNow = System.DateTime.Now; int TimeUp = System.DateTime.Compare(DateTimeNow, Convert.ToDateTime(Global.TimeToStartExecution)); if (TimeUp > 0) { TimeToStart = true; } } } Global.LoopingDone = false; while (!Global.LoopingDone) { try { DoScenarioLooping(); } catch (Exception e) { string sayString = ""; if (e.ToString().IndexOf("Thread was being aborted.") == -1) { sayString = e.ToString().Substring(0, 28); Global.TempErrorString = "Ranorex Crashed Message: " + e.Message; WriteToErrorFile.Run(); Global.WavFilePath = "RanorexCrashed.wav"; PlayWavFile.Run(); if (e.ToString().Contains("MemoryException")) { // Write out Tasklist to file in C:\PAL\Reports String.Empty string TimeStampPart = System.DateTime.Now.ToString(); TimeStampPart = Regex.Replace(TimeStampPart, @"[/]", "-"); TimeStampPart = Regex.Replace(TimeStampPart, @"[:]", "-"); TimeStampPart = Regex.Replace(TimeStampPart, @"[ ]", "_"); TimeStampPart = "(" + TimeStampPart + ")"; string CsvFilename = "Tasklist_(" + Global.RegisterName + ")_" + TimeStampPart; var proc = new Process { StartInfo = new ProcessStartInfo { FileName = Global.Register1DriveLetter + @":\PAL\Reports\GetTaskList.bat", Arguments = CsvFilename, UseShellExecute = false, RedirectStandardOutput = true, CreateNoWindow = true, WorkingDirectory = Global.Register1DriveLetter + @":\PAL\Reports\" } }; proc.Start(); } ; //Report.Snapshot("/form[@controlname='frmWebBrowserHost']"); if (Global.DoRegisterSoundAlerts) { Speech.Speak(sayString); } Global.WavFilePath = "Error.wav"; PlayWavFile.Run(); PlayWavFile.Run(); PlayWavFile.Run(); PlayWavFile.Run(); string ErrorMessage; ErrorMessage = e.ToString(); Global.LogText = @ErrorMessage; WriteToLogFile.Run(); MessageBox.Show(e.ToString(), "Ranorex has crashed"); fnTearDown Teardown = new fnTearDown(); Report.Log(ReportLevel.Info, "Main", "Starting Teardown", new RecordItemIndex(0)); TestModuleRunner.Run(Teardown); Report.Log(ReportLevel.Info, "Main", "Teardown Finished", new RecordItemIndex(0)); Environment.Exit(0); } } } Global.LogText = "OUT fnDoScenarios"; WriteToLogFile.Run(); Global.LogFileIndentLevel--; } }
// #################################################### private void DoScenarioLooping() { RanorexRepository repo = new RanorexRepository(); fnGetEndTime GetEndTime = new fnGetEndTime(); fnGetStartTime GetStartTime = new fnGetStartTime(); fnPlayWavFile PlayWavFile = new fnPlayWavFile(); fnWriteToLogFile WriteToLogFile = new fnWriteToLogFile(); fnDumpStats DumpStats = new fnDumpStats(); fnWriteToErrorFile WriteToErrorFile = new fnWriteToErrorFile(); fnUpdatePALStatusMonitor UpdatePALStatusMonitor = new fnUpdatePALStatusMonitor(); // Backoffice fnDoScenario13 DoScenario13 = new fnDoScenario13(); fnDoScenario14 DoScenario14 = new fnDoScenario14(); fnDoScenario15 DoScenario15 = new fnDoScenario15(); fnDoScenario18 DoScenario18 = new fnDoScenario18(); fnDoScenario19 DoScenario19 = new fnDoScenario19(); fnDoScenario20 DoScenario20 = new fnDoScenario20(); fnDoScenario21 DoScenario21 = new fnDoScenario21(); // Retech fnDoScenario16 DoScenario16 = new fnDoScenario16(); fnDoScenario33 DoScenario33 = new fnDoScenario33(); fnDoScenario34 DoScenario34 = new fnDoScenario34(); fnDoScenario36 DoScenario36 = new fnDoScenario36(); fnDoScenario37 DoScenario37 = new fnDoScenario37(); fnDoScenario38 DoScenario38 = new fnDoScenario38(); fnDoScenario41 DoScenario41 = new fnDoScenario41(); fnDoScenario42 DoScenario42 = new fnDoScenario42(); fnDoScenario43 DoScenario43 = new fnDoScenario43(); fnDoScenario47 DoScenario47 = new fnDoScenario47(); // Other fnDoScenario50 DoScenario50 = new fnDoScenario50(); fnUpdateItemMDB UpdateItemMDB = new fnUpdateItemMDB(); Global.LogText = "RUN STARTED - IN fnDoScenarios Iteration: " + Global.CurrentIteration; WriteToLogFile.Run(); // Decide if limited by number of iterations or time if (Global.IterationsToDo != -1) { // not equal to zero is based on number of iterations Global.StopByTime = false; } else { // equal to -1 means drive by stop time Global.StopByTime = true; } Global.DoDumpStats = false; Global.CurrentScenario = 0; Global.RetechScenariosPerformed = 0; if (Global.RegisterNumber == "1") { Global.LogText = "Updating SKU quantities"; WriteToLogFile.Run(); Global.SQLCommand = "update sku set Qty = 999999 where Qty < 5000"; UpdateItemMDB.Run(); } // If Scenario 37 Reserve Pickup then turn flag off for all SKUs EnforceStreetDate if (Global.DoScenarioFlag[37] && Global.RegisterNumber == "1") { Global.LogText = "Setting all EnforceStreetDates to false"; WriteToLogFile.Run(); Global.SQLCommand = "update sku set EnforceStreetDate = false where EnforceStreetDate = true"; UpdateItemMDB.Run(); Global.LogText = "Setting all IsStreetDateOverridden to true"; WriteToLogFile.Run(); Global.SQLCommand = "update sku set IsStreetDateOverridden = true where IsStreetDateOverridden = false"; UpdateItemMDB.Run(); } // ########## Start the main scenario looping here ########## do { GetStartTime.Run(); // Get Scenario start time InitScenarioStart(); DoScenario13.Run(); EndScenarioCleanup(); InitScenarioStart(); DoScenario14.Run(); EndScenarioCleanup(); InitScenarioStart(); DoScenario15.Run(); EndScenarioCleanup(); InitScenarioStart(); DoScenario16.Run(); EndScenarioCleanup(); InitScenarioStart(); DoScenario18.Run(); EndScenarioCleanup(); InitScenarioStart(); DoScenario19.Run(); EndScenarioCleanup(); InitScenarioStart(); DoScenario20.Run(); EndScenarioCleanup(); InitScenarioStart(); DoScenario21.Run(); EndScenarioCleanup(); InitScenarioStart(); DoScenario33.Run(); EndScenarioCleanup(); InitScenarioStart(); DoScenario34.Run(); EndScenarioCleanup(); InitScenarioStart(); DoScenario36.Run(); EndScenarioCleanup(); InitScenarioStart(); DoScenario37.Run(); EndScenarioCleanup(); InitScenarioStart(); DoScenario38.Run(); EndScenarioCleanup(); InitScenarioStart(); DoScenario41.Run(); EndScenarioCleanup(); InitScenarioStart(); DoScenario42.Run(); EndScenarioCleanup(); InitScenarioStart(); DoScenario43.Run(); EndScenarioCleanup(); InitScenarioStart(); DoScenario47.Run(); EndScenarioCleanup(); InitScenarioStart(); DoScenario50.Run(); EndScenarioCleanup(); GetEndTime.Run(); // Get Scenario end time // Dump stats for all scenarios to the stats file Global.CurrentScenario = 0; if (Global.DoDumpStats) { DumpStats.Run(); } Global.CurrentIteration++; // See if time to quit if (!Global.LoopingDone) { if (!Global.StopByTime) { if (Global.CurrentIteration > Global.IterationsToDo) { Global.LoopingDone = true; } } else { System.DateTime DateTimeNow = System.DateTime.Now; string TimeToStopExecution = Global.TimeToStopExecution; int CommaOffset = TimeToStopExecution.IndexOf(","); if (CommaOffset != -1) { TimeToStopExecution = Global.TimeToStopExecution.Substring(0, CommaOffset); } int TimeUp = System.DateTime.Compare(DateTimeNow, Convert.ToDateTime(TimeToStopExecution)); if (TimeUp > 0) { Global.LoopingDone = true; } } } Global.IterationsToday++; // PAL Status Monitor UpdatePALStatusMonitor.Run(); Global.LogText = "Next Iteration"; WriteToLogFile.Run(); } while (!Global.LoopingDone); Global.WavFilePath = "Register" + Global.RegisterNumber + "Finished.wav"; PlayWavFile.Run(); Global.LogText = "RUN FINISHED - OUT fnDoScenarios Iteration: " + Global.CurrentIteration; WriteToLogFile.Run(); }
public void Run() { Mouse.DefaultMoveTime = 300; Keyboard.DefaultKeyPressTime = 100; Delay.SpeedFactor = 1.0; Ranorex.Unknown element = null; RanorexRepository repo = new RanorexRepository(); fnWriteToLogFile WriteToLogFile = new fnWriteToLogFile(); fnBrowserGoHome BrowserGoHome = new fnBrowserGoHome(); fnWriteToErrorFile WriteToErrorFile = new fnWriteToErrorFile(); fnPlayWavFile PlayWavFile = new fnPlayWavFile(); SpeechSynthesizer Speech = new SpeechSynthesizer(); Global.LogFileIndentLevel++; Global.LogText = "IN fnWaitForBrowserToLoad"; WriteToLogFile.Run(); Global.POSBrowserFlush = false; Thread.Sleep(5000); int AttemptsCounter = 0; while (!repo.POSBrowserV25StorePortal.HomeF6.Enabled || !repo.StorePortal.QAPOSReCommerce.Enabled || !(repo.POSBrowserV25StorePortal.ProgressBar.Value == 100)) { Thread.Sleep(100); double aaaa = repo.POSBrowserV25StorePortal.ProgressBar.Value; // Check for Oops Game Over Report.Log(ReportLevel.Info, "WaitStatus", "Ck Oops"); if (Host.Local.TryFindSingle(repo.RecommerceTradeLink.OopsGameOverWhatYouWereAttemptingToDoInfo.AbsolutePath.ToString(), out element)) { AttemptsCounter++; GlobalOverhead.Stopwatch.Start(); Global.TempErrorString = "Browser Oops Game Over - pressing home and retrying"; if (Global.DoRegisterSoundAlerts) { Speech.Speak(Global.TempErrorString + " try number " + AttemptsCounter.ToString()); } WriteToErrorFile.Run(); Global.LogText = Global.TempErrorString; WriteToLogFile.Run(); Global.WavFilePath = "BrowserOopsGameOver.wav "; PlayWavFile.Run(); BrowserGoHome.Run(); GlobalOverhead.Stopwatch.Stop(); } // Check for browser unavailable Report.Log(ReportLevel.Info, "WaitStatus", "Ck browser unavailable"); if (Host.Local.TryFindSingle(repo.StorePortal.POSBrowsingIsCurrentlyUnavailableInfo.AbsolutePath.ToString(), out element)) { AttemptsCounter++; GlobalOverhead.Stopwatch.Start(); Global.TempErrorString = "Browser Unavailable - try go home"; if (Global.DoRegisterSoundAlerts) { Speech.Speak(Global.TempErrorString + " try number " + AttemptsCounter.ToString()); } WriteToErrorFile.Run(); Global.LogText = Global.TempErrorString; WriteToLogFile.Run(); BrowserGoHome.Run(); GlobalOverhead.Stopwatch.Stop(); } // Check for server error Report.Log(ReportLevel.Info, "WaitStatus", "Ck browser server error"); if (Host.Local.TryFindSingle(repo.RecommerceTradeLink.ServerErrorInApplicationInfo.AbsolutePath.ToString(), out element)) { AttemptsCounter++; GlobalOverhead.Stopwatch.Start(); Global.TempErrorString = "Browser Server Error In Application - try go home"; if (Global.DoRegisterSoundAlerts) { Speech.Speak(Global.TempErrorString + " try number " + AttemptsCounter.ToString()); } WriteToErrorFile.Run(); Global.LogText = Global.TempErrorString; WriteToLogFile.Run(); BrowserGoHome.Run(); GlobalOverhead.Stopwatch.Stop(); } Report.Log(ReportLevel.Info, "WaitStatus", "look for recommerce link"); if (!Host.Local.TryFindSingle(repo.StorePortal.QAPOSReCommerceInfo.AbsolutePath.ToString(), out element)) { if (AttemptsCounter > Global.MaxRetries) { Global.LogText = "Flushing wait for browser to load"; WriteToLogFile.Run(); Global.POSBrowserFlush = true; } else { } } } Global.LogText = "OUT fnWaitForBrowserToLoad"; WriteToLogFile.Run(); Global.LogFileIndentLevel--; }