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