2014-10-10 8 views
3

我正在使用UI Automation進行GUI測試。如何指定包含在UI自動化PropertyCondition中

我的窗口標題包含由文件名附加的應用程序名稱。

所以,我想在我的Name PropertyCondition中指定Contains。

我檢查了過載,但它與忽略名稱值的情況有關。

任何人都可以讓我知道如何指定包含在我的名字PropertyCondition?

問候,

kvk938

+0

誰能回答這個問題題? – kvk938 2014-10-13 05:03:39

回答

2

據我所知,他們是沒有辦法的事情,同時使用name屬性,但你可以做這樣的事情一個包含。

/// <summary> 
    /// Returns the first automation element that is a child of the element you passed in and contains the string you passed in. 
    /// </summary> 
    public AutomationElement GetElementByName(AutomationElement aeElement, string sSearchTerm) 
    { 
     AutomationElement aeFirstChild = TreeWalker.RawViewWalker.GetFirstChild(aeElement); 

     AutomationElement aeSibling = null; 
     while ((aeSibling = TreeWalker.RawViewWalker.GetNextSibling(aeFirstChild)) != null) 
     { 
      if (aeSibling.Current.Name.Contains(sSearchTerm)) 
      { 
       return aeSibling; 
      } 
     } 
     return aeSibling; 
    } 

那麼你會做到這一點得到了桌面,並使用字符串傳遞桌面到上述方法

/// <summary> 
    /// Finds the automation element for the desktop. 
    /// </summary> 
    /// <returns>Returns the automation element for the desktop.</returns> 
    public AutomationElement GetDesktop() 
    { 
     AutomationElement aeDesktop = AutomationElement.RootElement; 
     return aeDesktop; 
    } 

完全使用看起來像

AutomationElement oAutomationElement = GetElementByName(GetDesktop(), "Part of my apps name");