コード例 #1
0
        /// <summary>
        /// The execute.
        /// </summary>
        /// <param name="executionObject">
        /// The execution object.
        /// </param>
        public static void Execute(ExecutionObject executionObject)
        {
            Log.Enter(LogInfo.Namespace(MethodBase.GetCurrentMethod()), MethodBase.GetCurrentMethod().Name);

            try
            {
                if (executionObject.ExecutionData.Method.GetCustomAttributesData().Count > 0)
                {
                    foreach (var attributeData in executionObject.ExecutionData.Method.GetCustomAttributesData())
                    {
                        executionObject.ExecutionData.AttributeData = attributeData;

                        if (executionObject.ExecutionData.AttributeData.ConstructorArguments.Count > 0)
                        {
                            if (attributeData.ConstructorArguments[0].Value.Equals(executionObject.ExecutionData.SearchedGuid))
                            {
                                MethodHandler.Execute(executionObject);
                            }
                        }
                    }
                }
                else
                {
                    Log.Error(LogInfo.Namespace(MethodBase.GetCurrentMethod()), "No attributeData available");
                }
            }
            catch (Exception exception)
            {
                Log.Error(LogInfo.Namespace(MethodBase.GetCurrentMethod()), exception.Message);
                PCPS.TestAutomation.Common.Tools.Log.Error(LogInfo.Namespace(MethodBase.GetCurrentMethod()), exception.Message);
                throw;
            }
        }
コード例 #2
0
        /// <summary>
        /// The execute.
        /// </summary>
        /// <param name="executionObject">
        /// The execution object.
        /// </param>
        public static void Execute(ExecutionObject executionObject)
        {
            Log.Enter(LogInfo.Namespace(MethodBase.GetCurrentMethod()), MethodBase.GetCurrentMethod().Name);

            try
            {
                if (executionObject.ExecutionData.Assembly.GetTypes().Length > 0)
                {
                    foreach (var type in executionObject.ExecutionData.Assembly.GetTypes())
                    {
                        executionObject.ExecutionData.Type = type;
                        MethodInfoHandler.Execute(executionObject);
                    }
                }
                else
                {
                    Log.Error(LogInfo.Namespace(MethodBase.GetCurrentMethod()), "No types available");
                }
            }
            catch (Exception exception)
            {
                Log.Error(LogInfo.Namespace(MethodBase.GetCurrentMethod()), exception.Message);
                PCPS.TestAutomation.Common.Tools.Log.Error(LogInfo.Namespace(MethodBase.GetCurrentMethod()), exception.Message);
                throw;
            }
        }
コード例 #3
0
        /// <summary>
        /// The finish reporting.
        /// </summary>
        /// <param name="executionObject">
        /// The execution object.
        /// </param>
        /// <param name="testCaseInfo">
        /// The test Case Info.
        /// </param>
        public static void FinishReporting(ref ExecutionObject executionObject, ref TestCaseInfo testCaseInfo)
        {
            Log.Enter(LogInfo.Namespace(MethodBase.GetCurrentMethod()), MethodBase.GetCurrentMethod().Name);

            try
            {
                testCaseInfo.TestCaseName   = currentTestCase; // executionObject.TestCaseName;
                testCaseInfo.TestCasePath   = executionObject.ReportFolderTestCases;
                testCaseInfo.TestCaseResult = (TestResult)TestReport.CurrentTestModuleActivity.Status;
                executionObject.CurrentTestReportInfo.TestCaseInfos.Add(testCaseInfo);

                // Finish testcase logfile
                TestReport.EndTestModule();
                TestReport.SetCurrentTestResult(testCaseInfo.TestCaseResult);
                TestReport.EndTestCase();
                TestReport.SetCurrentTestResult(testCaseInfo.TestCaseResult);
                TestReport.EndTestCaseSetup();
                TestReport.SetCurrentTestResult(testCaseInfo.TestCaseResult);
                TestReport.SaveReport();
                TestReport.Clear();
            }
            catch (Exception exception)
            {
                Log.Enter(LogInfo.Namespace(MethodBase.GetCurrentMethod()), exception.Message);
            }
        }
