0

我想在我的 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. 有没有办法TextBoxUIMap.cs自己的编码中搜索或在我的中搜索TestMethod?哪个是最好的方法?

4

1 回答 1

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稍等片刻即可显示亮点。

于 2012-04-13T08:49:00.900 回答