c# - 原始类型或结构无法解析:System.String hook [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);
}
}
解决方案
根据类似的问题,您可能无法通过传递string
参数来解决此问题。您可能必须使用properties
或custom type
推荐阅读
- javascript - TypeError:是事件处理程序“更改”。工作正常吗?
- css - CSS 绘制顺序属性的 SVG 问题
- python - 将数据描述符传递给函数
- python - 允许多个客户端监听 ThreadedHTTPServer python 3
- ios - 如何在 Swift 4 中将 2 个布尔值组合在一起
- javascript - 如何为foreach循环中的每个数据打开一个带有按钮的模式?
- django - 如何在模板Django中增加变量
- java - Spring - FlatFileItemReader 与 FixedLengthTokenizer 的使用
- c++ - 对内部类的静态实例的未定义引用
- c# - 抽象类构造函数