Getting null value in PropertyInfo When trying to implement the extent report in specflow

346 views
Skip to first unread message

Swati Gupta

unread,
Jun 7, 2018, 4:40:36 AM6/7/18
to SpecFlow
public void InsertReportingSteps()
        {    
            var stepType = ScenarioStepContext.Current.StepInfo.StepDefinitionType.ToString();
            PropertyInfo pInfo = typeof(ScenarioContext).GetProperty("TestStatus", BindingFlags.Instance | BindingFlags.NonPublic);//Getting Null value in PropertyInfo
            MethodInfo getter = pInfo.GetGetMethod(nonPublic: true);
            object TestResult = getter.Invoke(ScenarioContext.Current, null);
            var status = TestContext.CurrentContext.Result.Outcome.Status;
            var stackTrace = "" + TestContext.CurrentContext.Result.StackTrace + "";
            var errorMessage = TestContext.CurrentContext.Result.Message;            
            if (ScenarioContext.Current.TestError == null)
            {
                if (stepType == "Given")
                    scenario.CreateNode<Given>(ScenarioStepContext.Current.StepInfo.Text);
                else if (stepType == "When")
                    scenario.CreateNode<When>(ScenarioStepContext.Current.StepInfo.Text);
                else if (stepType == "Then")
                    scenario.CreateNode<Then>(ScenarioStepContext.Current.StepInfo.Text);
                else if (stepType == "And")
                    scenario.CreateNode<And>(ScenarioStepContext.Current.StepInfo.Text);
            }
            else if (ScenarioContext.Current.TestError != null)
            {
                if (stepType == "Given")
                {
                    //status = TestContext.CurrentContext.Result.Outcome.Status;
                    //stackTrace = "<pre>" + TestContext.CurrentContext.Result.StackTrace + "</pre>";
                    //errorMessage = TestContext.CurrentContext.Result.Message;
                    scenario.CreateNode<Given>(ScenarioStepContext.Current.StepInfo.Text).Fail(ScenarioContext.Current.TestError.InnerException);
                    
                }                    
                else if (stepType == "When")
                {
                    scenario.CreateNode<When>(ScenarioStepContext.Current.StepInfo.Text).Fail(ScenarioContext.Current.TestError.InnerException);
                }                   
                else if (stepType == "Then")
                {
                    scenario.CreateNode<Then>(ScenarioStepContext.Current.StepInfo.Text).Fail(ScenarioContext.Current.TestError.Message);
                }
                    
            }
            //Pending Status
            if (TestResult.ToString() == "StepDefinitionPending")
            {
                if (stepType == "Given")
                {
                    scenario.CreateNode<Given>(ScenarioStepContext.Current.StepInfo.Text).Skip("Step Definition Pending");
                }                    
                else if (stepType == "When")
                {
                    scenario.CreateNode<When>(ScenarioStepContext.Current.StepInfo.Text).Skip("Step Definition Pending");
                }                    
                else if (stepType == "Then")
                {
                    scenario.CreateNode<Then>(ScenarioStepContext.Current.StepInfo.Text).Skip("Step Definition Pending");
                }
            }

Andreas Willich

unread,
Jun 7, 2018, 4:54:24 AM6/7/18
to spec...@googlegroups.com
That's what you get if you try to access internals via reflection. 
We changed the API and so your code broke. ;-)


We made the property you accessed public and renamed it. So no need more for reflection.

--
You received this message because you are subscribed to the Google Groups "SpecFlow" group.
To unsubscribe from this group and stop receiving emails from it, send an email to specflow+u...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Swati Gupta

unread,
Jun 7, 2018, 5:28:16 AM6/7/18
to SpecFlow
@Andreas Willich So, here what should i need to change I mean how can i fix it

subbu rayudu

unread,
Jun 7, 2018, 5:59:55 AM6/7/18
to SpecFlow
Hi Swathi,

For the lateste version for Specflow you have to use like bellow to get the step method pending status

//Pending Status
         if (ScenarioContext.Current.ScenarioExecutionStatus.ToString() == "StepDefinitionPending")
         {
            if (step_type == "Given")

               scenario.CreateNode<Given>(ScenarioStepContext.Current.StepInfo.Text).Skip("Step Definition Pending");
            else if (step_type == "When")

               scenario.CreateNode<When>(ScenarioStepContext.Current.StepInfo.Text).Skip("Step Definition Pending");
            else if (step_type == "Then")

               scenario.CreateNode<Then>(ScenarioStepContext.Current.StepInfo.Text).Skip("Step Definition Pending");

         }

Thanks,
Subbu.
Reply all
Reply to author
Forward
0 new messages