예제 #1
0
        public bool AddResult(ulong runId, ulong caseId, ResultStatus resultStatusId, ulong?userId = null)
        {
            var response = _apiClient.AddResultForCase(runId, caseId, resultStatusId, assignedToID: userId);

            if (!response.WasSuccessful)
            {
                Console.WriteLine($"TestRail: Error occured while reporting results for case {caseId}. Exception: {response.Exception.Message}");
            }

            return(response.WasSuccessful);
        }
예제 #2
0
        public void ResultBulkSend()
        {
            foreach (var item in _results)
            {
                var testCaseId = item.Key;
                var testStatus = item.Value.All(x => x.Status == ResultStatus.Passed)
                    ? ResultStatus.Passed
                    : ResultStatus.Failed;

                string message;

                if (testStatus == ResultStatus.Passed)
                {
                    message = "No errors";
                }
                else
                {
                    var           failedTestCases = item.Value.Where(x => x.Status == ResultStatus.Failed).ToList();
                    StringBuilder sb = new StringBuilder();
                    foreach (CaseResult caseResult in failedTestCases)
                    {
                        sb.AppendLine($"Error message: {caseResult.Comment}");
                    }
                    message = sb.ToString();
                }

                var result = _client.AddResultForCase((ulong)_testRunId, testCaseId, testStatus, message);
                if (!result.WasSuccessful)
                {
                    var errorMessage = result.Exception.Message;
                    switch (errorMessage)
                    {
                    case string a when a.Contains("400"):
                        Console.WriteLine($"TestCaseId {testCaseId} not found in TestRail. " +
                                          $"Please check if the id is correct.");

                        Console.WriteLine($"Exception: {errorMessage}");
                        break;

                    case string a when a.Contains("403"):
                        Console.WriteLine("The user from the TestRail.json file does not have sufficient rights to " +
                                          "work with the project specified in this file.");

                        Console.WriteLine($"Exception: {errorMessage}");
                        break;

                    default:
                        Console.WriteLine($"Error sending results to TestRail: {errorMessage}");
                        break;
                    }
                }
                _results.TryRemove(testCaseId, out _);
            }
        }
예제 #3
0
        public void TearDown()
        {
            var id             = TestContext.CurrentContext.Test.Properties.Get("Description").ToString().Replace("C", "");
            var result         = TestContext.CurrentContext.Result.Outcome.Status;
            var testrailStatus = result switch
            {
                TestStatus.Failed => ResultStatus.Failed,
                TestStatus.Passed => ResultStatus.Passed,
                _ => ResultStatus.Retest
            };

            var resultForCase = Client.AddResultForCase(_runId, ulong.Parse(id), testrailStatus);

            Console.WriteLine(resultForCase.WasSuccessful);
            WebDriver.Quit();
        }
    }
        private void onTestCaseExecutionComplete(TestCase testCase, TestCaseResult testCaseResult)
        {
#if DEBUG
            var testStepContent = _testStepResultBuilder.ToString();
#endif
            try
            {
                LogEvent.Debug($"{MethodInfo.GetCurrentMethod().Name} {testCaseResult.VirtualUser}");

                var messageBuilder = new StringBuilder();
                messageBuilder.AppendLine($"{_testStepResultBuilder.ToString()}");
                messageBuilder.AppendLine();
                messageBuilder.AppendLine("Test case summary:");
                messageBuilder.AppendLine($"Test suite:  \"{_currentTestSuiteFile}\"");
                messageBuilder.AppendLine($"Test message:  {testCaseResult.TestMessage ?? "None"}");
                messageBuilder.AppendLine($"Test verdict:  {testCaseResult.TestVerdict}");
                messageBuilder.AppendLine(testCaseResult.FormattedCounters);
                messageBuilder.AppendLine($"Start:  {testCaseResult.StartTime}, End: {testCaseResult.EndTime}, Elapsed time:{testCaseResult.ElapsedTime}");

#if DEBUG
                var uUserId  = Convert.ToUInt32(testCase.UserID);
                var trStatus = convertToTestRailStatus(testCaseResult.TestVerdict);
                var message  = messageBuilder.ToString();
#endif
                var commandResult = _testRailClient.AddResultForCase((ulong)_testRailRun.ID, Convert.ToUInt32(testCase.UserID),
                                                                     convertToTestRailStatus(testCaseResult.TestVerdict), messageBuilder.ToString(), _parameters["ProductVersion"],
                                                                     testCaseResult.ElapsedTime);

                LogEvent.Info(string.Format("Test case result addition {0}.", commandResult.WasSuccessful ? "successful" : "unsuccessful"));

                if (!commandResult.WasSuccessful)
                {
                    //LogEvent.Info(commandResult.Exception.ToString());
                    throw commandResult.Exception;
                }
            }
            catch (Exception e)
            {
                LogEvent.Error(e.ToString());
                throw;
            }
            finally
            {
            }
        }
 public void UpdateSuiteExecutionResult(ulong suiteId, ulong runId, int id, ScenarioExecutionStatus status)
 {
     _client?.AddResultForCase(runId, (ulong)id, MapToReultStatus(status));
 }
예제 #6
0
 private void MarkAsPassed(ulong testCaseId)
 {
     _client.AddResultForCase(_testRunId, testCaseId, ResultStatus.Passed);
 }