/*
         * Path with 2 blocks/modules, successful
         */
        public TestResult Path1Usermethod()
        {
            TestReport.BeginTestCase("Flow1_Path1");

            TestResult testResult = TestResult.Skipped;

            try {
                TestReport.BeginTestModule("Flow1_Path1_Block1");
                // --- BEGIN ARD Blockcode ---
                Report.Info("Flow1 Path Block1");
                // --- END ARD Blockcode ---
                TestReport.EndTestModule();

                TestReport.BeginTestModule("Flow1_Path1_Block2");
                // --- BEGIN ARD Blockcode ---
                Report.Info("Flow1 Path Block2");
                // --- END ARD Blockcode ---
                TestReport.EndTestModule();

                testResult = TestResult.Passed;
            }
            catch (Exception e) {
                TestReport.EndTestModule();
                testResult = RanorexCoreReflectionHelper.HandleError(e);
                TestReport.SaveLocalScreenshotBuffer();
            }
            finally {
                TestReport.BeginTestCaseTeardown();

                try
                {
                    TestReport.BeginTestModule("Flow1_Path2_Teardown");
                    // --- BEGIN ARD Blockcode ---
                    Report.Info("There goes the successful Teardown");
                    // --- END ARD Blockcode ---
                    TestReport.EndTestModule();
                }
                catch (Exception e) {
                    TestReport.EndTestModule();
                    testResult = RanorexCoreReflectionHelper.HandleError(e);
                    TestReport.SaveLocalScreenshotBuffer();
                }
                finally
                {
                    TestReport.EndTestCaseTeardown();
                    TestReport.EndTestCase();
                }
            }
            return(testResult);
        }
        /// <summary>
        /// The prepare reporting.
        /// </summary>
        /// <param name="executionObject">
        /// The execution object.
        /// </param>
        /// <param name="testSuite">
        /// The test suite.
        /// </param>
        /// <returns>
        /// The <see cref="bool"/>.
        /// </returns>
        public static bool PrepareReporting(ExecutionObject executionObject, string testSuite)
        {
            Log.Enter(LogInfo.Namespace(MethodBase.GetCurrentMethod()), MethodBase.GetCurrentMethod().Name);

            if (!Directory.Exists(executionObject.ReportFolderOverview + @"\Temp"))
            {
                Directory.CreateDirectory(executionObject.ReportFolderOverview + @"\Temp");
            }

            TestReport.Setup(ReportLevel.Debug, executionObject.ReportPathAndFileOverviewTemp, true);
            TestReport.BeginTestSuite(testSuite, executionObject.DtmStudioTestData.DeviceTypeProject.FDTDeviceTypeName);
            TestReport.BeginTestCase(testSuite, string.Empty);
            TestReport.BeginTestModule("Details");

            return(true);
        }
        /*
         * Path with 1 block/module, fails in the block/module itself
         */
        public TestResult Path1Usermethod()
        {
            TestReport.BeginTestCase("Flow2_Path1");

            TestResult testResult = TestResult.Skipped;

            try {
                TestReport.BeginTestModule("Flow2_Path1_Block1");
                // --- BEGIN ARD Blockcode ---
                Report.Info("Flow2 Path Block1");
                Validate.IsTrue(false);
                // --- END ARD Blockcode ---
                TestReport.EndTestModule();

                testResult = TestResult.Passed;
            }
            catch (Exception e) {
                TestReport.EndTestModule();
                testResult = RanorexCoreReflectionHelper.HandleError(e);
                TestReport.SaveLocalScreenshotBuffer();
            }
            finally {
                TestReport.BeginTestCaseTeardown();

                try
                {
                    TestReport.BeginTestModule("Flow2_Path1_Teardown");
                    // --- BEGIN ARD Blockcode ---
                    Report.Info("And our teardown does its job");
                    Validate.IsTrue(true);
                    // --- END ARD Blockcode ---
                    TestReport.EndTestModule();
                }
                catch (Exception e) {
                    TestReport.EndTestModule();
                    testResult = RanorexCoreReflectionHelper.HandleError(e);
                    TestReport.SaveLocalScreenshotBuffer();
                }
                finally
                {
                    TestReport.EndTestCaseTeardown();
                    TestReport.EndTestCase();
                }
            }
            return(testResult);
        }
