1

Visual Studio2010でUIコード化されたUIテストがあります。次のようなコードを記述したいと思います。

  1. ボタン、グリッド、ラベルであるウィンドウと子ウィンドウのすべてのコントロールを検出します
  2. コード内のコントロールの名前であるidを使用してuimapを記述します。

それを始めるために、私は次のように書いた:

public void CodedUITestMethod1()
{    
   string uiTestFileName = @"D:\dev11\ConsoleApplication1\TestProject1\UIMap.uitest";

   UITest uiTest = UITest.Create(uiTestFileName);

   Microsoft.VisualStudio.TestTools.UITest.Common.UIMap.UIMap newMap = new Microsoft.VisualStudio.TestTools.UITest.Common.UIMap.UIMap(); 
   newMap.Id = "UIMap"; 
   uiTest.Maps.Add(newMap);

   GetAllChildren(BrowserWindow.Launch(new Uri("http://bing.com")), uiTest.Maps[0];);
   uiTest.Save(uiTestFileName);    
}

private void GetAllChildren(UITestControl uiTestControl, Microsoft.VisualStudio.TestTools.UITest.Common.UIMap.UIMap map)
{
   foreach (UITestControl child in uiTestControl.GetChildren())
   {
       map.AddUIObject((IUITechnologyElement)child.GetProperty(UITestControl.PropertyNames.UITechnologyElement));

       GetAllChildren(child, map);    
    }    
}

しかし、それは再帰ループに挿入され、それを終了しません。

誰か助けてもらえますか?

4

3 に答える 3

1

無限再帰の可能性を回避するには、次のコードを追加する必要があると思います。

private void GetAllChildren(UITestControl uiTestControl, Microsoft.VisualStudio.TestTools.UITest.Common.UIMap.UIMap map)
{
  foreach (UITestControl child in uiTestControl.GetChildren())
  {
      IUITechnologyElement tElem=(IUITechnologyElement)child.GetProperty(UITestControl.PropertyNames.UITechnologyElement);
      if (!map.Contains(tElem))
      {
          map.AddUIObject(tElem);
          GetAllChildren(child, map);    
      }
  }    
}

このようにして、同じオブジェクトを何度も検討することを避け、考えられる視覚的なツリーサイクルを避けます。

于 2011-06-08T07:50:11.433 に答える
0

foreachループでmap.AddUIObjectとGetAllChildrenを呼び出す前に、オブジェクトがマップコレクションにまだ存在していないことを確認してください。

于 2011-06-01T12:15:23.663 に答える
0

GetAllChildren(child、map)を呼び出す前に、子に子があることを確認してください

if(child.HasChildren){
   GetAllChildren(子、マップ);
}
于 2011-06-02T19:44:02.223 に答える