public void AddTestResult(string testName, DateTime testStartTime, string node, TestResult testResult) { bool success = testResult.TestState != TestState.Error; if (success) { _passedTests++; } else { _failedTests++; } _totalTests++; var exceutionId = Guid.NewGuid(); var testEndTime = DateTime.Now; var testDuration = testEndTime.Subtract(testStartTime); var testTypeId = StringToGuid(testName); var testId = StringToGuid(testName + "test"); string outcome = success ? "Passed" : "Failed"; string log = string.Join(Environment.NewLine, testResult.Log); if (!string.IsNullOrEmpty(log)) { log = log + Environment.NewLine + Environment.NewLine; } string errorOutput = success || testResult.Error == null ? "": "<Output>"+ "<ErrorInfo>"+ "<Message>" + HttpUtility.HtmlEncode(testResult.Error.Message) + "</Message>"+ "<StackTrace>"+ HttpUtility.HtmlEncode(log + testResult.Error.StackTrace) + "</StackTrace>"+ "</ErrorInfo>"+ " </Output> "; _results.Append( "<UnitTestResult executionId = \"" + exceutionId + "\" testId = \"" + testId + "\" " + "testName = \"" + testName + "\" computerName=\"" + node + "\" duration=\"" + testDuration + "\"" + " startTime=\"" + testStartTime.ToString("s", CultureInfo.InvariantCulture) + "\" endTime=\"" + testEndTime.ToString("s", CultureInfo.InvariantCulture) + "\"" + " testType=\"" + testTypeId + "\" outcome=\"" + outcome + "\" " + "testListId=\"" + _resultsNotInListId + "\">" + errorOutput + "</UnitTestResult>" ); _testDefinitions.Append( "<UnitTest name=\"" + testName + "\" id=\"" + testId + "\" >" + "<Execution id= \"" + exceutionId + "\" />" + "<TestMethod codeBase=\"" + "cb:" + testName + "\" name=\"DE Chrome " + testName + "\" className=\"" + testName + "\"/>" + "</UnitTest>" ); _testEntries.Append( "<TestEntry testId=\""+ testId + "\" executionId=\""+ exceutionId +"\" testListId=\"" + _resultsNotInListId + "\" />" ); }
public static void FinishedWorkItem(string nodeName, TestResult testResult) { lock (Lock) { var currentTestJob = TestingJobs[0]; var workItemTask = currentTestJob.CurrentWorkItems[nodeName]; var item = workItemTask.WorkItem; currentTestJob.ResultGenerator.AddTestResult(item.Testcase.Type, workItemTask.StartedAt, nodeName, testResult); currentTestJob.FinishedWorkItems.Add(item); currentTestJob.CurrentWorkItems.Remove(nodeName); Console.WriteLine(nodeName + " Finished WI: " + currentTestJob.FinishedWorkItems.Count + " Done. " + currentTestJob.CurrentWorkItems.Count + " Now. " + currentTestJob.WaitingWorkItems.Count + " Waiting."); if (currentTestJob.WaitingWorkItems.Count == 0 && currentTestJob.CurrentWorkItems.Count == 0) { TestingJobs.Remove(currentTestJob); FinishedTestingJobs.Add(currentTestJob); Console.WriteLine("Testjob " + currentTestJob.Guid + " finished."); } } }
private void HandleResult(ITestWorker testWorker, TestResult testResult) { if (testWorker.WorkItem != null && (testResult.TestState == TestState.Error || testResult.TestState == TestState.ErrorRepeat) && testWorker.WorkItem.RunCount < RegtestingServerConfiguration.MaxRunCount) { _testPool.ReAddWorkItem(testWorker.WorkItem); testWorker.WorkItem = null; return; } WorkItem workItem = testWorker.WorkItem; workItem.TestState = testResult.TestState; string imagefile = null; if (!String.IsNullOrEmpty(testResult.Screenshot)) { string folder = RegtestingServerConfiguration.Screenshotsfolder; string subFolder = DateTime.Now.Year + "-" + DateTime.Now.Month + "\\"; string fileName = "screen" + Helper.GetScreenshotString() + ".png"; Directory.CreateDirectory(folder + subFolder); imagefile = subFolder + fileName; Screenshot screenshot = new Screenshot(testResult.Screenshot); screenshot.SaveAsFile(folder + imagefile, ImageFormat.Png); } Result result = _resultRepository.Get(workItem.Testsystem, workItem.Testcase, workItem.Browser, workItem.Language); result.ResultCode = testResult.TestState; result.DetailLog = CreateLog(testResult.Log); result.Error = testResult.Error; result.Testtime = DateTime.Now; result.ScreenshotFile = imagefile; if (result.ResultCode == TestState.Error || result.ResultCode == TestState.ErrorRepeat || result.ResultCode == TestState.KnownError) { if (result.ErrorCount == null) { result.ErrorCount = 1; result.ErrorSince = result.Testtime; } else { result.ErrorCount = result.ErrorCount + 1; } } else { result.ErrorSince = null; result.ErrorCount = null; } _resultRepository.Store(result); workItem.Result = result; foreach (ITestJobManager testJobManager in workItem.TestJobManagers) { HistoryResult historyResult = Mapper.Map<HistoryResult>(workItem); historyResult.DetailLog = CreateLog(testResult.Log); historyResult.ResultCode = testResult.TestState; historyResult.Error = testResult.Error; historyResult.Testtime = DateTime.Now; historyResult.TestJob = testJobManager.TestJob; historyResult.ScreenshotFile = imagefile; _historyResultRepository.Store(historyResult); } lock (TestsystemSummariesCache.Cache.GetLock(workItem.Testsystem.ID)) { TestsystemSummariesCache.Cache.Set(workItem.Testsystem.ID, null); } testWorker.WorkItem = null; _testPool.WorkItemFinished(workItem); }
void INodeService.FinishedWork(string nodeName, TestResult testResult) { ITestWorker testWorker = _testPool.GetTestWorker(nodeName); HandleResult(testWorker, testResult); }
private void SendTestResultToServer(TestResult testResult) { Console.Out.WriteLine("Result: " + testResult.TestState); using (WcfClient objWcfClient = new WcfClient(_serverAdr)) { objWcfClient.FinishedWork(_nodename, testResult); } Console.Out.WriteLine("Finished."); }
private TestResult HandleTest(WorkItem workItem) { TestResult testResult = new TestResult(); ITestable testable = null; List<string> log = new List<string>(); try { log.Add("Test on " + _nodename); /**1: Load Testclass **/ Console.WriteLine(@"Testing {0} {1} ({2}/{3})", workItem.Testcase.Name, workItem.Browser.Name, workItem.Testsystem.Name, workItem.Language.Languagecode); testable = LoadTestable(workItem); if (testable == null) return new TestResult { TestState = TestState.NotAvailable }; /**2: Wait for branch get ready **/ WaitOnWebExceptions(workItem); /**3: Prepare Test **/ Browser browser = new Browser() { Browserstring = workItem.Browser.Browserstring, Versionsstring = workItem.Browser.Versionsstring }; testable.SetupTest(WebDriverInitStrategy.SeleniumLocal, browser, workItem.Testsystem.Url, workItem.Language.Languagecode); /**4: Run Test **/ testable.Test(); testResult.TestState = TestState.Success; } catch (NotSupportedException notSupportedException) { Error error = CreateErrorFromException(notSupportedException); testResult.TestState = TestState.NotSupported; testResult.Error = error; } catch (TaskCanceledException taskCanceledException) { Error error = CreateErrorFromException(taskCanceledException); testResult.TestState = TestState.Canceled; testResult.Error = error; } catch (Exception exception) { ServerErrorModel serverException = null; try { if (testable != null) serverException = testable.CheckForServerError(); } catch { //Error catching serverException } Error error = CreateErrorFromException(exception); if (serverException != null) { error.Type = serverException.Type; error.Message = serverException.Message; error.InnerException = serverException.InnerException; //objError.StackTrace = serverException.StackTrace; Keep error stacktrace. } testResult.TestState = TestState.Error; testResult.Error = error; if (testable != null) testResult.Screenshot = testable.SaveScreenshot(""); } finally { if (testable != null) { testable.TeardownTest(); log.AddRange(testable.GetLogLastTime()); } testResult.Log = log; } return testResult; }
/// <summary> /// The node has finished some WorkItem /// </summary> /// <param name="nodeName">the node</param> /// <param name="testResult">The results of the testrun</param> public void FinishedWork(string nodeName, TestResult testResult) { _channel.FinishedWork(nodeName, testResult); }
void INodeService.FinishedWork(string nodeName, TestResult testResult) { TestPool.FinishedWorkItem(nodeName, testResult); }