コード例 #4
0
        /// <summary>
        /// The manipulate overview report layout.
        /// </summary>
        /// <param name="executionObject">
        /// The execution Object.
        /// </param>
        public static void ManipulateOverviewReportLayout(ExecutionObject executionObject)
        {
            if (File.Exists(executionObject.ReportPathAndFileOverviewTemp))
            {
                var reader     = File.OpenText(executionObject.ReportPathAndFileOverviewTemp);
                var fileString = reader.ReadToEnd();
                reader.Close();

                string totalFailedCountOld  = "var failed  = parseInt($(" + (char)34 + "#testCasesPie" + (char)34 + ").attr('totalfailedcount'));";
                string totalFailedCountNew  = "var failed  = parseInt($(" + (char)34 + "#testCasesPie" + (char)34 + ").attr('totaltestcasefailedcount'));";
                string totalSuccessCountOld = "var success = parseInt($(" + (char)34 + "#testCasesPie" + (char)34 + ").attr('totalsuccesscount'));";
                string totalSuccessCountNew = "var success = parseInt($(" + (char)34 + "#testCasesPie" + (char)34 + ").attr('totaltestcasesuccesscount'));";
                string totalIgnoredCountOld = "var ignored = parseInt($(" + (char)34 + "#testCasesPie" + (char)34 + ").attr('totalblockedcount'));";
                string totalIgnoredCountNew = "var ignored = parseInt($(" + (char)34 + "#testCasesPie" + (char)34 + ").attr('totalwarningcount'));";
                string blockedIgnoredOld    = "line1.push([ignored + 'x Blocked', ignored]);";
                string blockedIgnoredNew    = "line1.push([ignored + 'x Warning', ignored]);";

                fileString = fileString.Replace(totalFailedCountOld, totalFailedCountNew);
                fileString = fileString.Replace(totalSuccessCountOld, totalSuccessCountNew);

                fileString = fileString.Replace(totalIgnoredCountOld, totalIgnoredCountNew);
                fileString = fileString.Replace(blockedIgnoredOld, blockedIgnoredNew);

                var writer = new StreamWriter(executionObject.ReportPathAndFileOverviewTemp);
                writer.Write(fileString);
                writer.Close();
            }
        }
コード例 #5
0
        /// <summary>
        /// The create reporting.
        /// </summary>
        /// <param name="executionObject">
        /// The execution object.
        /// </param>
        public static void CreateReporting(ExecutionObject executionObject)
        {
            Log.Enter(LogInfo.Namespace(MethodBase.GetCurrentMethod()), MethodBase.GetCurrentMethod().Name);

            if (executionObject.TestReportInfos != null)
            {
                foreach (TestReportInfo testReportInfo in executionObject.TestReportInfos)
                {
                    if (testReportInfo.TestSuiteName.Equals(string.Empty))
                    {
                        foreach (TestCaseInfo testCaseInfo in testReportInfo.TestCaseInfos)
                        {
                            string relativePathToTestCase = FileNameHandler.RelativePathToTestCase(executionObject.ReportFolderOverview, testCaseInfo.TestCasePathAndName);
                            Report.LogHtml(testCaseInfo.GetReportLevel(), testCaseInfo.TestCaseResult.ToString(), @"<a href='" + relativePathToTestCase + "'>" + GetTestCaseNameWithoutTimeStamp(testCaseInfo.TestCaseName) + "</a>");
                        }
                    }
                    else
                    {
                        Report.Info("Begin of Testsuite: ", testReportInfo.TestSuiteName);
                        foreach (TestCaseInfo testCaseInfo in testReportInfo.TestCaseInfos)
                        {
                            string relativePathToTestCase = FileNameHandler.RelativePathToTestCase(executionObject.ReportFolderOverview, testCaseInfo.TestCasePathAndName);
                            Report.LogHtml(testCaseInfo.GetReportLevel(), testCaseInfo.TestCaseResult.ToString(), @"<a href='" + relativePathToTestCase + "'>" + GetTestCaseNameWithoutTimeStamp(testCaseInfo.TestCaseName) + "</a>");
                        }

                        Report.Info("End of Testsuite: ", testReportInfo.TestSuiteName);
                    }
                }
            }
        }
コード例 #6
0
        /// <summary>
        /// Initializes a new instance of the <see cref="Runner"/> class.
        /// </summary>
        /// <param name="fileName">
        /// The file name.
        /// </param>
        public Runner(string fileName)
        {
            Log.Enter(this, MethodBase.GetCurrentMethod().Name);

            dataManager          = new EhDataManager();
            this.executionObject = new ExecutionObject(fileName, dataManager.DTMstudioTestData);
        }
コード例 #7
0
        /// <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);
        }
