From 8d0fdb0b3bef95d975d6d257441f99339fb5804f Mon Sep 17 00:00:00 2001 From: danilov-sv Date: Mon, 23 Jan 2023 14:15:50 +0600 Subject: [PATCH 1/2] Changed encoding of csv attachements to UTF8 Changed encoding of csv attachements to UTF8 to support non-ASCII symbols (ex. cyrillic) --- Allure.SpecFlowPlugin/AllureTestTracerWrapper.cs | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/Allure.SpecFlowPlugin/AllureTestTracerWrapper.cs b/Allure.SpecFlowPlugin/AllureTestTracerWrapper.cs index 6d99fd18..e0cf7f7f 100644 --- a/Allure.SpecFlowPlugin/AllureTestTracerWrapper.cs +++ b/Allure.SpecFlowPlugin/AllureTestTracerWrapper.cs @@ -127,7 +127,8 @@ private void StartStep(StepInstance stepInstance) // add csv table for multi-row table if was not processed as params already if (isTableProcessed) return; - using var sw = new StringWriter(); + var ms = new MemoryStream(); + var sw = new StreamWriter(ms, System.Text.Encoding.UTF8); using var csv = new CsvWriter(sw, CultureInfo.InvariantCulture); foreach (var item in table.Header) csv.WriteField(item); csv.NextRecord(); @@ -137,8 +138,8 @@ private void StartStep(StepInstance stepInstance) csv.NextRecord(); } - allure.AddAttachment("table", "text/csv", - Encoding.ASCII.GetBytes(sw.ToString()), ".csv"); + sw.Flush(); + allure.AddAttachment("table", "text/csv", ms.ToArray(), ".csv"); } private static void FailScenario(Exception ex) @@ -151,4 +152,4 @@ private static void FailScenario(Exception ex) }); } } -} \ No newline at end of file +} From 6836d2c2a1ae79f2d6f223a8705f55ed84654136 Mon Sep 17 00:00:00 2001 From: danilov-sv Date: Mon, 23 Jan 2023 15:35:06 +0600 Subject: [PATCH 2/2] handling IDisposable --- Allure.SpecFlowPlugin/AllureTestTracerWrapper.cs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Allure.SpecFlowPlugin/AllureTestTracerWrapper.cs b/Allure.SpecFlowPlugin/AllureTestTracerWrapper.cs index e0cf7f7f..a56ec182 100644 --- a/Allure.SpecFlowPlugin/AllureTestTracerWrapper.cs +++ b/Allure.SpecFlowPlugin/AllureTestTracerWrapper.cs @@ -127,8 +127,8 @@ private void StartStep(StepInstance stepInstance) // add csv table for multi-row table if was not processed as params already if (isTableProcessed) return; - var ms = new MemoryStream(); - var sw = new StreamWriter(ms, System.Text.Encoding.UTF8); + using var ms = new MemoryStream(); + using var sw = new StreamWriter(ms, System.Text.Encoding.UTF8); using var csv = new CsvWriter(sw, CultureInfo.InvariantCulture); foreach (var item in table.Header) csv.WriteField(item); csv.NextRecord();