将编码控件添加到UIMap(编码UI测试)

时间:2012-04-12 10:34:58

标签: unit-testing mstest coded-ui-tests handwriting

我想在我的UIMap.cs(而不是UIMap.Designer.cs)中添加一个手写的编码控件。

例如,当我录制:writing in a texBox时,我在UIMap.Designer.cs中获得以下代码:

public class Recorded_Writing_In_forRecordParams
{
    public string UIForRecordEditText = "forRecord";
}

public class UIMainWindowWindow : WpfWindow
{
    public UIMainWindowWindow()
    {
        this.SearchProperties[WpfWindow.PropertyNames.Name] = "MainWindow";
        this.SearchProperties.Add(new PropertyExpression(WpfWindow.PropertyNames.ClassName, "HwndWrapper", PropertyExpressionOperator.Contains));
        this.WindowTitles.Add("MainWindow");
    }

    public WpfEdit UIForRecordEdit
    {
        get
        {
            if ((this.mUIForRecordEdit == null))
            {
                this.mUIForRecordEdit = new WpfEdit(this);
                this.mUIForRecordEdit.SearchProperties[WpfEdit.PropertyNames.AutomationId] = "forRecord";
                this.mUIForRecordEdit.WindowTitles.Add("MainWindow");
            }

            return this.mUIForRecordEdit;
        }
    }

    private WpfEdit mUIForRecordEdit;
}

我想在CodedUITest中使用此控件。有没有办法通过自己编码搜索TextBox中的UIMap.cs或在TestMethod中搜索它?哪种方式最好?

1 个答案:

答案 0 :(得分:1)

感谢您的回答,但我通过以下方式自行解决了问题:

<强> UIMap.cs

public partial class TestLittleAppUIMap
{
    private MyWindow mMyWindow;
    public MyWindow MMyWindow
    {
        get
        {
            if (this.mMyWindow == null)
            {
                this.mMyWindow = new MyWindow();
            }
            return this.mMyWindow;
        }
    }
}

public class MyWindow : WpfWindow
{ 
    private WpfEdit mWpfEdit;

    public MyWindow()
    {
        this.SearchProperties[WpfWindow.PropertyNames.Name] = "MainWindow";
        this.SearchProperties.Add(new PropertyExpression(WpfWindow.PropertyNames.ClassName, "HwndWrapper", PropertyExpressionOperator.Contains));
        this.WindowTitles.Add("MainWindow");
    }

    public WpfEdit MWpfEdit
    {
        get
        {
            if ((this.mWpfEdit == null))
            {
                this.mWpfEdit = new WpfEdit(this);
                #region Search Criteria
                this.mWpfEdit.SearchProperties[WpfEdit.PropertyNames.AutomationId] = "forOwn";
                this.mWpfEdit.WindowTitles.Add("MainWindow");
                #endregion
            }
            return this.mWpfEdit;
        }
    }

CodedUI测试

[TestMethod]
public void TestLittleAppOwnMap()
{
    this.UIMap.MMyWindow.MWpfEdit.DrawHighlight();
    Playback.Wait(2500);
}

它几乎是设计师类的副本。

要直接在TestMethod中搜索,您可以这样:

[TestMethod]
public void TestLittleAppOwn()
{
    WpfWindow w = new WpfWindow();
    w.SearchProperties[WpfWindow.PropertyNames.Name] = "MainWindow";
    w.SearchProperties.Add(new PropertyExpression(WpfWindow.PropertyNames.ClassName, "HwndWrapper", PropertyExpressionOperator.Contains));
    w.DrawHighlight();

    WpfEdit e = new WpfEdit(w);
    e.SearchProperties[WpfEdit.PropertyNames.AutomationId] = "forOwn";
    e.SetProperty("Text","myText");
    e.DrawHighlight();
    Playback.Wait(2500);
}

Playback.Wait只需等待很短时间即可显示精彩集锦。