コード例 #8
0
        /// <summary>
        /// The get test case info error count.
        /// </summary>
        /// <param name="executionObject">
        /// The execution object.
        /// </param>
        /// <returns>
        /// The <see cref="int"/>.
        /// </returns>
        public static int GetTestCaseInfoErrorCount(ExecutionObject executionObject)
        {
            int result = 0;

            foreach (TestReportInfo testSuiteInfo in executionObject.TestReportInfos)
            {
                foreach (TestCaseInfo testCaseInfo in testSuiteInfo.TestCaseInfos)
                {
                    if (testCaseInfo.TestCaseResult == TestResult.Failed)
                    {
                        result++;
                    }
                }
            }

            return(result);
        }
コード例 #9
0
        /// <summary>
        /// The execute new.
        /// </summary>
        /// <param name="executionObject">
        /// The execution object.
        /// </param>
        /// <returns>
        /// The <see cref="ExecutionObject"/>.
        /// </returns>
        public ExecutionObject Execute(ExecutionObject executionObject)
        {
            Log.Enter(this, MethodBase.GetCurrentMethod().Name);
            if (executionObject != null)
            {
                // Create a copy from origin
                var currentExecutionObject = new ExecutionObject(executionObject);

                // Get all available testobjects from testconfiguration (= control document)
                TestObjectCollection testObjectCollection = currentExecutionObject.TestConfiguration.AvailableTestObjects;

                // More than one testObjectCollection is possible. In fact there´s only one. It´s the top layer in control document.
                foreach (var testObject in testObjectCollection)
                {
                    if (testObject is TestCollection)
                    {
                        // Add new TestReportInfos without related TestSuites
                        var testReportInfo = new TestReportInfo(string.Empty);
                        currentExecutionObject.TestReportInfos.Add(testReportInfo);
                        currentExecutionObject.CurrentTestReportInfo = testReportInfo;

                        // Recursvive call
                        currentExecutionObject.CurrentTestObject         = testObject;
                        currentExecutionObject.ExecutionData.TestMethods = ((TestCollection)testObject).TestObjects;
                        currentExecutionObject = this.ReadByObject(currentExecutionObject);
                    }
                }

                return(currentExecutionObject);
            }

            Log.Error(this, "ExecutionObject is Null before execution");
            PCPS.TestAutomation.Common.Tools.Log.Error(LogInfo.Namespace(MethodBase.GetCurrentMethod()), "ExecutionObject is Null before execution");
            Console.WriteLine("ExecutionObject is Null before execution");
            return(null);
        }
コード例 #10
0
        /// <summary>
        /// The initialize execution object.
        /// </summary>
        /// <param name="executionObject">
        /// The execution object.
        /// </param>
        /// <returns>
        /// The <see cref="bool"/>.
        /// </returns>
        public static bool InitializeExecutionObject(ExecutionObject executionObject)
        {
            Log.Enter(LogInfo.Namespace(MethodBase.GetCurrentMethod()), MethodBase.GetCurrentMethod().Name);

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

            // Prüfung 1: läuft das Projekt im usprünglichen Verzeichnis.
            // => Dann werden die Projektspezifischen Daten verwendet.
            // => Unter dem Ordner Report\Output\ werden alle Verzeichnisse und Dateien abgelegt
            // Alternative:
            // => Aktuelles Ausführungsverzeichnis wird ermittelt
            // => Unter dem Ordner Report\Output\ werden alle Verzeichnisse und Dateien abgelegt

            // DONE
            // Prüfung 2: ist der Pfad für die Ausgabe absolut?
            // => Dann geschieht die komplette Ausgabe in diesem Verzeichnis.
            // => Verzeichnisse müssen vorbereitend angepasst werden.
            // Alternative:
            // => Unter dem Ordner Report\Output\ werden alle Verzeichnisse und Dateien abgelegt

            // DONE
            // Prüfung 3: hat der Pfad eine gültige Länge und lässt er noch x Zeichen übrig?
            // => Es geht normal weiter
            // Alternative:
            // Die Programausführung wird mit einem Hinweis auf die Pfadlänge abgebrochen.
            ReportHelper.ReportPath = executionObject.DtmStudioTestData.DeviceTypeTestProject.ReportOutputPath;

            if (!ReportHelper.ReportPath.Contains(":"))
            {
                if (executionObject.DtmStudioTestData.DeviceTypeTestProject.ExecutionPath != null)
                {
                    // Normierung des ReportOutputPath => Entfernen von führenden und nachfolgenden "\"
                    executionObject.DtmStudioTestData.DeviceTypeTestProject.ReportOutputPath = RemoveFromFirstAndLastPosition(executionObject.DtmStudioTestData.DeviceTypeTestProject.ReportOutputPath, @"\");

                    executionObject.ReportFolderOverview          = executionObject.DtmStudioTestData.DeviceTypeTestProject.ExecutionPath + @"\" + executionObject.DtmStudioTestData.DeviceTypeTestProject.ReportOutputPath + @"\" + currentDateAndTime;
                    executionObject.ReportFolderTestCases         = executionObject.ReportFolderOverview + @"\" + executionObject.DtmStudioTestData.DeviceTypeTestProject.Name;
                    executionObject.ReportNameOverview            = currentDateAndTime + @"_" + executionObject.DtmStudioTestData.DeviceTypeTestProject.Name + executionObject.FileExtension;
                    executionObject.ReportPathAndFileOverview     = executionObject.ReportFolderOverview + @"\" + executionObject.ReportNameOverview;
                    executionObject.ReportPathAndFileOverviewTemp = executionObject.ReportFolderOverview + @"\Temp\" + executionObject.ReportNameOverview;
                    ReportHelper.ReportPath = executionObject.ReportFolderOverview;

                    // Main Report folder consists of path to reports and current target sub folder
                    if (Directory.Exists(executionObject.ReportFolderOverview) == false)
                    {
                        Directory.CreateDirectory(executionObject.ReportFolderOverview);
                    }
                }
            }
            else
            {
                executionObject.ReportFolderOverview          = executionObject.DtmStudioTestData.DeviceTypeTestProject.ReportOutputPath + currentDateAndTime;
                executionObject.ReportFolderTestCases         = executionObject.ReportFolderOverview + @"\" + executionObject.DtmStudioTestData.DeviceTypeTestProject.Name;
                executionObject.ReportNameOverview            = currentDateAndTime + @"_" + executionObject.DtmStudioTestData.DeviceTypeTestProject.Name + executionObject.FileExtension;
                executionObject.ReportPathAndFileOverview     = executionObject.ReportFolderOverview + @"\" + executionObject.ReportNameOverview;
                executionObject.ReportPathAndFileOverviewTemp = executionObject.ReportFolderOverview + @"\Temp\" + executionObject.ReportNameOverview;
            }

            // Check for reportFileName length
            if (executionObject.ReportPathAndFileOverview.Length > ConstLenghts.MaxPathLengthByOperatingSystem)
            {
                string caption = "Error: Project path is too long.";
                string message = "Problem:\t Project path is to long. ReportFileName [" + executionObject.ReportPathAndFileOverview + "] has more than " + ConstLenghts.MaxPathLengthByOperatingSystem + " charakters (" + executionObject.ReportPathAndFileOverview.Length + "). \n\nSolution: \tPlease copy ControlDocument from this project into a new project with a shorter project path.\n\nTest will be aborted!";
                Console.ForegroundColor = ConsoleColor.Magenta;
                Console.Write(message);
                Console.ResetColor();
                System.Windows.Forms.MessageBox.Show(message, caption);

                return(false);
            }

            return(true);
        }
コード例 #11
0
        /// <summary>
        /// Starts the execution of the current test script
        /// </summary>
        /// <returns>
        /// The <see cref="int"/>.
        /// </returns>
        public int StartExecution()
        {
            int result;
            var duration = new Stopwatch();

            duration.Start();

            Log.Enter(this, MethodBase.GetCurrentMethod().Name);
            dataManager.LoadDataForExecution(Environment.CurrentDirectory);

            dataManager.DTMstudioTestData.ReportData.FirmwareInformation.Clone(InfrastructureHandler.GetFimwareInformation(dataManager.DTMstudioTestData.DeviceTypeTestProject.FirmwareInformationAssembly));

            // Configurationsdaten speichern
            dataManager.SaveDeviceTypeProjectData();

            var initialization = false;

            try
            {
                this.executionObject.DtmStudioTestData = dataManager.DTMstudioTestData;
                initialization = TestReportHandler.InitializeExecutionObject(this.executionObject);
                if (initialization)
                {
                    this.executionObject = (new ControlDocumentHandler()).Execute(this.executionObject);
                }
            }
            catch (ImageNotFoundException e)
            {
                Log.Error(this, e.Message);
                this.executionObject.LatestSummaryResult = TestResult.Failed;
                result = -1;
                return(result);
            }
            catch (RanorexException e)
            {
                Log.Error(this, e.Message);
                this.executionObject.LatestSummaryResult = TestResult.Failed;
                result = -1;
                return(result);
            }
            catch (ThreadAbortException e)
            {
                Log.Error(this, e.Message);
                this.executionObject.LatestSummaryResult = TestResult.Failed;
                Thread.ResetAbort();
                result = -1;
                return(result);
            }
            catch (PathTooLongException e)
            {
                Log.Error(this, e.Message);
                System.Windows.Forms.MessageBox.Show(e.Message);
                this.executionObject.LatestSummaryResult = TestResult.Failed;
                result = -1;
                return(result);
            }
            catch (Exception e)
            {
                Log.Error(this, e.Message);
                this.executionObject.LatestSummaryResult = TestResult.Failed;
                result = -1;
                return(result);
            }

            duration.Stop();
            this.executionObject.Duration = duration.Elapsed;

            if (initialization)
            {
                // Get Result Data For Report Data
                dataManager.DTMstudioTestData.ReportData.TotalFailedCount  = TestReportHandler.GetTestCaseInfoErrorCount(this.executionObject);
                dataManager.DTMstudioTestData.ReportData.TotalSuccessCount = TestReportHandler.GetTestCaseInfoSuccessCount(this.executionObject);

                // Write Result Into Report Data
                if (dataManager.DTMstudioTestData.ReportData.TotalFailedCount > 0)
                {
                    this.executionObject.LatestSummaryResult = TestResult.Failed;
                    dataManager.DTMstudioTestData.ReportData.ResultOfTest = TestResult.Failed.ToString();
                }

                if (TestReportHandler.PrepareReporting(this.executionObject, dataManager.DTMstudioTestData.DeviceTypeProject.FDTDeviceTypeName))
                {
                    TestReportHandler.CreateReporting(this.executionObject);
                    TestReportHandler.FinishReporting(this.executionObject.LatestSummaryResult);

                    if (File.Exists(this.executionObject.ReportPathAndFileOverviewTemp))
                    {
                        InfrastructureHandler.InsertReportData(this.executionObject.ReportPathAndFileOverviewTemp, dataManager.DTMstudioTestData);
                        InfrastructureHandler.InsertDuration(this.executionObject.ReportPathAndFileOverviewTemp, this.executionObject.Duration);
                        InfrastructureHandler.ReplaceReportStyleSheet(this.executionObject.ReportPathAndFileOverviewTemp, "EHReportOverview");
                        InfrastructureHandler.CopyCustomizedReportDefaultStyle(Path.Combine(this.executionObject.DtmStudioTestData.DeviceTypeTestProject.ExecutionPath, "Report"), this.executionObject.ReportFolderOverview + @"\Temp", "EHReportOverview");
                        InfrastructureHandler.DeleteRanorexStyle(this.executionObject.ReportFolderOverview + @"\Temp");
                        InfrastructureHandler.ManipulateOverviewReportLayout(this.executionObject);
                        InfrastructureHandler.InsertHTMLCodeToReport(Path.Combine(this.executionObject.ReportPathAndFileOverviewTemp, "EHReportOverview.xsl"), dataManager.DTMstudioTestData.DeviceTypeProject.DeviceFunctions, dataManager.DTMstudioTestData.ReportData.FirmwareInformation.AdditionalInformation);
                    }

                    InfrastructureHandler.CopyReportAndDeleteTempFolder(this.executionObject.ReportFolderOverview + @"\Temp");
                    InfrastructureHandler.ExportTestResult(this.executionObject.ReportFolderOverview, this.executionObject.ReportPathAndFileOverview, dataManager.DTMstudioTestData);
                }
                else
                {
                    System.Windows.Forms.MessageBox.Show("Error: Test project path [" + this.executionObject.ReportPathAndFileOverview + "] is too long, [" + this.executionObject.ReportPathAndFileOverview.Length + "] characters.");
                }

                this.OpenExplorer(this.executionObject.ReportFolderOverview);

                // return test result as integer
                if (this.executionObject.LatestSummaryResult.Equals(TestResult.Passed))
                {
                    result = 0;
                }
                else
                {
                    result = -1;
                }

                return(result);
            }

            return(-1);
        }
コード例 #12
0
        /// <summary>
        /// Executes the invoke for a method depending it´s number of parameters
        /// </summary>
        /// <param name="executionObject">
        /// The execution object.
        /// </param>
        public static void Execute(ExecutionObject executionObject)
        {
            Log.Enter(LogInfo.Namespace(MethodBase.GetCurrentMethod()), MethodBase.GetCurrentMethod().Name);

            try
            {
                if (executionObject.ExecutionData.Method.GetParameters().Length > 0)
                {
                    if (executionObject.ExecutionData.Parameters.Count == executionObject.ExecutionData.Method.GetParameters().Length)
                    {
                        var parameterObjects = new object[executionObject.ExecutionData.Parameters.Count];
                        parameterObjects.Initialize();
                        for (var index = 0; index < executionObject.ExecutionData.Parameters.Count; index++)
                        {
                            var parameterType = executionObject.ExecutionData.Parameters[index].ParameterType;

                            switch (parameterType)
                            {
                            case "System.Int32":
                            {
                                Log.Info(LogInfo.Namespace(MethodBase.GetCurrentMethod()), "Return: System.Int32");
                                parameterObjects[index] = int.Parse(executionObject.ExecutionData.Parameters[index].ParameterValue);
                                break;
                            }

                            case "System.Single":
                            {
                                Log.Info(LogInfo.Namespace(MethodBase.GetCurrentMethod()), "Return: System.Single");
                                parameterObjects[index] = float.Parse(executionObject.ExecutionData.Parameters[index].ParameterValue);
                                break;
                            }

                            case "System.String":
                            {
                                Log.Info(LogInfo.Namespace(MethodBase.GetCurrentMethod()), "Return: System.String");
                                parameterObjects[index] = executionObject.ExecutionData.Parameters[index].ParameterValue;
                                break;
                            }

                            case "System.Boolean":
                            {
                                Log.Info(LogInfo.Namespace(MethodBase.GetCurrentMethod()), "Return: System.Boolean");
                                parameterObjects[index] = bool.Parse(executionObject.ExecutionData.Parameters[index].ParameterValue);
                                break;
                            }

                            default:
                                Log.Error(LogInfo.Namespace(MethodBase.GetCurrentMethod()), "EH.DTMstudioTest.TestScriptEngine.Execution.MethodHandler: Unknown type " + parameterType + " for cast.");
                                break;
                            }
                        }

                        executionObject.ExecutionData.Method.Invoke(null, parameterObjects);

                        // Cleanup
                        executionObject.ExecutionData.Parameter = null;
                    }
                    else
                    {
                        PCPS.TestAutomation.Common.Tools.Log.Failure(LogInfo.Namespace(MethodBase.GetCurrentMethod()), string.Format("Number of parameters from control document and expected number of parameters are not equal. Please contact developer. TestCase: [{0}]", executionObject.TestCaseName));
                    }
                }
                else
                {
                    executionObject.ExecutionData.Method.Invoke(null, null);
                }
            }
            catch (Exception exception)
            {
                Log.Error(LogInfo.Namespace(MethodBase.GetCurrentMethod()), exception.Message);
                PCPS.TestAutomation.Common.Tools.Log.Error(LogInfo.Namespace(MethodBase.GetCurrentMethod()), exception.Message);
                throw;
            }
        }
コード例 #13
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);
        }
