Пример #1
0
        public override void RunTestCase(TestCaseExecution execution)
        {
            //get the test case source ids to be used by the Minitest
            string webId = execution.TestCase.SourceId;
            //update the execution status to be running
            SaberAgent.Log.logger.Info(string.Format("Set status of execution {0} of job {1} to running", execution.ExecutionId, Job2Run.JobId));
            execution.SetStatus(ExecutionStatus.Running);
            string scriptRootFolderForProject = scriptRootFolder + @"\" + vcsRootPath + @"\RubyMinitest";

            string scriptFilePath = GetTestScriptFilesnFolderContainTestCaseWithWebId(scriptRootFolderForProject, webId);
            if (string.IsNullOrEmpty(scriptFilePath))
            {
                SaberAgent.Log.logger.Info(string.Format("Could not find the test script for the test execution {0} of job {1}", execution.ExecutionId, Job2Run.JobId));
                execution.SetStatus(ExecutionStatus.Fail);
            }
            else
            {
                try
                {
                    string logfilePath = string.Format(@"{0}\webid_{1}.log", this.RootResultPath, execution.TestCase.SourceId);
                    string testcasePattern = string.Format(@"/_webid_{0}/", webId);
                    string parameters = string.Format(@"{0} ""{1}"" ""{2}"" ""{3}""", testcasePattern, scriptFilePath, scriptRootFolderForProject, logfilePath);
                    string runBATFile = @"C:\SaberAgent\RunRubyMiniTest.bat";
                    string command = string.Format(@"{0} /C {1}", runBATFile, parameters);
                    SaberAgent.Log.logger.Info(command);
                    string result = CMDScript.RumCmdWithWindowsVisible(runBATFile, parameters);
                    SaberAgent.Log.logger.Info(result);

                    SaberAgent.Log.logger.Info(string.Format("Execution of test case has been finished for job {0}", Job2Run.JobId));
                    string defaultMiniTestResultFile = string.Format(@"{0}\test\reports\_webid_{1}.xml", scriptRootFolderForProject, webId);
                    //copy related files to Result folder
                    FileHelper.CopyFile(@"C:\SaberAgent\Config\Environment.xml", this.RootResultPath, true);
                    if (FileHelper.IsExistsFile(defaultMiniTestResultFile))
                    {
                        FileHelper.CopyFile(defaultMiniTestResultFile, this.RootResultPath, true);
                    }
                    else
                    {
                        string message = string.Format("Could not find the result file for case [{0}] at location [{1}]", execution.TestCase.Name, defaultMiniTestResultFile);
                        SaberAgent.Log.logger.Error(message);
                        Job2Run.AddJobProgressInformation(message);
                        execution.SetStatus(ExecutionStatus.Fail);
                        return;
                    }
                    //Parse the test result
                    SaberAgent.Log.logger.Info(string.Format("Start to parse the result for execution {0} of job {1}", execution.ExecutionId, Job2Run.JobId));
                    resultParser.ParseResult(string.Format(@"{0}\_webid_{1}.xml", this.RootResultPath, webId), Job2Run.JobId);
                    SaberAgent.Log.logger.Info(string.Format("Result parsing has been completed for execution {0} of job {1}", execution.ExecutionId, Job2Run.JobId));
                    //set execution status to complete
                    SaberAgent.Log.logger.Info(string.Format("Set status of execution {0} of job {1} to Compleate", execution.ExecutionId, Job2Run.JobId));
                    execution.SetStatus(ExecutionStatus.Complete);
                }
                catch (Exception ex)
                {
                    execution.SetStatus(ExecutionStatus.Fail);
                    string error = string.Format("Failed to run the execution {0}", execution.ExecutionId);
                    SaberAgent.Log.logger.Error(error, ex);
                }
            }
        }
        public override void RunTestCase(TestCaseExecution execution)
        {
            FileHelper.EmptyFolder(this.RootResultPath);
            string resultFileFullPath = this.RootResultPath + @"\" + execution.TestCase.SourceId.ToString() + @".xml";

            SaberAgent.Log.logger.Info(string.Format("Set status of execution {0} of job {1} to running", execution.ExecutionId, Job2Run.JobId));
            execution.SetStatus(ExecutionStatus.Running);

            //get the test case source ids to used by the NUnit console
            string testCaseIdList = "WebId=" + execution.TestCase.SourceId;

            string resultLogFilePath = string.Format(@"{0}\{1}_RunCSharpNUnitTest.bat.log", this.RootResultPath, execution.TestCase.SourceId);
            string parameters = string.Format(@"""{0}"" {1}.xml ""{2}"" {3}> ""{4}""",
                testCaseIdList, execution.TestCase.SourceId, this.RootResultPath, this.vcsRootFolder + @"/CSharpNUnit/Saber", resultLogFilePath);
            string runBATFile = @"C:\SaberAgent\RunCSharpNUnitTest.bat";

            string command = string.Format(@"{0} /C {1}", runBATFile, parameters);
            SaberAgent.Log.logger.Info(command);
            string result = CMDScript.RumCmd(runBATFile, parameters);
            SaberAgent.Log.logger.Info(result);

            SaberAgent.Log.logger.Info(string.Format("Execution of test case [{0}] has been finished for job {1}", execution.TestCase.Name, Job2Run.JobId));
            //Parse the test result
            SaberAgent.Log.logger.Info(string.Format("Start to parse the result for test Case [{0}]", execution.TestCase.Name));
            FileHelper.CopyFile(@"C:\SaberAgent\Config\Environment.xml", this.RootResultPath, true);
            try
            {
                resultParser.ParseResult(resultFileFullPath, Job2Run.JobId);
                SaberAgent.Log.logger.Info(string.Format("Result parsing has been completed for test Case [{0}]", execution.TestCase.Name));
            }
            catch (Exception ex)
            {
                execution.SetStatus(ExecutionStatus.Fail);
                SaberAgent.Log.logger.Error(string.Format("Met error when parse the result of test case [{0}]", execution.TestCase.Name), ex);
                return;
            }

            //set execution status to complete
            SaberAgent.Log.logger.Info(string.Format("Set status of execution {0} of test case {1} to Complete", execution.TestCase.Name, Job2Run.JobId));
            execution.SetStatus(ExecutionStatus.Complete);
        }
