private static void StartStep(StepInfo stepInfo, string containerId)
        {
            var stepResult = new StepResult
            {
                name = $"{stepInfo.StepDefinitionType} {stepInfo.Text}"
            };

            allure.StartStep(containerId, AllureHelper.NewId(), stepResult);

            if (stepInfo.Table != null)
            {
                var csvFile = $"{Guid.NewGuid().ToString()}.csv";
                using (var csv = new CsvWriter(File.CreateText(csvFile)))
                {
                    foreach (var item in stepInfo.Table.Header)
                    {
                        csv.WriteField(item);
                    }
                    csv.NextRecord();
                    foreach (var row in stepInfo.Table.Rows)
                    {
                        foreach (var item in row.Values)
                        {
                            csv.WriteField(item);
                        }
                        csv.NextRecord();
                    }
                }
                allure.AddAttachment("table", "text/csv", csvFile);
            }
        }
 private void StartFixture(HookBinding hook, string containerId)
 {
     if (hook.HookType.ToString().StartsWith("Before"))
     {
         allure.StartBeforeFixture(containerId, AllureHelper.NewId(), AllureHelper.GetFixtureResult(hook));
     }
     else
     {
         allure.StartAfterFixture(containerId, AllureHelper.NewId(), AllureHelper.GetFixtureResult(hook));
     }
 }
Beispiel #3
0
        private static void StartStep(StepInstance stepInstance)
        {
            var stepResult = new StepResult()
            {
                name = $"{stepInstance.Keyword} {stepInstance.Text}"
            };

            var table = stepInstance.TableArgument;

            // add step params for 1 row table
            if (table != null && table.RowCount == 1)
            {
                var paramNames = table.Header.ToArray();
                var parameters = new List <Parameter>();
                for (int i = 0; i < table.Header.Count; i++)
                {
                    parameters.Add(new Parameter()
                    {
                        name = paramNames[i], value = table.Rows[0][i]
                    });
                }
                stepResult.parameters = parameters;
            }

            allure.StartStep(AllureHelper.NewId(), stepResult);

            // add csv table for multi-row table
            if (table != null && table.RowCount != 1)
            {
                var csvFile = $"{Guid.NewGuid().ToString()}.csv";
                using (var csv = new CsvWriter(File.CreateText(csvFile)))
                {
                    foreach (var item in table.Header)
                    {
                        csv.WriteField(item);
                    }
                    csv.NextRecord();
                    foreach (var row in table.Rows)
                    {
                        foreach (var item in row.Values)
                        {
                            csv.WriteField(item);
                        }
                        csv.NextRecord();
                    }
                }
                allure.AddAttachment("table", "text/csv", csvFile);
            }
        }
        private void StartStep(StepInstance stepInstance)
        {
            var stepResult = new StepResult
            {
                name = $"{stepInstance.Keyword} {stepInstance.Text}"
            };


            // parse MultilineTextArgument
            if (stepInstance.MultilineTextArgument != null)
            {
                allure.AddAttachment(
                    "multiline argument",
                    "text/plain",
                    Encoding.ASCII.GetBytes(stepInstance.MultilineTextArgument),
                    ".txt");
            }

            var  table            = stepInstance.TableArgument;
            bool isTableProcessed = (table == null);

            // parse table as step params
            if (table != null)
            {
                var header = table.Header.ToArray();
                if (pluginConfiguration.ConvertToParameters)
                {
                    var parameters = new List <Parameter>();

                    // convert 2 column table into param-value
                    if (table.Header.Count == 2)
                    {
                        var paramNameMatch  = pluginConfiguration.ParamNameRegex?.IsMatch(header[0]);
                        var paramValueMatch = pluginConfiguration.ParamValueRegex?.IsMatch(header[1]);
                        if (paramNameMatch.HasValue && paramValueMatch.HasValue && paramNameMatch.Value && paramValueMatch.Value)
                        {
                            for (int i = 0; i < table.RowCount; i++)
                            {
                                parameters.Add(new Parameter {
                                    name = table.Rows[i][0], value = table.Rows[i][1]
                                });
                            }

                            isTableProcessed = true;
                        }
                    }
                    // add step params for 1 row table
                    else if (table.RowCount == 1)
                    {
                        for (int i = 0; i < table.Header.Count; i++)
                        {
                            parameters.Add(new Parameter {
                                name = header[i], value = table.Rows[0][i]
                            });
                        }
                        isTableProcessed = true;
                    }

                    stepResult.parameters = parameters;
                }
            }

            allure.StartStep(AllureHelper.NewId(), stepResult);

            // add csv table for multi-row table if was not processed as params already
            if (!isTableProcessed)
            {
                using (var sw = new StringWriter())
                    using (var csv = new CsvWriter(sw))
                    {
                        foreach (var item in table.Header)
                        {
                            csv.WriteField(item);
                        }
                        csv.NextRecord();
                        foreach (var row in table.Rows)
                        {
                            foreach (var item in row.Values)
                            {
                                csv.WriteField(item);
                            }
                            csv.NextRecord();
                        }
                        allure.AddAttachment("table", "text/csv",
                                             Encoding.ASCII.GetBytes(sw.ToString()), ".csv");
                    }
            }
        }