2012-04-12 38 views
0

我想向我的UIMap.cs(而不是UIMap.Designer.cs)添加一個手寫編碼控件。將編碼控件添加到UIMap(編碼UI測試)

例如,當我記錄: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中搜索它?哪種方法最好?

+0

不知道我明白你想要做什麼。爲什麼要在代碼中搜索UIMap中的文本框?還是你想在你的應用程序中搜索具有給定值的文本框? – stoj 2012-04-12 14:18:35

回答

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只是等待很短的時間展示亮點。