示例#4
0
文件: Root.cs 项目: joeyrodrigue/PAL
        public void ExecuteScenarios()
        {
            var rnd = new Random();

            //Loop through the scenario list while the list still has scenarios
            while (lsScenarios.Count != 0)
            {
                var    index         = rnd.Next(0, lsScenarios.Count);
                string strScenarioId = lsScenarios[index];

                XDocument xdocSc = XDocument.Load(@"c:\PAL\Automation\Scenarios\" + strScenarioId + ".config");

                TestReport.BeginTestCase("Scenario " + strScenarioId, "");
                Report.Log(ReportLevel.Info, "Scenario", "Starting Scenario " + strScenarioId);

                //Query xml for the scenario matching the random selected scenario index
                var lv1s = from lv1 in xdocSc.Descendants("module")
                           select lv1;

                //Loop through results
                foreach (var lv1 in lv1s)
                {
                    if (Global.Proceed)
                    {
                        Global.xelModule = lv1;
                        switch (lv1.Attribute("name").Value)
                        {
                        case "login":
                            Login mLogin = new Login();
                            TestModuleRunner.Run(mLogin);
                            break;

                        case "AddItems":
                            AddItems mAddItems = new AddItems();
                            TestModuleRunner.Run(mAddItems);
                            break;

                        case "GPG":
                            GPG mGPG = new GPG();
                            TestModuleRunner.Run(mGPG);
                            break;

                        case "IncludeCustomer":
                            IncludeCustomer mIncludeCustomer = new IncludeCustomer();
                            TestModuleRunner.Run(mIncludeCustomer);
                            break;

                        case "PURBenefits":
                            PURBenefits mPURBenefits = new PURBenefits();
                            TestModuleRunner.Run(mPURBenefits);
                            break;

                        case "Checkout":
                            Checkout mCheckout = new Checkout();
                            TestModuleRunner.Run(mCheckout);
                            break;

                        case "Cash":
                            Cash mCash = new Cash();
                            TestModuleRunner.Run(mCash);
                            break;

                        default:
                            break;
                        }
                    }
                }

                lsScenarios.RemoveAt(index);
                TestReport.EndTestCase();
                Global.Proceed = true;
            }
        }
        /*
         * Path with 1 block/module, automates notepad and then fails in the teardown
         */
        public TestResult Path2Usermethod()
        {
            TestReport.BeginTestCase("Flow1_Path2");

            TestResult testResult = TestResult.Skipped;

            try {
                TestReport.BeginTestModule("Flow1_Path2_Block1");
                // --- BEGIN ARD Blockcode  ---
                Report.Info("Flow1 Path2 Block1 (only block)");
                Report.Info("This is it!");
                Delay.Milliseconds(200);
                Report.Info("This is it!");
                Delay.Milliseconds(200);

                var start = repo.Explorer.Start;
                start.MoveTo();

                // copied from NotepadTest
                Report.Log(ReportLevel.Info, "Application", "Run application 'C:\\Windows\\System32\\notepad.exe' with arguments '' in normal mode.");
                Host.Local.RunApplication("C:\\Windows\\System32\\notepad.exe", "", "C:\\Windows\\System32", false);

                Report.Log(ReportLevel.Info, "Mouse", "Mouse Left Click item 'UntitledNotepad.Text15' at 254;96.", repo.UntitledNotepad.Text15Info);
                repo.UntitledNotepad.Text15.Click("254;96");

                Report.Log(ReportLevel.Info, "Keyboard", "Key sequence 'aaa' with focus on 'UntitledNotepad.Text15'.", repo.UntitledNotepad.Text15Info);
                repo.UntitledNotepad.Text15.PressKeys("aaa");

                Report.Log(ReportLevel.Info, "Mouse", "Mouse Left Click item 'UntitledNotepad.Edit' at 21;17.", repo.UntitledNotepad.EditInfo);
                repo.UntitledNotepad.Edit.Click("21;17");

                Report.Log(ReportLevel.Info, "Mouse", "Mouse Left Click item 'Notepad.UndoCtrlPlusZ' at 35;6.", repo.Notepad.UndoCtrlPlusZInfo);
                repo.Notepad.UndoCtrlPlusZ.Click("35;6");

                Report.Log(ReportLevel.Info, "Mouse", "Mouse Left Click item 'UntitledNotepad.File' at 5;14.", repo.UntitledNotepad.FileInfo);
                repo.UntitledNotepad.File.Click("5;14");

                Report.Log(ReportLevel.Info, "Mouse", "Mouse Left Click item 'Notepad.Exit' at 34;13.", repo.Notepad.ExitInfo);
                repo.Notepad.Exit.Click("34;13");
                // --- END ARD Blockcode ---
                TestReport.EndTestModule();

                testResult = TestResult.Passed;
            }
            catch (Exception e) {
                TestReport.EndTestModule();
                testResult = RanorexCoreReflectionHelper.HandleError(e);
                TestReport.SaveLocalScreenshotBuffer();
            }
            finally {
                TestReport.BeginTestCaseTeardown();

                try
                {
                    TestReport.BeginTestModule("Flow1_Path2_Teardown");
                    // --- BEGIN ARD Blockcode ---
                    Report.Info("And our teardown blows off");
                    Validate.IsTrue(false);
                    // --- END ARD Blockcode ---
                    TestReport.EndTestModule();
                }
                catch (Exception e) {
                    TestReport.EndTestModule();
                    testResult = RanorexCoreReflectionHelper.HandleError(e);
                    TestReport.SaveLocalScreenshotBuffer();
                }
                finally
                {
                    TestReport.EndTestCaseTeardown();
                    TestReport.EndTestCase();
                }
            }
            return(testResult);
        }
示例#6
0
 /// <summary>
 /// Begins the test case.
 /// </summary>
 /// <param name="testCaseName">Name of the test case.</param>
 public static void BeginTestCase(string testCaseName)
 {
     TestReport.BeginTestCase(testCaseName);
 }
示例#7
0
        /// <summary>
        /// The prepare reporting.
        /// </summary>
        /// <param name="executionObject">
        /// The execution object.
        /// </param>
        /// <returns>
        /// The <see cref="string"/>.
        /// </returns>
        public static string PrepareReporting(ref ExecutionObject executionObject)
        {
            Log.Enter(LogInfo.Namespace(MethodBase.GetCurrentMethod()), MethodBase.GetCurrentMethod().Name);
            if (!Directory.Exists(executionObject.ReportFolderTestCases))
            {
                Directory.CreateDirectory(executionObject.ReportFolderTestCases);
            }

            var currentDateAndTime = DateTime.Now.ToString("yyyyMMdd_HHmmss");

            // currentTestCase contains the current testcase namen + date-time-stamp
            currentTestCase = currentDateAndTime + "_" + executionObject.TestCaseName;

            // filename contains the whole path
            // it´s number of characters must be less then 255-5 (5 from .data by creating the file)
            var fileName            = executionObject.ReportFolderTestCases + @"\" + currentTestCase;
            var testCasePathAndFile = fileName + executionObject.FileExtension; // originFileName;

            // check path length of all parts
            // Check path length for creating ranorex report
            // if ranorexReportLength > 92
            //   shorten name of ranorex report
            //   log info about shortening ranorexReport
            // if completePathLength > 250
            //   shorten name of ranorex report
            //   log info about shortening ranorexReport
            // if shortenig is not enought
            //   log info about ranorexReport which wont be available due path length issues
            try
            {
                string testSuiteName = executionObject.CurrentTestReportInfo.TestSuiteName;

                // Check currentTestCase length if filename is too long for ranorex setup function.
                // If filename is too long, cut of characters for valid number of characters.
                int currentTestCaseLength = currentTestCase.Length;
                if (currentTestCaseLength > ConstLenghts.MaxFileLengthByRanorex)
                {
                    Console.ForegroundColor = ConsoleColor.Cyan;
                    Console.WriteLine("TestCaseName [" + currentTestCase + "] has more than " + ConstLenghts.MaxFileLengthByRanorex + " (" + currentTestCaseLength.ToString(CultureInfo.InvariantCulture) + ") characters and has been reduced to a valid length.");
                    Console.ResetColor();

                    currentTestCase       = currentTestCase.Remove(ConstLenghts.MaxFileLengthByRanorex, currentTestCaseLength - ConstLenghts.MaxFileLengthByRanorex);
                    testCasePathAndFile   = executionObject.ReportFolderTestCases + @"\" + currentTestCase + executionObject.FileExtension;
                    currentTestCaseLength = currentTestCase.Length;
                }

                // Check reportFileName length if path is too long for file system.
                // If filename is too long and if it is possible to cut of characters from currentTestCase filename
                // cut of characters for valid number of characters.
                int reportFileNameLength = testCasePathAndFile.Length;

                if (reportFileNameLength > ConstLenghts.MaxPathLengthForTempararyPostfix)
                {
                    Console.ForegroundColor = ConsoleColor.Cyan;
                    Console.WriteLine("ReportFileName [" + testCasePathAndFile + "] has more than " + (ConstLenghts.MaxPathLengthByOperatingSystem - 1) + " (" + testCasePathAndFile.Length + ") characters.");
                    Console.ResetColor();

                    int availableCharacters = ConstLenghts.MaxPathLengthForTempararyPostfix - reportFileNameLength + currentTestCaseLength;

                    // Shorten currentTestCase name to the length of available characters
                    if (availableCharacters - DateTimeLength - executionObject.FileExtension.Length > 0)
                    {
                        currentTestCase      = currentTestCase.Remove(availableCharacters, currentTestCaseLength - availableCharacters);
                        testCasePathAndFile  = executionObject.ReportFolderTestCases + @"\" + currentTestCase + executionObject.FileExtension;
                        reportFileNameLength = testCasePathAndFile.Length;
                    }
                    else
                    {
                        Console.ForegroundColor = ConsoleColor.Cyan;
                        Console.WriteLine("ReportFileName [" + testCasePathAndFile + "] could not be trimmed. There are less characters left for a filename with a length of one character + file extension.");
                        Console.ResetColor();
                    }
                }

                if (reportFileNameLength > ConstLenghts.MaxPathLengthForTempararyPostfix)
                {
                    // Create Report Object
                    executionObject.CurrentTestCaseInfo.TestCaseName   = currentTestCase + ": The TestCaseReport [" + currentTestCase + "] is not available due to exceeded path length = " + testCasePathAndFile.Length.ToString(CultureInfo.InvariantCulture) + ".";
                    executionObject.CurrentTestCaseInfo.TestCasePath   = string.Empty;
                    executionObject.CurrentTestCaseInfo.TestCaseResult = TestResult.Failed;
                    executionObject.CurrentTestReportInfo.TestCaseInfos.Add(executionObject.CurrentTestCaseInfo);
                }
                else
                {
                    TestReport.Setup(ReportLevel.Debug, testCasePathAndFile, true);
                    TestReport.BeginTestSuite(executionObject.CurrentTestCase.DisplayName, testSuiteName);
                    TestReport.BeginTestCase(executionObject.CurrentTestCase.DisplayName);
                    TestReport.BeginTestModule("Details");

                    string backToOverview = FileNameHandler.GetRelativePathToOverview(executionObject.ReportFolderOverview, executionObject.ReportFolderTestCases);
                    backToOverview = backToOverview + @"\" + executionObject.ReportNameOverview;

                    Report.LogHtml(ReportLevel.Debug, string.Empty, @"<a href='" + backToOverview + "'>" + @"Back to Overview" + "</a>");
                }
            }
            catch (Exception exception)
            {
                Log.Enter(LogInfo.Namespace(MethodBase.GetCurrentMethod()), exception.Message);
                Console.ForegroundColor = ConsoleColor.Cyan;
                Console.WriteLine(LogInfo.Namespace(MethodBase.GetCurrentMethod()) + ": " + exception.Message);
                Console.ResetColor();
            }

            return(testCasePathAndFile);
        }