Примитивные типы или структуры не могут быть разрешены: хук System.String [AfterStep] specflow C#

В моей автоматизации у меня возникают проблемы с запуском автоматических тестов, когда метод, который мне нужен для ввода параметра с помощью хука [AfterStep], отображает ошибку:

Примитивные типы или структуры не могут быть разрешены: System.String BoDi.ObjectContainerException

Но тестируя код, я понял, что когда я удаляю строковый параметр из метода, ошибка перестает возникать, может ли кто-нибудь дать мне решение этой проблемы?

[AfterStep]

        public static void InserirStepsNoRelatorio(string screenshotPath)
        {

            var TipoStep = ScenarioStepContext.Current.StepInfo.StepDefinitionType.ToString();


            PropertyInfo pInfo = typeof(ScenarioContext).GetProperty("ScenarioExecutionStatus", BindingFlags.Instance | BindingFlags.Public);
            MethodInfo getter = pInfo.GetGetMethod(nonPublic: true);
            object TestResult = getter.Invoke(ScenarioContext.Current, null);


            try
            {


                if (ScenarioContext.Current.TestError == null)
                {


                    if (TipoStep == "Given")
                    {

                        //objGeraScreenshot.TiraPrint(objUsaNavegador);
                        scenario.CreateNode<Given>(ScenarioStepContext.Current.StepInfo.Text).AddScreenCaptureFromPath(screenshotPath);
                    }


                    else if (TipoStep == "When")
                    {

                        scenario.CreateNode<When>(ScenarioStepContext.Current.StepInfo.Text).AddScreenCaptureFromPath(screenshotPath);

                    }

                    else if (TipoStep == "Then")
                        scenario.CreateNode<Then>(ScenarioStepContext.Current.StepInfo.Text).AddScreenCaptureFromPath(screenshotPath);
                    else if (TipoStep == "And")
                        scenario.CreateNode<And>(ScenarioStepContext.Current.StepInfo.Text).AddScreenCaptureFromPath(screenshotPath);

                }

                else if (ScenarioContext.Current.TestError != null)
                {
                    if (TipoStep == "Given")
                    {
                        var MensagemErroAtual = ScenarioContext.Current.TestError.Message;

                        scenario.CreateNode<Given>(ScenarioStepContext.Current.StepInfo.Text).Fail(MarkupHelper.CreateLabel(MensagemErroAtual, ExtentColor.Black)).AddScreenCaptureFromPath(screenshotPath);


                    }

                    else if (TipoStep == "When")
                    {
                        var MensagemErroAtual = ScenarioContext.Current.TestError.Message;

                        scenario.CreateNode<When>(ScenarioStepContext.Current.StepInfo.Text).Fail(MarkupHelper.CreateLabel(MensagemErroAtual, ExtentColor.Black)).AddScreenCaptureFromPath(screenshotPath);


                    }

                    else if (TipoStep == "Then")
                    {
                        var MensagemErroAtual = ScenarioContext.Current.TestError.Message;

                        scenario.CreateNode<Then>(ScenarioStepContext.Current.StepInfo.Text).Fail(MarkupHelper.CreateLabel(MensagemErroAtual, ExtentColor.Black)).AddScreenCaptureFromPath(screenshotPath);
                    }

                }



                //else if (ScenarioStepContext.Current.StepInfo.StepDefinitionType. != null)
                //Pending Status
                if (TestResult.ToString() == "StepDefinitionPending")
                {
                    if (TipoStep == "Given")
                        scenario.CreateNode<Given>(ScenarioStepContext.Current.StepInfo.Text).Skip(MarkupHelper.CreateLabel("Step Pendente de Desenvolvimento", ExtentColor.Blue));

                    else if (TipoStep == "When")
                        scenario.CreateNode<When>(ScenarioStepContext.Current.StepInfo.Text).Skip(MarkupHelper.CreateLabel("Step Pendente de Desenvolvimento", ExtentColor.Blue));

                    else if (TipoStep == "Then")
                        scenario.CreateNode<Then>(ScenarioStepContext.Current.StepInfo.Text).Skip(MarkupHelper.CreateLabel("Step Pendente de Desenvolvimento", ExtentColor.Blue));

                }

            }
            catch (Exception e)
            {
                Assert.Fail(e.Message);
            }

        }

person Ruan Menezes    schedule 21.11.2019    source источник


Ответы (1)


В соответствии с похожим вопросом вы не сможете решить это путем передачи параметра string. Возможно, вам придется использовать properties или custom type

person user1207289    schedule 21.11.2019