Пример #3
0
        private void RunAutomationCase(TestCaseExecution testCaseExecution, CancellationToken token)
        {
            ATFEnvironment.Log.logger.Info("Run automation case #" + testCaseExecution.TestCaseId);

            testCaseExecution.SetStatus(ExecutionStatus.Running);

            var result = new TestResult
            {
                ExecutionId = testCaseExecution.ExecutionId,
                Result = (int)ResultType.NotRun,
                IsTriaged = false,
                TriagedBy = null,
                Files = null,
            };

            TestResult.CreateRunResult(result);

            try
            {
                // todo: call agent to run test cases
                // change test result
                Thread.Sleep(60 * 1000);

                testCaseExecution.SetStatus(ExecutionStatus.Complete);
                result.SetResult(ResultType.Pass);

                if (token.IsCancellationRequested)
                {
                    ATFEnvironment.Log.logger.Info("Timeout to run automation case #" + testCaseExecution.TestCaseId);
                    testCaseExecution.SetStatus(ExecutionStatus.Complete);
                    result.SetResult(ResultType.TimeOut);
                }
            }
            catch (EnvironmentException ex)
            {
                string errorMsg = string.Format("Failed to run automation case #{0}, error: {1}", testCaseExecution.TestCaseId, ex.Message);
                ATFEnvironment.Log.logger.Error(errorMsg);
                testCaseExecution.SetStatus(ExecutionStatus.Fail);
                result.SetResult(ResultType.Exception);
            }
            catch (Exception ex)
            {
                string errorMsg = string.Format("Failed to run automation case #{0}, error: {1}", testCaseExecution.TestCaseId, ex.Message);
                ATFEnvironment.Log.logger.Error(errorMsg);
                testCaseExecution.SetStatus(ExecutionStatus.Fail);
                result.SetResult(ResultType.Failed);
            }
        }