Пример #1
0
        public void BeforeScenario()
        {
            if (CurrentFeatureId != null)
            {
                var request = new StartTestItemRequest
                {
                    LaunchId  = Bridge.Context.LaunchId,
                    Name      = ScenarioContext.Current.ScenarioInfo.Title,
                    StartTime = DateTime.UtcNow,
                    Type      = TestItemType.Test,
                    Tags      = new List <string>(ScenarioContext.Current.ScenarioInfo.Tags)
                };

                var eventArg = new TestItemStartedEventArgs(Bridge.Service, request);
                if (BeforeScenarioStarted != null)
                {
                    BeforeScenarioStarted(this, eventArg);
                }
                if (!eventArg.Canceled)
                {
                    CurrentScenarioId = Bridge.Service.StartTestItem(CurrentFeatureId, request).Id;
                    if (AfterScenarioStarted != null)
                    {
                        AfterScenarioStarted(this,
                                             new TestItemStartedEventArgs(Bridge.Service, request, CurrentScenarioId));
                    }
                }
            }
        }
        public void BeforeScenario()
        {
            var currentFeature = ReportPortalAddin.GetFeatureTestReporter(this.FeatureContext);

            if (currentFeature != null)
            {
                var request = new StartTestItemRequest
                {
                    Name      = this.ScenarioContext.ScenarioInfo.Title,
                    StartTime = DateTime.UtcNow,
                    Type      = TestItemType.Step,
                    Tags      = new List <string>(this.ScenarioContext.ScenarioInfo.Tags)
                };

                var eventArg = new TestItemStartedEventArgs(Bridge.Service, request);
                ReportPortalAddin.OnBeforeScenarioStarted(this, eventArg);

                if (!eventArg.Canceled)
                {
                    var currentScenario = currentFeature.StartNewTestNode(request);
                    ReportPortalAddin.SetScenarioTestReporter(this.ScenarioContext, currentScenario);

                    ReportPortalAddin.OnAfterScenarioStarted(this, new TestItemStartedEventArgs(Bridge.Service, request, currentFeature));
                }
            }
        }
        public void TestStarted(TestName testName)
        {
            if (Bridge.Context.LaunchId != null)
            {
                // get parent suite id from stack
                string parentSuiteId = (_suiteIds.Count > 0) ? _suiteIds.Peek() : null;

                var requestNewTest = new StartTestItemRequest
                {
                    LaunchId  = Bridge.Context.LaunchId,
                    Name      = testName.Name,
                    StartTime = DateTime.UtcNow,
                    Type      = TestItemType.Step
                };

                var eventArg = new TestItemStartedEventArgs(Bridge.Service, requestNewTest);
                if (BeforeTestStarted != null)
                {
                    BeforeTestStarted(this, eventArg);
                }
                if (!eventArg.Canceled)
                {
                    _testId = Bridge.Service.StartTestItem(parentSuiteId, requestNewTest).Id;
                    Bridge.Context.TestId = _testId;
                    if (AfterTestStarted != null)
                    {
                        AfterTestStarted(this, new TestItemStartedEventArgs(Bridge.Service, requestNewTest, _testId));
                    }
                }
            }
        }
Пример #4
0
 private static void ReportPortalAddin_BeforeScenarioStarted(object sender, TestItemStartedEventArgs e)
 {
     // Adding scenario tag on runtime
     e.StartTestItemRequest.Attributes.Add(new ItemAttribute {
         Value = "runtime_scenario_tag"
     });
 }
Пример #5
0
        public void BeforeScenario()
        {
            if (CurrentFeature != null)
            {
                CurrentScenarioDescription = string.Empty;

                Status = Status.Passed;
                var request = new StartTestItemRequest
                {
                    Name        = ScenarioContext.Current.ScenarioInfo.Title,
                    StartTime   = DateTime.UtcNow,
                    Type        = TestItemType.Step,
                    Description = CurrentScenarioDescription,
                    Tags        = new List <string>(ScenarioContext.Current.ScenarioInfo.Tags)
                };

                var eventArg = new TestItemStartedEventArgs(Bridge.Service, request);
                if (BeforeScenarioStarted != null)
                {
                    BeforeScenarioStarted(this, eventArg);
                }
                if (!eventArg.Canceled)
                {
                    CurrentScenario = CurrentFeature.StartNewTestNode(request);

                    if (AfterScenarioStarted != null)
                    {
                        AfterScenarioStarted(this,
                                             new TestItemStartedEventArgs(Bridge.Service, request, CurrentScenario));
                    }
                }
            }
        }
