3

I'm using the Microsoft UI Automation API from within NUnit 2.5.10 tests to perform automated UI testing for a WPF application.

There some cases where running the tests on my development machine is able to locate certain UI elements, but when the same script is run against the same binaries on our build agent machine, it is unable to locate those elements.

I can't find any reason why the agent machine behaves differently. I suspect it has something to do with UIAccess flags or UAC, but haven't come across anything specific.

Can anyone provide some guidance as to why the build agent would have different behavior, or how to fix the agent to see the same elements as my other machines?

For example, I have a comboBox, which has about a dozen options in it. Using the "Inspect Objects" tool from the Win7 SDK, I can see that each option has a child element which has the actual displayed text. So in my test code, I do something like this:

// get the child elements
var options = comboBoxElement.FindAll(TreeScope.Children, (System.Windows.Automation.Condition) new PropertyCondition(AutomationElement.IsControlElementProperty, (object) true));

foreach (AutomationElement child in viewOptions)
{
    var subControls = child.GetChildren();
    Console.WriteLine("Child: {0} w/ {1} children", child.Current.Name,  subControls.Count);
    foreach (AutomationElement subControl in subControls)
        Console.WriteLine("SubControl: {0}", subControl.Current.Name);
}

On my dev machine, I get these results:

Child: My.BoundObject.ClassName w/ 1 children
SubControl: Displayed Text for first item
Child: My.BoundObject.ClassName w/ 1 children
SubControl: Displayed Text for second item
Child: My.BoundObject.ClassName w/ 1 children
SubControl: Displayed Text for third item

But on the server, I get this:

Child: My.BoundObject.ClassName w/ 0 children
Child: My.BoundObject.ClassName w/ 0 children
Child: My.BoundObject.ClassName w/ 0 children

In both cases, Inspect Objects shows the child objects. Inspect Options screenshot

Both the build agent and my local machine are running Windows 7 SP1 with .Net 4. In both cases, I am running the nunit-console.exe to kick off the tests. I'm copying the entire environment between the machines, so not only is it the same version of nunit and my app's binaries, it's exactly the same files, configs, libraries, etc. The nunit-console is running as an Administrator user.

John M. Wright
  • 4,477
  • 1
  • 43
  • 61
  • If you have access to the build agent machine, can you login there, run the the nunit-console manually, and see if the test works? Does adding a sleep before the the find call help? I've seen inadequately spec'd agent machines do things like this. – Mike Zboray Jul 09 '12 at 22:14
  • Running the test manually, either using nunit-console or the GUI-based nunit.exe, both result in the same (missing elements) behavior. – John M. Wright Jul 10 '12 at 12:02

2 Answers2

7

After running the scenarios on multiple machines, I was able to determine that those machines with .Net 4.5 installed were able to access the child elements, while those with only .Net 4.0 were not. Note that the application and tests were all compiled for .Net 4.0.

Hopefully this helps anyone else that comes across this issue.

John M. Wright
  • 4,477
  • 1
  • 43
  • 61
  • +100 - You saved me from further thrashing about in futility !! – Gishu May 31 '13 at 11:34
  • @Gishu, thank you very much! Having thrashed around quite a bit myself before even posting this question, I can empathize with your situation. Stackoverflow for the win! – John M. Wright May 31 '13 at 15:33
  • @JohnM.Wright Can you provide a URL to documentation explaining why it works this way? It doesn't sound all that intuitive to me why this would be the case. – gonzobrains Jul 11 '13 at 17:42
  • @gonzobrains I wasn't able to find any documentation about the changes from 4.0 to 4.5 -- my determination was based solely on observed behavior running my code on multiple machines with either 4.0 or 4.5 installed. Sorry. – John M. Wright Jul 11 '13 at 22:37
  • Okay. I'm just trying to figure out a similar problem I have that is related to not being able to find elements unless I run my client with elevated rights, despite the user account already being an administrator. – gonzobrains Jul 11 '13 at 22:56
0

Please choose user version of windows instead of server versions. i.e. XP/Windows7 over Windows2003/Windows2008. The automation support for UIA is generally poor in server editions of windows.

check out here

Loganswamy
  • 257
  • 2
  • 5
  • 14