Esempio n. 1
0
        //public static void ImportResultsFromXML(SearchCmdletBase cmdlet, string path)
        public static void ImportResultsFromXML(ImportExportCmdletBase cmdlet, string path)
        {
            string lastTestSuiteName = string.Empty;
            string lastTestScenarioName = string.Empty;
            string lastTestResultName = string.Empty;
            string lastTestResultDetailName = string.Empty;

            try {

                if (!System.IO.File.Exists(cmdlet.Path)) {

                    cmdlet.WriteError(
                        cmdlet,
                        "There is no such file '" +
                        cmdlet.Path +
                        "'.",
                        "NoSuchFile",
                        ErrorCategory.InvalidArgument,
                        true);
                }

                TestSuite currentTestSuite = TMX.TestData.CurrentTestSuite;
                TestScenario currentTestScenario = TMX.TestData.CurrentTestScenario;
                ITestResult currentTestResult = TMX.TestData.CurrentTestResult;

                TMX.TestData.CurrentTestSuite = null;
                TMX.TestData.CurrentTestScenario = null;
                TMX.TestData.CurrentTestResult = null;

                XDocument doc = XDocument.Load(cmdlet.Path);
                XNamespace df = doc.Root.Name.Namespace;
                var suites = from suite in doc.Descendants("suite")
                    where suite.Attribute("name").Value != "autogenerated"
                    select suite;

                foreach (var singleSuite in suites) {

                    cmdlet.WriteVerbose(cmdlet, "importing suite '" + singleSuite.Attribute("name").Value + "'");
                    lastTestSuiteName = singleSuite.Attribute("name").Value;

                    string suiteDescription = string.Empty;
                    try {
                        suiteDescription = singleSuite.Attribute("description").Value;
                    }
                    catch {}

                    TestSuite testSuite =
                        TMX.TestData.GetTestSuite(
                            singleSuite.Attribute("name").Value,
                            singleSuite.Attribute("id").Value,
                            singleSuite.Attribute("platformId").Value);
                    TMX.TestData.CurrentTestSuite = testSuite;

                    if (null == testSuite) {
                        TMX.TestData.AddTestSuite(
                            singleSuite.Attribute("name").Value,
                            singleSuite.Attribute("id").Value,
                            singleSuite.Attribute("platformId").Value,
                            suiteDescription,
                            null,
                            null);
                    }

                    //TMX.TestData.CurrentTestSuite.SetNow = singleSuite
            //                    try {
            //                        TMX.TestData.CurrentTestSuite.PlatformId =
            //                            singleSuite.Attribute("platformId").Value;
            //                    }
            //                    catch {}

                    var scenarios = from scenario in singleSuite.Descendants("scenario")
                        where scenario.Attribute("name").Value != "autogenerated"
                        select scenario;

                    foreach (var singleScenario in scenarios) {

                        cmdlet.WriteVerbose(cmdlet, "importing scenario '" + singleScenario.Attribute("name").Value + "'");
                        lastTestScenarioName = singleScenario.Attribute("name").Value;

                        string scenarioDescription = string.Empty;
                        try {
                            scenarioDescription = singleScenario.Attribute("description").Value;
                        }
                        catch {}

                        TestScenario testScenario =
                            TMX.TestData.GetTestScenario(
                                TMX.TestData.CurrentTestSuite,
                                singleScenario.Attribute("name").Value,
                                singleScenario.Attribute("id").Value,
                                TMX.TestData.CurrentTestSuite.Name,
                                TMX.TestData.CurrentTestSuite.Id,
                                TMX.TestData.CurrentTestSuite.PlatformId);
                        TMX.TestData.CurrentTestScenario = testScenario;

                        if (null == testScenario) {
                            TMX.TestData.AddTestScenario(
                                TMX.TestData.CurrentTestSuite,
                                singleScenario.Attribute("name").Value,
                                singleScenario.Attribute("id").Value,
                                scenarioDescription,
                                string.Empty,
                                string.Empty,
                                singleScenario.Attribute("platformId").Value,
                                null,
                                null);
                        }

            //                        try {
            //                            TMX.TestData.CurrentTestScenario.PlatformId =
            //                                singleScenario.Attribute("platformId").Value;
            //                        }
            //                        catch {}

                        var testResults = from testResult in singleScenario.Descendants("testResult")
                            //where testResult.Attribute("name").Value != "autoclosed"
                            select testResult;

                        foreach (var singleTestResult in testResults) {

                            cmdlet.WriteVerbose(cmdlet, "importing test result '" + singleTestResult.Attribute("name").Value + "', id = '" + singleTestResult.Attribute("id").Value + "'");
                            lastTestResultName = singleTestResult.Attribute("name").Value;

                            bool passedValue = false;
                            bool knownIssueValue = false;
                            try {
                                if ("PASSED" == singleTestResult.Attribute("status").Value) {
                                    passedValue = true;
                                }
                                if ("KNOWN ISSUE" == singleTestResult.Attribute("status").Value) {
                                    knownIssueValue = true;
                                }
                            }
                            catch {}

                            // 20130626
                            TestResultOrigins origin = TestResultOrigins.Logical;
                            try {
                                if ("TECHNICAL" == singleTestResult.Attribute("origin").Value.ToUpper()) {
                                    origin = TestResultOrigins.Technical;
                                }
                                if ("AUTOMATIC" == singleTestResult.Attribute("origin").Value.ToUpper()) {
                                    origin = TestResultOrigins.Automatic;
                                }
                            }
                            catch {}

                            if ((TestResultOrigins.Technical == origin) &&
                                //(!knownIssueValue &&
                                 passedValue) {

                                continue;
                            }

                            string testResultDescription = string.Empty;
                            try {
                                testResultDescription = singleTestResult.Attribute("description").Value;
                            }
                            catch {}

                            TMX.TestData.AddTestResult(
                                singleTestResult.Attribute("name").Value,
                                singleTestResult.Attribute("id").Value,
                                passedValue,
                                knownIssueValue,
                                false,
                                null,
                                null,
                                testResultDescription,
                                // 20130626
                                //false,
                                origin,
                                true);

                            //TMX.TestData.CurrentTestResult = TMX.TestData.CurrentTestScenario.TestResults[TMX.TestData.CurrentTestScenario.TestResults.Count - 1];
                            ITestResult currentlyAddedTestResult = TMX.TestData.CurrentTestScenario.TestResults[TMX.TestData.CurrentTestScenario.TestResults.Count - 1];

                            try {
                                //TMX.TestData.CurrentTestResult.PlatformId =
                                currentlyAddedTestResult.PlatformId =
                                    singleTestResult.Attribute("platformId").Value;
                            }
                            catch (Exception eTestResultPlatform) {
                                cmdlet.WriteVerbose(cmdlet, "adding test platform to the current test result");
                                cmdlet.WriteVerbose(cmdlet, eTestResultPlatform.Message);
                            }

                            try {
                                lastTestResultDetailName = string.Empty;

                                var testResultDetails = from testResultDetail in singleTestResult.Descendants("detail")
                                    select testResultDetail;

                                if (null != testResultDetails && 0 < testResultDetails.Count()) {
                                    foreach (var singleDetail in testResultDetails) {

                                        cmdlet.WriteVerbose(cmdlet, "importing test result detail '" + singleDetail.Attribute("name").Value + "', status = '" + singleDetail.Attribute("status").Value + "'");
                                        lastTestResultDetailName = singleDetail.Attribute("name").Value;

                                        //TestResultDetailCmdletBase cmdletTRD = new TestResultDetailCmdletBase();
                                        TestResultDetail detail = new TestResultDetail();
                                        //cmdletTRD.Name = singleDetail.Attribute("name").Value;
                                        detail.TextDetail = singleDetail.Attribute("name").Value;
                                        string detailStatus = singleDetail.Attribute("status").Value;
                                        switch (detailStatus.ToUpper()) {
                                            case "FAILED":
                                                //cmdletTRD.TestResultStatus = TestResultStatuses.Failed;
                                                detail.DetailStatus = TestResultStatuses.Failed;
                                                break;
                                            case "PASSED":
                                                //cmdletTRD.TestResultStatus = TestResultStatuses.Passed;
                                                detail.DetailStatus = TestResultStatuses.Passed;
                                                break;
                                            case "KNOWNISSUE":
                                                //cmdletTRD.TestResultStatus = TestResultStatuses.KnownIssue;
                                                detail.DetailStatus = TestResultStatuses.KnownIssue;
                                                break;
                                            case "NOTTESTED":
                                                //cmdletTRD.TestResultStatus = TestResultStatuses.NotTested;
                                                detail.DetailStatus = TestResultStatuses.NotTested;
                                                break;
                                            default:
                                                //cmdletTRD.TestResultStatus = TestResultStatuses.NotTested;
                                                detail.DetailStatus = TestResultStatuses.NotTested;
                                                break;
                                        }

                                        //cmdlet.WriteVerbose(cmdlet, "the current test result is name = '" + TMX.TestData.CurrentTestResult.Name + "', id ='" + TMX.TestData.CurrentTestResult.Id + "'");
                                        cmdlet.WriteVerbose(cmdlet, "the current test result is name = '" + currentlyAddedTestResult.Name + "', id ='" + currentlyAddedTestResult.Id + "'");

                                        //TMX.TestData.AddTestResultTextDetail(cmdletTRD, cmdletTRD.TestResultDetail);

                                        currentlyAddedTestResult.Details.Add(detail);

                                    }
                                }
                            }
                            catch (Exception eImportDetails) {
                                cmdlet.WriteVerbose(cmdlet, eImportDetails);
                            }
                        }
                    }

                    TMX.TestData.RefreshSuiteStatistics(TMX.TestData.CurrentTestSuite, true);
                }

                TMX.TestData.CurrentTestSuite = currentTestSuite;
                TMX.TestData.CurrentTestScenario = currentTestScenario;

                // ??
                TMX.TestData.CurrentTestResult = currentTestResult;

            }
            catch (Exception eImportDocument) {

                cmdlet.WriteError(
                    cmdlet,
                    "Unable to load an XML report from the file '" +
                    path +
                    "'. " +
                    eImportDocument.Message +
                    "\r\nsuite='" +
                    lastTestSuiteName +
                    "', scenario='" +
                    lastTestScenarioName +
                    "', test result='" +
                    lastTestResultName +
                    "', detail='" +
                    lastTestResultDetailName +
                    "',",
                    "FailedToImportReport",
                    ErrorCategory.InvalidOperation,
                    true);
            }
        }