Пример #6
0
        public static void BeforeFeature()
        {
            if (Bridge.Context.LaunchReporter != null)
            {
                var request = new StartTestItemRequest
                {
                    Name        = FeatureContext.Current.FeatureInfo.Title,
                    Description = FeatureContext.Current.FeatureInfo.Description,
                    StartTime   = DateTime.UtcNow,
                    Type        = TestItemType.Suite,
                    Tags        = new List <string>(FeatureContext.Current.FeatureInfo.Tags)
                };

                var eventArg = new TestItemStartedEventArgs(Bridge.Service, request);
                if (BeforeFeatureStarted != null)
                {
                    BeforeFeatureStarted(null, eventArg);
                }
                if (!eventArg.Canceled)
                {
                    CurrentFeature = Bridge.Context.LaunchReporter.StartNewTestNode(request);
                    if (AfterFeatureStarted != null)
                    {
                        AfterFeatureStarted(null, new TestItemStartedEventArgs(Bridge.Service, request, CurrentFeature));
                    }
                }
            }
        }
        private void StartSuite(XmlDocument xmlDoc)
        {
            try
            {
                var id       = xmlDoc.SelectSingleNode("/*/@id").Value;
                var parentId = xmlDoc.SelectSingleNode("/*/@parentId").Value;
                var name     = xmlDoc.SelectSingleNode("/*/@name").Value;

                var startSuiteRequest = new StartTestItemRequest
                {
                    StartTime = DateTime.UtcNow,
                    Name      = name,
                    Type      = TestItemType.Suite
                };

                var beforeSuiteEventArg = new TestItemStartedEventArgs(Bridge.Service, startSuiteRequest);
                try
                {
                    if (BeforeSuiteStarted != null)
                    {
                        BeforeSuiteStarted(this, beforeSuiteEventArg);
                    }
                }
                catch (Exception exp)
                {
                    Console.WriteLine("Exception was thrown in 'BeforeSuiteStarted' subscriber." + Environment.NewLine + exp);
                }
                if (!beforeSuiteEventArg.Canceled)
                {
                    TestReporter test;
                    if (string.IsNullOrEmpty(parentId) || !_suitesFlow.ContainsKey(parentId))
                    {
                        test = Bridge.Context.LaunchReporter.StartNewTestNode(startSuiteRequest);
                    }
                    else
                    {
                        test = _suitesFlow[parentId].StartNewTestNode(startSuiteRequest);
                    }

                    _suitesFlow[id] = test;

                    try
                    {
                        if (AfterSuiteStarted != null)
                        {
                            AfterSuiteStarted(this, new TestItemStartedEventArgs(Bridge.Service, startSuiteRequest, test));
                        }
                    }
                    catch (Exception exp)
                    {
                        Console.WriteLine("Exception was thrown in 'AfterSuiteStarted' subscriber." + Environment.NewLine + exp);
                    }
                }
            }
            catch (Exception exception)
            {
                Console.WriteLine("ReportPortal exception was thrown." + Environment.NewLine + exception);
            }
        }
        public void StartTest(XmlDocument xmlDoc)
        {
            try
            {
                var id       = xmlDoc.SelectSingleNode("/*/@id").Value;
                var parentId = xmlDoc.SelectSingleNode("/*/@parentId").Value;
                var name     = xmlDoc.SelectSingleNode("/*/@name").Value;
                var fullname = xmlDoc.SelectSingleNode("/*/@fullname").Value;

                var startTestRequest = new StartTestItemRequest
                {
                    StartTime = DateTime.UtcNow,
                    Name      = name,
                    Type      = TestItemType.Step
                };

                var beforeTestEventArg = new TestItemStartedEventArgs(Bridge.Service, startTestRequest);
                try
                {
                    if (BeforeTestStarted != null)
                    {
                        BeforeTestStarted(this, beforeTestEventArg);
                    }
                }
                catch (Exception exp)
                {
                    Console.WriteLine("Exception was thrown in 'BeforeTestStarted' subscriber." + Environment.NewLine +
                                      exp);
                }
                if (!beforeTestEventArg.Canceled)
                {
                    var test = _suitesFlow[parentId].StartNewTestNode(startTestRequest);

                    _testFlowIds[id] = test;

                    _testFlowNames[fullname] = test;

                    try
                    {
                        if (AfterTestStarted != null)
                        {
                            AfterTestStarted(this, new TestItemStartedEventArgs(Bridge.Service, startTestRequest, test));
                        }
                    }
                    catch (Exception exp)
                    {
                        Console.WriteLine("Exception was thrown in 'AfterTestStarted' subscriber." + Environment.NewLine +
                                          exp);
                    }
                }
            }
            catch (Exception exception)
            {
                Console.WriteLine("ReportPortal exception was thrown." + Environment.NewLine + exception);
            }
        }
 internal static void OnAfterScenarioStarted(object sender, TestItemStartedEventArgs eventArg)
 {
     try
     {
         AfterScenarioStarted?.Invoke(sender, eventArg);
     }
     catch (Exception exp)
     {
         Logger.Error($"Exception occured in {nameof(OnAfterScenarioStarted)} event handler: {exp}");
     }
 }
