HpToolsLauncher.Helper.GetTestStateFromReport C# (CSharp) Method

GetTestStateFromReport() public static method

public static GetTestStateFromReport ( TestRunResults runDesc ) : TestState
runDesc TestRunResults
return TestState
        public static TestState GetTestStateFromReport(TestRunResults runDesc)
        {
            try
            {
                if (!Directory.Exists(runDesc.ReportLocation))
                {
                    runDesc.ErrorDesc = string.Format(Resources.DirectoryNotExistError, runDesc.ReportLocation);

                    runDesc.TestState = TestState.Error;
                    return runDesc.TestState;
                }
                //if there is Result.xml -> UFT
                //if there is sla.xml file -> LR

                string[] resultFiles = Directory.GetFiles(runDesc.ReportLocation, "Results.xml",
                    SearchOption.TopDirectoryOnly);
                if (resultFiles.Length == 0)
                    resultFiles = Directory.GetFiles(runDesc.ReportLocation, "run_results.xml",
                        SearchOption.TopDirectoryOnly);
                //resultFiles = Directory.GetFiles(Path.Combine(runDesc.ReportLocation, "Report"), "Results.xml", SearchOption.TopDirectoryOnly);

                if (resultFiles != null && resultFiles.Length > 0)
                    return GetTestStateFromUFTReport(runDesc, resultFiles);

                resultFiles = Directory.GetFiles(runDesc.ReportLocation, "SLA.xml", SearchOption.AllDirectories);

                if (resultFiles != null && resultFiles.Length > 0)
                {
                    return GetTestStateFromLRReport(runDesc, resultFiles);
                }

                //no LR or UFT => error
                runDesc.ErrorDesc = string.Format("no results file found for " + runDesc.TestName);
                runDesc.TestState = TestState.Error;
                return runDesc.TestState;
            }
            catch (Exception e)
            {
                return TestState.Unknown;
            }
        }

Usage Example

        private void AnalyzeRunResult(TestRunResults runResult)
        {
            //if fail was terminated before this step, continue
            if (runResult.TestState != TestState.Failed)
            {
                if (runResult.TestState != TestState.Error)
                {
                    Helper.GetTestStateFromReport(runResult);
                }
                else
                {
                    if (string.IsNullOrEmpty(runResult.ErrorDesc))
                    {
                        if (RunCancelled())
                        {
                            runResult.ErrorDesc = HpToolsLauncher.Properties.Resources.ExceptionUserCancelled;
                        }
                        else
                        {
                            runResult.ErrorDesc = HpToolsLauncher.Properties.Resources.ExceptionExternalProcess;
                        }
                    }
                    runResult.ReportLocation = null;
                    runResult.TestState      = TestState.Error;
                }
            }

            if (runResult.TestState == TestState.Passed && runResult.HasWarnings)
            {
                runResult.TestState = TestState.Warning;
                ConsoleWriter.WriteLine(Resources.FsRunnerTestDoneWarnings);
            }
            else
            {
                ConsoleWriter.WriteLine(string.Format(Resources.FsRunnerTestDone, runResult.TestState));
            }

            ConsoleWriter.WriteLine(DateTime.Now.ToString(Launcher.DateFormat) + " Test complete: " + runResult.TestPath + "\n-------------------------------------------------------------------------------------------------------");

            UpdateCounters(runResult.TestState);
        }
All Usage Examples Of HpToolsLauncher.Helper::GetTestStateFromReport