【问题标题】:Add coded control to UIMap (Coded UI Test)将编码控件添加到 UIMap(编码 UI 测试)
【发布时间】:2012-04-12 10:34:57
【问题描述】:

我想在我的 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 中使用这个控件。有没有办法通过自己的编码在UIMap.cs 中搜索TextBox 或在我的TestMethod 中搜索?哪种方式最好?

【问题讨论】:

  • 不确定我是否理解您要执行的操作。为什么要在 UIMap 中搜索代码中的文本框?或者您想在您的应用程序中搜索具有给定值的文本框?

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


【解决方案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 只需稍等片刻即可显示精彩集锦。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2023-03-23
    • 1970-01-01
    • 2015-07-08
    • 2013-02-05
    • 1970-01-01
    • 2014-11-12
    相关资源
    最近更新 更多