Пример #10
0
        public void StartTest(XmlDocument xmlDoc)
        {
            try
            {
                var id       = xmlDoc.SelectSingleNode("/*/@id").Value;
                var parentId = xmlDoc.SelectSingleNode("/*/@parentId").Value;
                var name     = xmlDoc.SelectSingleNode("/*/@name").Value;
                var fullname = xmlDoc.SelectSingleNode("/*/@fullname").Value;

                var startTime = DateTime.UtcNow;

                var startTestRequest = new StartTestItemRequest
                {
                    StartTime = startTime,
                    Name      = name,
                    Type      = TestItemType.Step
                };

                var beforeTestEventArg = new TestItemStartedEventArgs(Bridge.Service, startTestRequest, null, xmlDoc.OuterXml);
                try
                {
                    BeforeTestStarted?.Invoke(this, beforeTestEventArg);
                }
                catch (Exception exp)
                {
                    Console.WriteLine("Exception was thrown in 'BeforeTestStarted' subscriber." + Environment.NewLine +
                                      exp);
                }
                if (!beforeTestEventArg.Canceled)
                {
                    var testReporter = _flowItems[parentId].TestReporter.StartChildTestReporter(startTestRequest);

                    _flowItems[id] = new FlowItemInfo(id, parentId, FlowItemInfo.FlowType.Test, fullname, testReporter, startTime);

                    try
                    {
                        AfterTestStarted?.Invoke(this, new TestItemStartedEventArgs(Bridge.Service, startTestRequest, testReporter, xmlDoc.OuterXml));
                    }
                    catch (Exception exp)
                    {
                        Console.WriteLine("Exception was thrown in 'AfterTestStarted' subscriber." + Environment.NewLine +
                                          exp);
                    }
                }
            }
            catch (Exception exception)
            {
                Console.WriteLine("ReportPortal exception was thrown." + Environment.NewLine + exception);
            }
        }
Пример #11
0
        public void TraceStep(StepInstance stepInstance, bool showAdditionalArguments)
        {
            if (CurrentScenarioId != null)
            {
                var description = stepInstance.MultilineTextArgument;
                if (stepInstance.TableArgument != null)
                {
                    description = string.Empty;
                    foreach (var header in stepInstance.TableArgument.Header)
                    {
                        description += "| " + header + "&#9;";
                    }
                    description += "|\n";
                    foreach (var row in stepInstance.TableArgument.Rows)
                    {
                        foreach (var value in row.Values)
                        {
                            description += "| " + value + "&#9;";
                        }
                        description += "|\n";
                    }
                }
                var request = new StartTestItemRequest
                {
                    LaunchId    = Bridge.Context.LaunchId,
                    Name        = stepInstance.Keyword + " " + stepInstance.Text,
                    Description = description,
                    StartTime   = DateTime.UtcNow,
                    Type        = TestItemType.Step
                };

                var eventArg = new TestItemStartedEventArgs(Bridge.Service, request);
                if (BeforeStepStarted != null)
                {
                    BeforeStepStarted(this, eventArg);
                }
                if (!eventArg.Canceled)
                {
                    CurrentStepId         = Bridge.Service.StartTestItem(CurrentScenarioId, request).Id;
                    Bridge.Context.TestId = CurrentStepId;
                    if (AfterStepStarted != null)
                    {
                        AfterStepStarted(this, new TestItemStartedEventArgs(Bridge.Service, request, CurrentStepId));
                    }
                }
            }
        }
