Пример #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 relative path to test case.
        /// </summary>
        /// <param name="basePath">
        /// The base path.
        /// </param>
        /// <param name="fullPath">
        /// The full path.
        /// </param>
        /// <returns>
        /// The <see cref="string"/>.
        /// </returns>
        public static string RelativePathToTestCase(string basePath, string fullPath)
        {
            Log.Enter(LogInfo.Namespace(MethodBase.GetCurrentMethod()), MethodBase.GetCurrentMethod().Name);
            string buffer = fullPath.Replace(basePath, string.Empty);

            return(buffer.Remove(0, 1));
        }
        /// <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);
                    }
                }
            }
        }
Пример #5
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);
            }
        }
        /// <summary>
        /// The finish execution.
        /// </summary>
        /// <param name="testResult">
        /// The test Result.
        /// </param>
        public static void FinishReporting(TestResult testResult)
        {
            Log.Enter(LogInfo.Namespace(MethodBase.GetCurrentMethod()), MethodBase.GetCurrentMethod().Name);

            // Finish testcase logfile
            TestReport.EndTestModule();
            TestReport.SetCurrentTestResult(testResult);
            TestReport.EndTestCase();
            TestReport.SetCurrentTestResult(testResult);
            TestReport.EndTestCaseSetup();
            TestReport.SetCurrentTestResult(testResult);
            TestReport.SaveReport();
            TestReport.Clear();
        }
        /// <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 relative path to overview.
        /// </summary>
        /// <param name="baseFolder">
        /// The base folder.
        /// </param>
        /// <param name="currentFolder">
        /// The current folder.
        /// </param>
        /// <returns>
        /// The <see cref="string"/>.
        /// </returns>
        public static string GetRelativePathToOverview(string baseFolder, string currentFolder)
        {
            Log.Enter(LogInfo.Namespace(MethodBase.GetCurrentMethod()), MethodBase.GetCurrentMethod().Name);
            string buffer = currentFolder.Replace(baseFolder, string.Empty);

            string[] parts = buffer.Split(Convert.ToChar("\\"));
            buffer = string.Empty;
            foreach (var part in parts)
            {
                if (part != string.Empty)
                {
                    string value = part;
                    value  = value.Replace(value, "\\..");
                    buffer = buffer + value;
                }
            }

            buffer = buffer.Remove(0, 1);
            return(buffer);
        }
        /// <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);
        }
 /// <summary>
 /// The get test case name without time stamp.
 /// </summary>
 /// <param name="testCaseName">
 /// The test case name.
 /// </param>
 /// <returns>
 /// The <see cref="string"/>.
 /// </returns>
 private static string GetTestCaseNameWithoutTimeStamp(string testCaseName)
 {
     Log.Enter(LogInfo.Namespace(MethodBase.GetCurrentMethod()), MethodBase.GetCurrentMethod().Name);
     return(testCaseName.Remove(0, 16));
 }
        /// <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);
        }
Пример #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);
        }
        /// <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;
            }
        }