编码的UI测试生成器检查器

时间:2018-06-18 11:52:09

标签: vb.net wpf-controls coded-ui-tests

所以我想实现编码的Ui测试,因为我们仍在我们公司手动测试。 不知何故,没有任何作用,更具体地说: 所以有一个带有4个文本框的wpf UserControl。但是在Test Builder中它只显示了4个Textbox中的2个。检查员也没有显示我所定义的任何属性。

  1. 如何使所有ui元素可见(或至少在xaml中定义x:Name的那些元素)?

  2. 如何使自定义属性可见(例如:Public Property myProp as String)?

  3. enter image description here

2 个答案:

答案 0 :(得分:0)

也许您应该尝试检查“ UiItemCustom”并检查是否有4个子项。

var _UiItemCustom = new WpfCustom(UiMainWindowWindow); //the father of this element is your Main Window element

_UiItemCustom.SearchProperties.Add(WpfCustom.PropertyNames.ControlType, "Custom");
_UiItemCustom.SearchProperties.Add(WpfCustom.PropertyNames.Name, "**THE CUSTOM NAME HERE**");

if(UiItemCustom.GetChildren().Count == 4){
   //if the custom has 4 children the it has 4 textboxes (Maybe)
}

//if you want to hold the 4 textboxes in your hand then do the following.
var _textBox1 = new WpfEdit(_UiItemCustom.GetChildren()[0]); //TextBox1
var _textBox1 = new WpfEdit(_UiItemCustom.GetChildren()[1]); //TextBox2
var _textBox1 = new WpfEdit(_UiItemCustom.GetChildren()[2]); //TextBox3
var _textBox1 = new WpfEdit(_UiItemCustom.GetChildren()[3]); //TextBox4

如果要使用值填充文本框之一,请执行以下操作:

_textBox1.Text = "Hello World;

答案 1 :(得分:0)

示例为C#,但您可以轻松地将其转换为vb.net:http://converter.telerik.com/

  1. 您可以以递归的方式遍历ui元素以获取所有子项:

    /// <summary>
    /// Returns a complete tree of controls and child controls in a recursive way.
    /// </summary>
    /// <param name="parentControl"></param>
    /// <returns></returns>
    public ParentControl GetChildControls(UITestControl parentControl)
    {
        ParentControl parent = new ParentControl();
    
        if (parentControl != null)
        {
            List<ParentControl> children = new List<ParentControl>();
    
            foreach (UITestControl childControl in parentControl.GetChildren())
            {
                children.Add(GetChildControls(childControl));
            }
    
            parent.Children = new KeyValuePair<UITestControl, List<ParentControl>>(parentControl, children);
        }
    
        return parent;
    }
    

父类:

    public class ParentControl
    {
        internal KeyValuePair<UITestControl, List<ParentControl>> Children { get; set; }
        internal string Value
        {
            get
            {
                return Children.Key.Name;
            }
        }
    }

2。参见https://msdn.microsoft.com/en-us/library/hh552522.aspx