Пример #12
0
        public static void BeforeFeature(FeatureContext featureContext)
        {
            try
            {
                if (_launchReporter != null)
                {
                    ContextAwareLogHandler.ActiveFeatureContext = featureContext;

                    lock (LockHelper.GetLock(FeatureInfoEqualityComparer.GetFeatureInfoHashCode(featureContext.FeatureInfo)))
                    {
                        var currentFeature = ReportPortalAddin.GetFeatureTestReporter(featureContext);

                        if (currentFeature == null || currentFeature.FinishTask != null)
                        {
                            var request = new StartTestItemRequest
                            {
                                Name        = featureContext.FeatureInfo.Title,
                                Description = featureContext.FeatureInfo.Description,
                                StartTime   = DateTime.UtcNow,
                                Type        = TestItemType.Suite,
                                Attributes  = featureContext.FeatureInfo.Tags?.Select(t => new ItemAttributeConverter().ConvertFrom(t, (opts) => opts.UndefinedKey = "Tag")).ToList()
                            };

                            var eventArg = new TestItemStartedEventArgs(_service, request, null, featureContext, null);
                            ReportPortalAddin.OnBeforeFeatureStarted(null, eventArg);

                            if (!eventArg.Canceled)
                            {
                                currentFeature = _launchReporter.StartChildTestReporter(request);
                                ReportPortalAddin.SetFeatureTestReporter(featureContext, currentFeature);

                                ReportPortalAddin.OnAfterFeatureStarted(null, new TestItemStartedEventArgs(_service, request, currentFeature, featureContext, null));
                            }
                        }
                        else
                        {
                            ReportPortalAddin.IncrementFeatureThreadCount(featureContext);
                        }
                    }
                }
            }
            catch (Exception exp)
            {
                _traceLogger.Error(exp.ToString());
            }
        }
        public void SuiteStarted(TestName testName)
        {
            // skip the first suite
            if (_suiteIds == null)
            {
                _suiteIds = new Stack <string>();
                return;
            }

            // get parent suite id from stack
            var parentSuiteId = (_suiteIds.Count > 0) ? _suiteIds.Peek() : null;

            var requestNewSuite = new StartTestItemRequest
            {
                LaunchId  = Bridge.Context.LaunchId,
                Name      = testName.Name,
                StartTime = DateTime.UtcNow,
                Type      = TestItemType.Suite
            };

            var beforeSuiteEventArg = new TestItemStartedEventArgs(Bridge.Service, requestNewSuite);

            if (BeforeSuiteStarted != null)
            {
                BeforeSuiteStarted(this, beforeSuiteEventArg);
            }
            if (!beforeSuiteEventArg.Canceled)
            {
                if (parentSuiteId != null)
                {
                    _suiteIds.Push(Bridge.Service.StartTestItem(parentSuiteId, requestNewSuite).Id);
                }
                else
                {
                    _suiteIds.Push(Bridge.Service.StartTestItem(requestNewSuite).Id);
                }

                if (AfterSuiteStarted != null)
                {
                    AfterSuiteStarted(this, new TestItemStartedEventArgs(Bridge.Service, requestNewSuite, _suiteIds.Peek()));
                }
            }
        }
        public static void BeforeFeature(FeatureContext featureContext)
        {
            if (Bridge.Context.LaunchReporter != null)
            {
                lock (LockHelper.GetLock(FeatureInfoEqualityComparer.GetFeatureInfoHashCode(featureContext.FeatureInfo)))
                {
                    var currentFeature = ReportPortalAddin.GetFeatureTestReporter(featureContext);

                    if (currentFeature == null || currentFeature.FinishTask != null)
                    {
                        var request = new StartTestItemRequest
                        {
                            Name        = featureContext.FeatureInfo.Title,
                            Description = featureContext.FeatureInfo.Description,
                            StartTime   = DateTime.UtcNow,
                            Type        = TestItemType.Suite,
                            Tags        = new List <string>(featureContext.FeatureInfo.Tags)
                        };

                        var eventArg = new TestItemStartedEventArgs(Bridge.Service, request);
                        ReportPortalAddin.OnBeforeFeatureStarted(null, eventArg);

                        if (!eventArg.Canceled)
                        {
                            currentFeature = Bridge.Context.LaunchReporter.StartNewTestNode(request);
                            ReportPortalAddin.SetFeatureTestReporter(featureContext, currentFeature);

                            ReportPortalAddin.OnAfterFeatureStarted(null, new TestItemStartedEventArgs(Bridge.Service, request, currentFeature));
                        }
                    }
                    else
                    {
                        ReportPortalAddin.IncrementFeatureThreadCount(featureContext);
                    }
                }
            }
        }
