private void Log(IRestResponse response) { var requestBody = response.Request.Parameters.FirstOrDefault(p => p.Type == ParameterType.RequestBody); string attachName = $"{response.Request.Method} {response.Request.Resource}"; var attachContext = new StringBuilder(); attachContext.AppendLine($"Executing {response.Request.Method} {response.ResponseUri}"); if (requestBody != null) { attachContext.AppendLine($"Content-Type: {requestBody.ContentType}").AppendLine(); attachContext.AppendLine(requestBody.Value.ToString()); } attachContext.AppendLine().AppendLine(); attachContext.AppendLine($"Response: {response.StatusCode}"); if (response.ErrorMessage != null) { attachContext.AppendLine(response.ErrorMessage); } attachContext.AppendLine(response.Content); //TestLog.WriteLine(attachContext.ToString()); Allure2Helper.AttachJson(attachName, attachContext.ToString()); // AllureReport.GetInstance().AddAttachment(TestContext.CurrentContext.Test.FullName, // Encoding.UTF8.GetBytes(attachContext.ToString()), attachName, "application/json"); }
private void LogToStep(IRestResponse response) { var requestBody = response.Request.Parameters.FirstOrDefault(p => p.Type == ParameterType.RequestBody); var requestHeaders = response.Request.Parameters.FindAll(p => p.Type == ParameterType.HttpHeader); string attachName = $"{DateTime.UtcNow.ToString("s")}(UTC) {response.Request.Method} {response.Request.Resource}"; var attachContext = new StringBuilder(); attachContext.AppendLine($"Executing {response.Request.Method} {response.ResponseUri}"); if (requestBody != null) { attachContext.AppendLine($"Content-Type: {requestBody.ContentType}").AppendLine(); attachContext.AppendLine(requestBody.Value.ToString()); } requestHeaders.ForEach(h => attachContext.AppendLine(h.Name + ": " + h.Value)); attachContext.AppendLine().AppendLine(); attachContext.AppendLine($"Response: {response.StatusCode}"); if (response.ErrorMessage != null) { attachContext.AppendLine(response.ErrorMessage); } attachContext.AppendLine(response.Content); Allure2Helper.AttachJson(attachName, attachContext.ToString()); }
private void Log(Message message, string send = "Sending") { string attachName = $"{send} message"; var attachContext = new StringBuilder(); attachContext.AppendLine(send); if (message != null) { attachContext.AppendLine(message.ToString().Replace("\u0001", "|")); } Allure2Helper.AttachJson(attachName, attachContext.ToString()); }
private void Log(IRestResponse response) { var requestBody = response.Request.Parameters.FirstOrDefault(p => p.Type == ParameterType.RequestBody); string attachName = $"{response.Request.Method} {response.Request.Resource}"; var attachContext = new StringBuilder(); attachContext.AppendLine($"Executing {response.Request.Method} {response.ResponseUri}"); if (requestBody != null) { attachContext.AppendLine($"Content-Type: {requestBody.ContentType}").AppendLine(); attachContext.AppendLine(requestBody.Value.ToString()); } attachContext.AppendLine().AppendLine(); attachContext.AppendLine($"Response: {response.StatusCode}"); if (response.ErrorMessage != null) { attachContext.AppendLine(response.ErrorMessage); } attachContext.AppendLine(response.Content); Allure2Helper.AttachJson(attachName, attachContext.ToString()); }