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

            AllureLifecycle.Instance.StartStep(containerId, PluginHelper.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();
                    }
                }

                AllureLifecycle.Instance.AddAttachment("table", "text/csv", csvFile);
            }
        }
Esempio n. 2
0
 private void StartFixture(HookBinding hook, string containerId)
 {
     if (hook.HookType.ToString().StartsWith("Before"))
     {
         AllureLifecycle.Instance.StartBeforeFixture(containerId, PluginHelper.NewId(), PluginHelper.GetFixtureResult(hook));
     }
     else
     {
         AllureLifecycle.Instance.StartAfterFixture(containerId, PluginHelper.NewId(), PluginHelper.GetFixtureResult(hook));
     }
 }
        private void StartStep(StepInstance stepInstance)
        {
            var stepResult = new StepResult
            {
                name = $"{stepInstance.Keyword} {stepInstance.Text}"
            };


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

            var table            = stepInstance.TableArgument;
            var isTableProcessed = table == null;

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

                    // convert 2 column table into param-value
                    if (table.Header.Count == 2)
                    {
                        var paramNameMatch = Regex.IsMatch(header[0],
                                                           PluginHelper.SpecFlowCfg.stepArguments.paramNameRegex);
                        var paramValueMatch = Regex.IsMatch(header[1],
                                                            PluginHelper.SpecFlowCfg.stepArguments.paramValueRegex);
                        if (paramNameMatch && paramValueMatch)
                        {
                            for (var 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 (var i = 0; i < table.Header.Count; i++)
                        {
                            parameters.Add(new Parameter {
                                name = header[i], value = table.Rows[0][i]
                            });
                        }
                        isTableProcessed = true;
                    }

                    stepResult.parameters = parameters;
                }
            }
            AllureLifecycle.Instance.StartStep(PluginHelper.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();
                        }

                        AllureLifecycle.Instance.AddAttachment("table", "text/csv",
                                                               Encoding.UTF8.GetBytes(sw.ToString()), ".csv");
                    }
            }
        }