예제 #1
0
        public void Run(TestContainer container)
        {
            foreach (var cmd in this.Commands)
            {
                try
                {
                    cmd.ApplyParameters(this._parameters);
                    cmd.ApplyParameters(container.GetGlobalParameters());
                    cmd.Run(container);


                    if (String.IsNullOrEmpty(cmd.Output.Key) == false)
                    {
                        //If command had output, add or update value to Test Case parameters for next command use
                        if (this._parameters.ContainsKey(cmd.Output.Key))
                        {
                            this._parameters[cmd.Output.Key] = cmd.Output.Value;
                        }
                    }
                    ConsoleReportPrint.CaseCommandPrint(cmd.Id, cmd.Description, cmd.SkipTest, cmd.PassTest);
                    //modify by zhuqianqian log4net start
                    //Logger.Write(@"\t Command:" + cmd.Id + "=>" + cmd.Description.PadRight(42, '.') + (cmd.PassTest ? "Pass" : "Fail"), "Info");
                    Logging.SaveLog(@"\t Command:" + cmd.Id + "=>" + cmd.Description.PadRight(42, '.') + (cmd.SkipTest ? "Skip" : (cmd.PassTest ? "Pass" : "Fail")), ELogType.Info);
                    //modify by zhuqianqian log4net end
                }
                catch (Exception ex)
                {
                    Logging.SaveLog(ex, ELogType.Error);
                    Console.WriteLine("\t Command:" + cmd.Id + "=>" + cmd.Description + " ERROR Occure, Interrupt this test case");
                    throw (new Exception(ex.Message));
                }
            }

            //Set test case pass or fail
            if (this.Commands.Where(c => c.PassTest.Equals(false)).Count() == 0)
            {
                this.PassTest = true;
            }
        }
예제 #2
0
 public void StartTest()
 {
     //*modify for OpenBrowserInTest
     if (_browserExectionSetting.Count > 0)
     {
         foreach (var browserSetting in _browserExectionSetting)
         {
             if (this._openBrowserInTest)
             {
                 //*modify for OpenBrowserInTest
                 this.SetBrowserDriver(browserSetting);
             }
             foreach (TestCase tCase in this._testCases)
             {
                 try
                 {
                     //modify by zhuqianqian log4net start
                     //Logger.Write(@"Run:" + tCase.Id + ":" + tCase.Description, "Info");
                     Logging.SaveLog(@"Run:" + tCase.Id + ":" + tCase.Description, ELogType.Info);
                     //modify by zhuqianqian log4net end
                     ConsoleReportPrint.TestCaseStartPrint(tCase.Id, tCase.Description);
                     tCase.Run(this);
                     //modify by zhuqianqian log4net start
                     //Logger.Write("Test Result:" + tCase.Id.PadRight(54, '.') + (tCase.PassTest ? "Pass" : "Fail"), "Info");
                     Logging.SaveLog("Test Result:" + tCase.Id.PadRight(54, '.') + (tCase.PassTest ? "Pass" : "Fail"), ELogType.Info);
                     //modify by zhuqianqian log4net end
                     ConsoleReportPrint.TestCaseCompletePrint(tCase.Id, tCase.PassTest);
                 }
                 catch (Exception ex)
                 {
                     /// Log without throw exception
                     //Logger.Write(@"ERROR Occure, Interrupt this test case", "Info");
                     //Logger.Write("Test Case:" + tCase.Id + " Exception:" + ex.Message, "Exception");
                     Logging.SaveLog(@"ERROR Occure, Interrupt this test case", ELogType.Error);
                     Logging.SaveLog("Test Case:" + tCase.Id + " Exception:" + ex.Message, ELogType.Error);
                     Console.WriteLine("Exception:" + tCase.Id + " Message:" + ex.Message);
                 }
             }
             this.PrintTestResult();
             if (this.Driver != null && this._openBrowserInTest && _closeBrowserAfterTestComplete)
             {
                 //*modify for closeBrowserAfterTestComplete
                 this.Driver.Close();
             }
         }
     }
     else if (!this._openBrowserInTest)
     {
         foreach (TestCase tCase in this._testCases)
         {
             try
             {
                 Logging.SaveLog(@"Run:" + tCase.Id + ":" + tCase.Description, ELogType.Info);
                 ConsoleReportPrint.TestCaseStartPrint(tCase.Id, tCase.Description);
                 tCase.Run(this);
                 Logging.SaveLog("Test Result:" + tCase.Id.PadRight(54, '.') + (tCase.PassTest ? "Pass" : "Fail"), ELogType.Info);
                 ConsoleReportPrint.TestCaseCompletePrint(tCase.Id, tCase.PassTest);
             }
             catch (Exception ex)
             {
                 Logging.SaveLog(@"ERROR Occure, Interrupt this test case", ELogType.Error);
                 Logging.SaveLog("Test Case:" + tCase.Id + " Exception:" + ex.Message, ELogType.Error);
                 Console.WriteLine("Exception:" + tCase.Id + " Message:" + ex.Message);
             }
         }
         this.PrintTestResult();
     }
 }