Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/visual-studio/7.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Visual studio 无法使用SpecFlow解析Bodi接口_Visual Studio_Specflow_Teststack - Fatal编程技术网

Visual studio 无法使用SpecFlow解析Bodi接口

Visual studio 无法使用SpecFlow解析Bodi接口,visual-studio,specflow,teststack,Visual Studio,Specflow,Teststack,我搜索了所有地方,找到了多篇关于SpecFlow中Bodi异常的帖子,但是没有一篇是关于TestStack.White的,也没有一篇回复在我的情况下有效 我正在使用以下工具: SpecFlow 2.4.0 TestStack.White0.13.3 MsTest1.4.0 Visual Studio 201715.9.4 我试图使用现有接口将自动化元素转换为TestStack.White UIItem UIItemFactory itemFactory { get; set; }

我搜索了所有地方,找到了多篇关于SpecFlow中Bodi异常的帖子,但是没有一篇是关于TestStack.White的,也没有一篇回复在我的情况下有效

我正在使用以下工具:

SpecFlow 2.4.0 TestStack.White0.13.3 MsTest1.4.0 Visual Studio 201715.9.4 我试图使用现有接口将自动化元素转换为TestStack.White UIItem

    UIItemFactory itemFactory { get; set; }
    ActionListener actionListener { get; set; }
    public UIItemFactoryHelper(UIItemFactory itemFactory, ActionListener actionListener)
    {
        this.itemFactory = itemFactory;
        this.actionListener = actionListener;
    }

    public virtual IUIItem CreateIUIItemFromAutoElement(AutomationElement automationElement)
    {
        var item = itemFactory.Create(automationElement, actionListener);

        return item;
    }
然后我就这样用

    private DataGrid GetGrid(ParameterizedString Id, Window window = null)
    {
        var form = ScenarioContext.Current["activeForm"];
        var tab = ScenarioContext.Current["activeTab"];
        var parent = GetElementParent(form.ToString(), Id.parentLevel, tab.ToString());

        if (window == null)
        {
            window = WindowHelper.GetWindow();
        }
        var parentUIItem = uiItemFactoryHelper.CreateIUIItemFromAutoElement(parent);
        var element = parentUIItem.Get<DataGrid>(SearchCriteria.ByText("DataGrid"));
        return element;
    }
当我运行测试时,我得到以下错误

消息:测试方法SmokeTests.SmokeTestSpec.SmokeTestsFeature.EditsSaved 引发异常: BoDi.ObjectContainerException:无法解析接口:TestStack.White.Factory.UIItemFactory

我已经尝试在ScenarioHooks中注册容器,并在Before场景挂钩中注册接口。当我这样做的时候,我得到了完全相同的东西

class ScenarioHooks
{
    IObjectContainer objectContainer;
    public XmlHelper xmlHelper { get; set; }
    public ScenarioHooks(XmlHelper xmlHelper, IObjectContainer objectContainer)
    {
        this.xmlHelper = xmlHelper;
        this.objectContainer = objectContainer;
    }
    [BeforeScenario]
    protected void RegisterInterfaces()
    {
        objectContainer.ResolveAll<UIItemFactory>();
    }
}
我一直在做SpecFlow很长一段时间,但我总是被这个容器注入的东西卡住。我已经阅读了文档并搜索了各个网站,但我无法让它工作


欢迎提出任何建议。我在这里完全被难住了。

BoDi和其他DI容器一样,只能在注册接口时解析接口

要获取UIItemFactory接口的实例,必须注册一个实现


在RegisterInterfaces方法中,您不是在注册接口,而是在解析接口。您必须将objectContainer.ResolveAll行更改为objectContainer.RegisterTypeAs

以防有人在这里查看TestStack。将自动化元素转换为UIItem的白色问题如上所述过于复杂

事实证明,您可以通过执行以下操作隐式地实现这一点

    public virtual IUIItem CreateIUIItemFromAutoElement(AutomationElement automationElement)
    {
        var element = new UIItem(automationElement, new NullActionListener());
        return element;
    }

您可以拥有一个空操作侦听器,只需创建传入AutomationElement的新UIItem。这将隐式调用UIItemFactory.Create方法,无需为显式调用注册接口。

非常感谢。我还在学习这个容器的东西。谢谢你的回答。