Esempio n. 2
0
        // 20130331
        //internal static void AddTestResultTextDetail(object detail)
        internal static void AddTestResultTextDetail(TestResultDetailCmdletBase cmdlet, object detail)
        {
            ITestResultDetail testResultDetail =
                new TestResultDetail();

            if (TestData.TestSuites.Count == 0) {
                InitTestData();
            }

            testResultDetail.AddTestResultDetail(
                TestResultDetailTypes.Comment,
                detail.ToString());
            CurrentTestResult.Details.Add(testResultDetail);

            // 20130402
            testResultDetail.DetailStatus = cmdlet.TestResultStatus;

            // 20130331
            switch (cmdlet.TestResultStatus) {
                case TestResultStatuses.Failed:
                    cmdlet.WriteVerbose(cmdlet, "TestResultStatus = Failed");
                    // 20130402
                    //CurrentTestResult.enStatus = TestResultStatuses.Failed;
                    if (TestResultStatuses.KnownIssue != CurrentTestResult.enStatus) {

                        CurrentTestResult.enStatus = TestResultStatuses.Failed;
                    }
                    break;
                case TestResultStatuses.Passed:
                    cmdlet.WriteVerbose(cmdlet, "TestResultStatus = Passed");
                    // 20130402
                    //CurrentTestResult.enStatus = TestResultStatuses.Passed;
                    if (TestResultStatuses.KnownIssue != CurrentTestResult.enStatus &&
                        TestResultStatuses.Failed != CurrentTestResult.enStatus) {

                        CurrentTestResult.enStatus = TestResultStatuses.Passed;
                    }
                    break;
                case TestResultStatuses.NotTested:
                    cmdlet.WriteVerbose(cmdlet, "TestResultStatus = NotTested");
                    // nothing to do
                    break;
                case TestResultStatuses.KnownIssue:
                    cmdlet.WriteVerbose(cmdlet, "TestResultStatus = KnownIssue");
                    CurrentTestResult.enStatus = TestResultStatuses.KnownIssue;
                    break;
                default:
                    cmdlet.WriteVerbose(cmdlet, "TestResultStatus = ????");
                    cmdlet.WriteVerbose(cmdlet, cmdlet.TestResultStatus.ToString());
                    break;
            }

            OnTMXNewTestResultDetailAdded(testResultDetail, null);

            // 20130402
            if (cmdlet.Finished) {

                TMXHelper.TestCaseStarted =
                    System.DateTime.Now;

                TestData.CurrentTestScenario.TestResults.Add(new TestResult(TestData.CurrentTestScenario.Id, TestData.CurrentTestSuite.Id));
                TestData.CurrentTestScenario.TestResults[TestData.CurrentTestScenario.TestResults.Count - 1] =
                    TestData.CurrentTestResult;

            }
        }
Esempio n. 3
0
        internal static void AddTestResultScreenshotDetail(object detail)
        {
            ITestResultDetail testResultDetail =
                new TestResultDetail();

            if (TestData.TestSuites.Count == 0) {
                InitTestData();
            }

            testResultDetail.AddTestResultDetail(
                TestResultDetailTypes.Screenshot,
                detail.ToString());
            CurrentTestResult.Details.Add(testResultDetail);
            CurrentTestResult.SetScreenshot(detail.ToString());
        }
Esempio n. 4
0
        internal static void AddTestResultErrorDetail(ErrorRecord detail)
        {
            ITestResultDetail testResultDetail =
                new TestResultDetail();

            if (TestData.TestSuites.Count == 0) {
                InitTestData();
            }

            testResultDetail.AddTestResultDetail(
                TestResultDetailTypes.ErrorRecord,
                detail);
            CurrentTestResult.Details.Add(testResultDetail);
        }
Esempio n. 5
0
        // 20130331
        //internal static void AddTestResultTextDetail(object detail)
        internal static void AddTestResultTextDetail(TestResultDetailCmdletBase cmdlet, object detail)
        {
            ITestResultDetail testResultDetail =
                new TestResultDetail();

            testResultDetail.AddTestResultDetail(
                TestResultDetailTypes.Comment,
                detail.ToString());
            CurrentTestResult.Details.Add(testResultDetail);

            testResultDetail.DetailStatus = cmdlet.TestResultStatus;

            switch (cmdlet.TestResultStatus) {
                case TestResultStatuses.Failed:
                    cmdlet.WriteVerbose(cmdlet, "TestResultStatus = Failed");
                    if (TestResultStatuses.KnownIssue != CurrentTestResult.enStatus) {

                        CurrentTestResult.enStatus = TestResultStatuses.Failed;
                    }
                    break;
                case TestResultStatuses.Passed:
                    cmdlet.WriteVerbose(cmdlet, "TestResultStatus = Passed");
                    if (TestResultStatuses.KnownIssue != CurrentTestResult.enStatus &&
                        TestResultStatuses.Failed != CurrentTestResult.enStatus) {

                        CurrentTestResult.enStatus = TestResultStatuses.Passed;
                    }
                    break;
                case TestResultStatuses.NotTested:
                    cmdlet.WriteVerbose(cmdlet, "TestResultStatus = NotTested");
                    // nothing to do
                    break;
                case TestResultStatuses.KnownIssue:
                    cmdlet.WriteVerbose(cmdlet, "TestResultStatus = KnownIssue");
                    CurrentTestResult.enStatus = TestResultStatuses.KnownIssue;
                    break;
                default:
                    cmdlet.WriteVerbose(cmdlet, "TestResultStatus = ????");
                    cmdlet.WriteVerbose(cmdlet, cmdlet.TestResultStatus.ToString());
                    break;
            }

            OnTMXNewTestResultDetailAdded(testResultDetail, null);

            // 20130402
            if (cmdlet.Finished) {

                TMXHelper.TestCaseStarted =
                    System.DateTime.Now;

                // 20130621
            //                TestData.CurrentTestScenario.TestResults.Add(new TestResult(TestData.CurrentTestScenario.Id, TestData.CurrentTestSuite.Id));
            //                TestData.CurrentTestScenario.TestResults[TestData.CurrentTestScenario.TestResults.Count - 1] =
            //                    TestData.CurrentTestResult;
                // 20130621
                ITestResult newTestResult = new TestResult(TestData.CurrentTestScenario.Id, TestData.CurrentTestSuite.Id);
                if (TestData.CurrentTestResult == TestData.CurrentTestScenario.TestResults[TestData.CurrentTestScenario.TestResults.Count - 1]) {
                    // autogeneration + Close-TMXTestResult
                    TestData.CurrentTestScenario.TestResults.Add(newTestResult);
                    TestData.CurrentTestResult = TestData.CurrentTestScenario.TestResults[TestData.CurrentTestScenario.TestResults.Count - 1];
                } else {
                    // Set-TMXCurrentTestResult + any closing
                    TestData.CurrentTestScenario.TestResults.Add(TestData.CurrentTestResult);
                    TestData.CurrentTestResult = newTestResult;
                }
            }
        }
Esempio n. 6
0
        internal static void AddTestResultTextDetail(object detail)
        {
            ITestResultDetail testResultDetail =
                new TestResultDetail();

            if (TestData.TestSuites.Count == 0) {
                InitTestData();
            }

            testResultDetail.AddTestResultDetail(
                TestResultDetailTypes.Comment,
                detail.ToString());
            CurrentTestResult.Details.Add(testResultDetail);
            OnTMXNewTestResultDetailAdded(testResultDetail, null);
        }