CodedUI中的System.WIndows.Forms.Ribbon控件 [英] System.WIndows.Forms.Ribbon controls in CodedUI

查看:275
本文介绍了CodedUI中的System.WIndows.Forms.Ribbon控件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在开发C#winform应用程序。我的表单中有功能区,其中包含几个选项卡和几个功能区按钮。我正在使用编码的UI进行测试。我面临的问题是我无法使用编码的ui找到功能区按钮,每当我将鼠标悬停在功能区的任何控件上(例如功能区按钮)时,它只能检测功能区,而不能检测到该控件。谁能建议功能区控件是否支持编码UI进行测试?如果是,那我该怎么办?

I am developing C# winform application. I have Ribbon in my form which contains several tabs and several ribbonbuttons. I am using Coded UI for testing. The problem i am facing is i am unable to find the ribbonbuttons using coded ui, whenever i hover on any control of ribbon (say ribbonbutton), it detects only ribbon but not that control. Can any one suggest whether ribbon controls supports Coded UI for testing? If yes, then how can i do so?

推荐答案

假设Pal Bognar的答案是正确的,我建议您创建自己的可重用的输入这种情况。这是一个例子。使它变得更通用并在每个实例中提供带有实际按钮和菜单选项卡的子类将很简单。

Assuming that Pal Bognar's answer is correct, I would recommend creating your own reusable type for this situation. Here is an example. It would be simple to make this more generic and have sub-classes with the actual buttons and menu tabs available in each instance.

public class WinRibbon : WinControl
{
    protected WinMenuBar RibbonBarInside {
        get
        {
            var ribbonBarInside = new WinMenuBar(this.RibbonBar);
            ribbonBarInside.SearchConfigurations.Add(WinControl.PropertyNames.Name, "radRibbonBar");
            return ribbonBarInside;
        }
    }

    public IEnumerable<WinTabPage> Tabs => new WinTabPage(this.RibbonBarInside).FindMatchingControls().OfType<WinTabPage>();

    public WinControl FileTab => this.Tabs.FirstOrDefault(t => t.AccessibleDescription.Trim() == "File");

    public IEnumerable<WinButton> Buttons => new WinButton(this.RibbonBarInside).FindMatchingControls().OfType<WinButton>();

    public WinButton OpenButton => this.Buttons.FirstOrDefault(t => t.AccessibleDescription.Trim() == "Open");

    public WinRibbon(UITestControl parent = null) : base(parent)
    {
        this.SearchProperties.Add(WinControl.PropertyNames.ControlName, "radRibbonBar");
    }

    public void ClickOpenButton()
    {
        var openButton = this.OpenButton; // to prevent creating a new one each time
        Mouse.Location = new Point(openButton.Left + openButton.Width / 2, openButton.Top + openButton.Height / 2);
        Mouse.Click();
    }
}

这篇关于CodedUI中的System.WIndows.Forms.Ribbon控件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