コード例 #14
0
        /// <summary>
        /// Recursive method to read by object.
        /// </summary>
        /// <param name="executionObject">
        /// The execution object.
        /// </param>
        /// <returns>
        /// The <see cref="ExecutionObject"/>.
        /// </returns>
        private ExecutionObject ReadByObject(ExecutionObject executionObject)
        {
            Log.Enter(this, MethodBase.GetCurrentMethod().Name);
            if (executionObject != null)
            {
                var currentExecutionObject = new ExecutionObject(executionObject);

                foreach (var testObject in currentExecutionObject.ExecutionData.TestMethods)
                {
                    if (testObject.GetType() == typeof(TestSuite))
                    {
                        // Add new TestReportInfos with related TestSuiteName
                        var testReportInfo = new TestReportInfo(testObject.DisplayName);
                        currentExecutionObject.TestReportInfos.Add(testReportInfo);
                        currentExecutionObject.CurrentTestReportInfo = testReportInfo;

                        // Recursvive call
                        currentExecutionObject.CurrentTestObject         = testObject;
                        currentExecutionObject.ExecutionData.TestMethods = ((TestCollection)testObject).TestObjects;
                        currentExecutionObject = this.ReadByObject(currentExecutionObject);
                    }
                    else if (testObject.GetType() == typeof(TestFolder) && testObject.Parent.GetType() == typeof(TestSuite))
                    {
                        // Recursvive call
                        currentExecutionObject.CurrentTestObject         = testObject;
                        currentExecutionObject.ExecutionData.TestMethods = ((TestCollection)testObject).TestObjects;
                        currentExecutionObject = this.ReadByObject(currentExecutionObject);
                    }
                    else if (testObject.GetType() == typeof(TestFolder) && testObject.Parent.GetType() != typeof(TestSuite) && testObject.Parent != null)
                    {
                        string targetFolder = currentExecutionObject.ReportFolderTestCases;

                        if (!Directory.Exists(targetFolder))
                        {
                            Directory.CreateDirectory(targetFolder);
                        }

                        // Add new TestReportInfos without related TestSuites
                        var testReportInfo = new TestReportInfo(string.Empty);
                        currentExecutionObject.TestReportInfos.Add(testReportInfo);
                        currentExecutionObject.CurrentTestReportInfo = testReportInfo;

                        // Recursvive call
                        currentExecutionObject.CurrentTestObject         = testObject;
                        currentExecutionObject.ExecutionData.TestMethods = ((TestCollection)testObject).TestObjects;
                        currentExecutionObject = this.ReadByObject(currentExecutionObject);
                    }
                    else if (testObject.GetType() == typeof(TestCase))
                    {
                        this.reportFileName = string.Empty;
                        try
                        {
                            currentExecutionObject.TestCaseName    = testObject.DisplayName;
                            currentExecutionObject.CurrentTestCase = (TestCase)testObject;

                            /* Manipulation der Ausgabe bevor der Bericht abgeschlossen ist, weil die Ausführung
                             * abgebrochen werden können soll, ohne dass dabei die neue Formatierung "vergessen" wird.
                             * Neue Styles ersetzen die Ranorex Styles */
                            this.reportFileName = TestCaseReportHandler.PrepareReporting(ref currentExecutionObject);
                            InfrastructureHandler.ManipulateDetailReportLayout(this.reportFileName);
                            InfrastructureHandler.ReplaceReportStyleSheet(this.reportFileName, "EHReportDetails");
                            string       source   = Path.Combine(currentExecutionObject.DtmStudioTestData.DeviceTypeTestProject.ExecutionPath, "Report");
                            string       target   = currentExecutionObject.ReportFolderTestCases;
                            const string FileName = "EHReportDetails";
                            InfrastructureHandler.CopyCustomizedReportDefaultStyle(source, target, FileName);
                            InfrastructureHandler.DeleteRanorexStyle(currentExecutionObject.ReportFolderTestCases);
                            InfrastructureHandler.InsertHTMLCodeToReport(Path.Combine(currentExecutionObject.ReportFolderTestCases, "EHReportDetails.xsl"), currentExecutionObject.DtmStudioTestData.DeviceTypeProject.DeviceFunctions, currentExecutionObject.DtmStudioTestData.ReportData.FirmwareInformation.AdditionalInformation);

                            // Ende des Kommentars
                            if (testObject.IsActive)
                            {
                                Log.Info(this, "Execute active Testobject -> TestCase");
                                TestObjectHandler.Execute(currentExecutionObject, testObject.Guid);
                            }
                            else
                            {
                                Log.Info(this, "Log inactive Testobject -> TestCase");
                                TestReport.SetCurrentTestResult(TestResult.Skipped);
                            }
                        }
                        catch (Exception exception)
                        {
                            Log.ErrorEx(this, exception, "A Critical Error Occured");
                            Console.WriteLine("A Critical Error Occured: " + exception.Message);
                            TestReport.SetCurrentTestResult(TestResult.Failed);
                        }
                        finally
                        {
                            var testCaseInfo = new TestCaseInfo();
                            TestCaseReportHandler.FinishReporting(ref currentExecutionObject, ref testCaseInfo);
                            currentExecutionObject.DtmStudioTestData.ReportData.ResultOfTest = testCaseInfo.TestCaseResult.ToString();

                            // Nachbearbeitung notwendig, da Ranorex mit jedem Schritt die Styledaten neu hineinkopiert
                            InfrastructureHandler.InsertReportData(testCaseInfo.TestCasePathAndName, currentExecutionObject.DtmStudioTestData);
                            InfrastructureHandler.ManipulateDetailReportLayout(this.reportFileName);
                            InfrastructureHandler.ReplaceReportStyleSheet(this.reportFileName, "EHReportDetails");
                            InfrastructureHandler.DeleteRanorexStyle(currentExecutionObject.ReportFolderTestCases);
                            InfrastructureHandler.InsertHTMLCodeToReport(Path.Combine(currentExecutionObject.ReportFolderTestCases, "EHReportDetails.xsl"), currentExecutionObject.DtmStudioTestData.DeviceTypeProject.DeviceFunctions, currentExecutionObject.DtmStudioTestData.ReportData.FirmwareInformation.AdditionalInformation);

                            // Ende des Kommentars

                            // Datenbank Aufruf
                            InfrastructureHandler.ExportTestResult(testCaseInfo.TestCasePathAndName, currentExecutionObject.TestCaseName, currentExecutionObject.DtmStudioTestData);
                        }
                    }
                    else
                    {
                        Log.Info(this, "Unhandled Type: " + typeof(TestObject));
                        Console.WriteLine("Unhandled Type:" + typeof(TestObject));
                    }
                }

                return(currentExecutionObject);
            }

            Log.Error(this, "ExecutionObject is Null before execution");
            Console.WriteLine("ExecutionObject is Null before execution");
            return(null);
        }
コード例 #15
0
        /// <summary>
        /// The execute.
        /// </summary>
        /// <param name="executionObject">
        /// The execution object.
        /// </param>
        /// <param name="guid">
        /// The guid.
        /// </param>
        public static void Execute(ExecutionObject executionObject, string guid)
        {
            Log.Enter(LogInfo.Namespace(MethodBase.GetCurrentMethod()), MethodBase.GetCurrentMethod().Name);

            try
            {
                TestObject testObject = executionObject.TestConfiguration.GetTestObject(executionObject.TestConfiguration.AvailableTestObjects, guid);

                if (testObject != null)
                {
                    executionObject.ExecutionData.Parameters = executionObject.TestConfiguration.GetTestObjectParameters(testObject);
                    executionObject.CurrentTestCase          = testObject as TestCase;

                    if (executionObject.CurrentTestCase != null)
                    {
                        if (executionObject.ExecutionData.ParentGuid == null)
                        {
                            executionObject.ExecutionData.ParentGuid          = executionObject.CurrentTestCase.Parent.Guid;
                            executionObject.ExecutionData.TestSuiteBaseFolder = executionObject.ReportFolderOverview;
                        }

                        if (!string.Equals(executionObject.ExecutionData.ParentGuid, executionObject.CurrentTestCase.Parent.Guid))
                        {
                            executionObject.ExecutionData.ParentGuid          = executionObject.CurrentTestCase.Parent.Guid;
                            executionObject.ExecutionData.TestSuiteBaseFolder = executionObject.ReportFolderOverview;
                        }

                        executionObject.ExecutionData.AssemblyName = executionObject.CurrentTestCase.AssemblyName;
                        executionObject.ExecutionData.SearchedGuid = executionObject.CurrentTestCase.AssemblyMethodRefId;

                        // ToDo: Der Pfad muss auf etwas Konfigurierbares angepasst werden
                        // Wird die TestLibrary verwendet, muss auf das Installationsverzeichnis referenziert werden
                        // Wird die UserDefined verwendet, muss auf das entsprechende Verzeichnis referenziert werden

                        // try path to installed testframework
                        string pathToAssembly = ConfiguratorDialog.SelectedConfiguration.TestFramework.PathToAssemblies + @"\" + executionObject.ExecutionData.AssemblyName;
                        if (!File.Exists(pathToAssembly))
                        {
                            // try path to userdefined assembly within running project
                            pathToAssembly = Directory.GetCurrentDirectory() + @"\" + executionObject.ExecutionData.AssemblyName;
                            if (!File.Exists(pathToAssembly))
                            {
                                Exception exception = new Exception("Assembly " + executionObject.ExecutionData.AssemblyName + "not found.");
                                Log.Error(LogInfo.Namespace(MethodBase.GetCurrentMethod()), exception.Message);
                                throw exception;
                            }
                        }

                        executionObject.ExecutionData.Assembly = Assembly.LoadFrom(pathToAssembly);

                        if (executionObject.ExecutionData.Assembly != null)
                        {
                            TypeHandler.Execute(executionObject);
                        }
                    }
                }
            }
            catch (Exception exception)
            {
                Log.Error(LogInfo.Namespace(MethodBase.GetCurrentMethod()), exception.Message);
                PCPS.TestAutomation.Common.Tools.Log.Error(LogInfo.Namespace(MethodBase.GetCurrentMethod()), exception.Message);
                throw;
            }
        }