Exemplo n.º 1
0
        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);
        }
Exemplo n.º 2
0
        /// <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--;
            }
        }