繁体   English   中英

#SpecFlow# For CreateDynamicInstance() - 错误 - Microsoft.CSharp.RuntimeBinder.RuntimeBinderException:最佳重载方法

[英]#SpecFlow# For CreateDynamicInstance() - error - Microsoft.CSharp.RuntimeBinder.RuntimeBinderException : The best overloaded method

我正在使用 Specflow 3 和 Selenium 页面 Object Model 模式。 下面是代码:

特征文件

When I want to edit the profile 
    | Hats | Shoes |
    | 98   | 99    |

页面类-

public IWebElement TxtHat => _driver.FindElement(By.Id("Hat"));

public IWebElement TxtShoe => _driver.FindElement(By.Id("Shoe"));

public void FillDetails (string hat, string shoe)
{
    TxtHat.SendKeys(hat);
    TxtShoe.SendKeys(shoe);
}

步骤定义 -

[When(@"I want to edit the profile")]
public void WhenIWantToEditTheProfile(Table table)
{
    profile.ClearDetails();
    dynamic var = table.CreateDynamicInstance();
    profile.FillDetails(var.Hats, var.Shoes);
}

错误

消息:Microsoft.CSharp.RuntimeBinder.RuntimeBinderException:“RefreshESS.Pages.UpdateProfilePage.FillDetails(string, string)”的最佳重载方法匹配有一些无效的 arguments

提前感谢您的帮助!

您需要改用“垂直”表:

When I want to edit the profile 
    | Field | Value |
    | Hats  | 98    |
    | Shoes | 99    |

数据表的“水平”布局(列标题应为属性名称)仅在创建对象集或集合时才有效。 由于您需要一个 object,因此您需要一个包含两列的表。 第 1 列是dynamic object 中的键或属性名称,第二列是属性值。

有关将数据表转换为对象的更多信息: https://specflow.org/documentation/SpecFlow-Assist-Helpers/

请注意,文档讨论了将数据表转换为具体类,但同样的基本原理也适用于将数据表转换为dynamic对象。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM