Question

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.

Was it helpful?

Solution

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.

OTHER TIPS

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

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top