cancel
Showing results for 
Search instead for 
Did you mean: 

Using Automation ID to identify objects

Moderator

RE: Using Automation ID to identify objects

Hello,

  I found this forum post useful while helping another customer search for objects based on their automation id. Here's a sample script that works similar to findchild().


function foo ()


{


  var window = Sys.Process("WpfApplication1.vshost").WPFObject("HwndSource: MainWindow", "MainWindow")


  var MyAppDomain = "WpfApplication1.vshost.exe";


  var MyAppProcess = Sys.Process("WpfApplication1.vshost");


  


   myControl = FindByAutomationID (MyAppProcess, MyAppDomain, "button1aid", window, 5 ,false)


   myControl.Click();


}


 


function FindByAutomationID ( objProcess, strAppDomain, strAutomationID, objSearchContainer, intSearchDepth, blCaseSensitive)


{


  AutomationIdProperty = objProcess.AppDomain(strAppDomain).dotNET.System_Windows_Automation.AutomationProperties.AutomationIdProperty


 


  objarrChildren = objSearchContainer.FindAllChildren("Exists", "True", intSearchDepth);


  objarrChildren = objarrChildren.toArray();


  


  if (objarrChildren.length > 0)


  {


    for (ii = 0; ii < objarrChildren.length; ii++)


    {


      if (0 == aqString.Compare(strAutomationID, objarrChildren[ii].GetValue(AutomationIdProperty), blCaseSensitive))


      {


        Log.Message("Found control with automation id '" + strAutomationID + "': " + objarrChildren[ii].FullName);


        return objarrChildren[ii];        


      }


    }


  }


  


  Log.Warning("No control found with automation id: " + strAutomationID);


}


 







This script will successfully find a control defined by the following XAML in a WPF application:

<Button Content="Button1" Height="23" HorizontalAlignment="Left" Margin="252,134,0,0" AutomationProperties.AutomationId="button1AID" VerticalAlignment="Top" Width="75" Background="#E7FC0019" Foreground="#FF000700" BorderBrush="#FF070000" Click="Button_Click_1" >



Of course, you need to modify the window, MyAppProcess, and MyAppDomain variables to match your tested application.



Thanks,

Rick



SmartBear Customer Care
Highlighted
Moderator

RE: Using Automation ID to identify objects


Please forgive me! As it turns out, we already support this. We've had the UI Automation plugin in TestComplete for some time, but I don't think anyone has ever tried to apply it to a WPF application. To enable UIA support in TestComplete: 

 


 

 


1. Go to File->Current Project Properties->Open Applications->UI Automation 

 


2. Enable the asterisk (*) item in the list of accepted windows. 

 


3. Go to File->Current Project Properties->Open Applications->General 

 


4. Move the NativeUIAObject to the top of the priority list. 

 


 

 


TestComplete will now see WPF objects in this way: Sys.Process("WpfApplication1.vshost").UIAObject("WindowNameUIA").UIAObject("button3AID") 

 


 

 


Where WindowNameUI is the AutomationProperties.Name of the main form and button3AID is the AutomationProperties.AutomationId of a button on that form. 

 


 

 


More information is available here: http://support.smartbear.com/viewarticle/55786/



Thanks,

Rick



SmartBear Customer Care

 

Contributor

Re: Using Automation ID to identify objects

Is there any way to enable this for WPF applications without affecting existing name mapping items? Changing the settings as described above seems to cause mappings to work differently.

New Here?
Join us and watch the welcome video:
Top Kudoed Authors