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);
            }
        }
Beispiel #2
0
        /// <summary>
        /// Wraps method into AllureStep.
        /// </summary>
        public static void WrapInStep(this AllureLifecycle lifecycle, Action action, string stepName = "", [CallerMemberName] string callerName = "")
        {
            if (string.IsNullOrEmpty(stepName))
            {
                stepName = callerName;
            }

            var id         = Guid.NewGuid().ToString();
            var stepResult = new StepResult {
                name = stepName
            };

            try
            {
                lifecycle.StartStep(id, stepResult);
                action.Invoke();
                lifecycle.StopStep(step => stepResult.status = Status.passed);
            }
            catch (Exception e)
            {
                lifecycle.StopStep(step =>
                {
                    step.statusDetails = new StatusDetails
                    {
                        message = e.Message,
                        trace   = e.StackTrace
                    };
                    step.status = AllureNUnitHelper.GetNUnitStatus();
                });
                throw;
            }
        }
Beispiel #3
0
        public static void WrapInStep(this AllureLifecycle allureInstance, Action action, string stepName = "")
        {
            var id         = Guid.NewGuid().ToString();
            var stepResult = new StepResult {
                name = stepName
            };

            try
            {
                allureInstance.StartStep(id, stepResult);
                action.Invoke();
                allureInstance.StopStep(step => stepResult.status = Status.passed);
            }
            catch (ArgumentNullException)
            {
                Console.WriteLine($" > WARN - You can't use step {stepName} here. Allure hasn't been initialized");
                action.Invoke();
            }
            catch (Exception ex)
            {
                allureInstance.StopStep(step =>
                {
                    step.stage         = Stage.finished;
                    step.status        = Status.failed;
                    step.statusDetails = GetStatusDetails(ex);
                });
                throw;
            }
        }
Beispiel #4
0
        public static string AddStep(step st)
        {
            StepResult str = new StepResult();

            if (string.IsNullOrWhiteSpace(st.id))
            {
                st.id = Guid.NewGuid().ToString("N");
            }

            string uuid = st.id;

            str.name  = st.name;
            str.stage = Stage.pending;
            if (st.listParamenters != null)
            {
                str.parameters = st.listParamenters;
            }

            if (st.listAttachment != null)
            {
                str.attachments = st.listAttachment;
            }

            str.description = st.description;
            _instance.StartStep(uuid, str);
            return(uuid);
        }
Beispiel #5
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");
                    }
            }
        }
Beispiel #7
0
        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;
            var isTableProcessed = table == null;

            // parse table as step params
            if (table != null)
            {
                var header = table.Header.ToArray();
                if (PluginConfiguration.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], PluginConfiguration.stepArguments.paramNameRegex);
                        var paramValueMatch =
                            Regex.IsMatch(header[1], PluginConfiguration.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;
                }
            }

            Allure.StartStep(Guid.NewGuid().ToString(), stepResult);
        }