Exemple #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.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;
            }
        }
Exemple #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.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;
            }
        }
        /// <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);
        }
Exemple #4
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);
        }
Exemple #6
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;
            }
        }