Пример #15
0
 internal static void OnBeforeFeatureStarted(object sender, TestItemStartedEventArgs eventArg)
 {
     BeforeFeatureStarted?.Invoke(sender, eventArg);
 }
Пример #16
0
        public void BeforeScenario()
        {
            try
            {
                ContextAwareLogHandler.ActiveScenarioContext = this.ScenarioContext;

                var currentFeature = ReportPortalAddin.GetFeatureTestReporter(this.FeatureContext);

                if (currentFeature != null)
                {
                    var request = new StartTestItemRequest
                    {
                        Name        = this.ScenarioContext.ScenarioInfo.Title,
                        Description = this.ScenarioContext.ScenarioInfo.Description,
                        StartTime   = DateTime.UtcNow,
                        Type        = TestItemType.Step,
                        Attributes  = this.ScenarioContext.ScenarioInfo.Tags?.Select(t => new ItemAttributeConverter().ConvertFrom(t, (opts) => opts.UndefinedKey = "Tag")).ToList(),
                    };

                    // fetch scenario parameters (from Examples block)
                    var arguments = this.ScenarioContext.ScenarioInfo.Arguments;
                    if (arguments != null && arguments.Count > 0)
                    {
                        request.Parameters = new List <KeyValuePair <string, string> >();

                        foreach (DictionaryEntry argument in arguments)
                        {
                            request.Parameters.Add(new KeyValuePair <string, string>
                                                   (
                                                       argument.Key.ToString(),
                                                       argument.Value.ToString()
                                                   ));
                        }

                        // append scenario outline parameters to description
                        var parametersInfo = new StringBuilder();
                        parametersInfo.Append("|");
                        foreach (var p in request.Parameters)
                        {
                            parametersInfo.Append(p.Key);

                            parametersInfo.Append("|");
                        }

                        parametersInfo.AppendLine();
                        parametersInfo.Append("|");
                        foreach (var p in request.Parameters)
                        {
                            parametersInfo.Append("---");
                            parametersInfo.Append("|");
                        }

                        parametersInfo.AppendLine();
                        parametersInfo.Append("|");
                        foreach (var p in request.Parameters)
                        {
                            parametersInfo.Append("**");
                            parametersInfo.Append(p.Value);
                            parametersInfo.Append("**");

                            parametersInfo.Append("|");
                        }

                        if (string.IsNullOrEmpty(request.Description))
                        {
                            request.Description = parametersInfo.ToString();
                        }
                        else
                        {
                            request.Description = parametersInfo.ToString() + Environment.NewLine + Environment.NewLine + request.Description;
                        }
                    }

                    var eventArg = new TestItemStartedEventArgs(_service, request, currentFeature, this.FeatureContext, this.ScenarioContext);
                    ReportPortalAddin.OnBeforeScenarioStarted(this, eventArg);

                    if (!eventArg.Canceled)
                    {
                        var currentScenario = currentFeature.StartChildTestReporter(request);
                        ReportPortalAddin.SetScenarioTestReporter(this.ScenarioContext, currentScenario);

                        ReportPortalAddin.OnAfterScenarioStarted(this, new TestItemStartedEventArgs(_service, request, currentFeature, this.FeatureContext, this.ScenarioContext));
                    }
                }
            }
            catch (Exception exp)
            {
                _traceLogger.Error(exp.ToString());
            }
        }
        private void StartSuite(XmlDocument xmlDoc)
        {
            try
            {
                var type = xmlDoc.SelectSingleNode("/*/@type").Value;

                var id       = xmlDoc.SelectSingleNode("/*/@id").Value;
                var parentId = xmlDoc.SelectSingleNode("/*/@parentId").Value;
                var name     = xmlDoc.SelectSingleNode("/*/@name").Value;
                var fullname = xmlDoc.SelectSingleNode("/*/@fullname").Value;

                var startTime = DateTime.UtcNow;

                var startSuiteRequest = new StartTestItemRequest
                {
                    StartTime = startTime,
                    Name      = name,
                    Type      = TestItemType.Suite
                };

                var beforeSuiteEventArg = new TestItemStartedEventArgs(Bridge.Service, startSuiteRequest, null, xmlDoc.OuterXml);

                var rootNamespaces = Config.GetValues <string>("rootNamespaces", null);
                if (rootNamespaces != null && rootNamespaces.Any(n => n == name))
                {
                    beforeSuiteEventArg.Canceled = true;
                }

                if (!beforeSuiteEventArg.Canceled)
                {
                    try
                    {
                        BeforeSuiteStarted?.Invoke(this, beforeSuiteEventArg);
                    }
                    catch (Exception exp)
                    {
                        Console.WriteLine("Exception was thrown in 'BeforeSuiteStarted' subscriber." + Environment.NewLine + exp);
                    }
                }

                if (!beforeSuiteEventArg.Canceled)
                {
                    ITestReporter suiteReporter;

                    if (string.IsNullOrEmpty(parentId) || !_flowItems.ContainsKey(parentId))
                    {
                        suiteReporter = Bridge.Context.LaunchReporter.StartChildTestReporter(startSuiteRequest);
                    }
                    else
                    {
                        var parentFlowItem = FindReportedParentFlowItem(parentId);
                        if (parentFlowItem == null)
                        {
                            suiteReporter = Bridge.Context.LaunchReporter.StartChildTestReporter(startSuiteRequest);
                        }
                        else
                        {
                            suiteReporter = parentFlowItem.TestReporter.StartChildTestReporter(startSuiteRequest);
                        }
                    }

                    _flowItems[id] = new FlowItemInfo(id, parentId, FlowItemInfo.FlowType.Suite, name, suiteReporter, startTime);

                    try
                    {
                        AfterSuiteStarted?.Invoke(this, new TestItemStartedEventArgs(Bridge.Service, startSuiteRequest, suiteReporter, xmlDoc.OuterXml));
                    }
                    catch (Exception exp)
                    {
                        Console.WriteLine("Exception was thrown in 'AfterSuiteStarted' subscriber." + Environment.NewLine + exp);
                    }
                }
                else
                {
                    _flowItems[id] = new FlowItemInfo(id, parentId, FlowItemInfo.FlowType.Suite, name, null, startTime);
                }
            }
            catch (Exception exception)
            {
                Console.WriteLine("ReportPortal exception was thrown." + Environment.NewLine + exception);
            }
        }
Пример #18
0
 private static void ReportPortalAddin_BeforeFeatureStarted(object sender, TestItemStartedEventArgs e)
 {
     // Adding feature tag on runtime
     e.TestItem.Tags.Add("runtime_feature_tag");
 }
Пример #19
0
 private static void ReportPortalAddin_BeforeScenarioStarted(object sender, TestItemStartedEventArgs e)
 {
     // Adding scenario tag on runtime
     e.TestItem.Tags.Add("runtime_scenario_tag");
 }
Пример #20
0
 internal static void OnAfterScenarioStarted(object sender, TestItemStartedEventArgs eventArg)
 {
     AfterScenarioStarted?.Invoke(sender, eventArg);
 }