Windows Vista Forums
Vista Forums Home Join Vista Forums Windows 7 Forum Vista Tutorials Tags
Welcome to Windows Vista Forums. Our forum is dedicated to helping you find solutions with any problems, errors or issues you are experiencing with Windows Vista. The Vista forum also covers news and updates and has an extensive Windows Vista tutorial section that covers a wide range of tips and tricks.

Go Back   Vista Forums > Misc Newsgroups > Avalon

Vista - AutomationElement from Window hangs on AutomationElement.Current

 
 
Old 02-24-2006   #1 (permalink)
Peter Fitzgibbons


 
 

AutomationElement from Window hangs on AutomationElement.Current

Hello all,

I am using NUnit to unit test a WPF form. Issues with Nunit MTA threads and
WPF STA Thread requirement have been handled. The NUnit thread now correctly
receives any Assert exceptions from the delegated STA Thread running the WPF
window.

I am also instantiating AutomationElement in order to automate the window
for testing.

AutomationElement instance is hanging on Current property-get. I can
step-through the TestAddressbookWorker() method below and teh debugger (and
run-time out of debug mode) hangs at "x =
aeWindow.Current.BoundingRectangle.Location.X;"
In the CommandWindow-Immediate, inspection of abHelper results in "Function
evaluation timed out." on the AcceleratorKey property and then "Function
evaluation disabled..." on every subsequent property.

I notice that the handle reported by "abHelper.Handle" is not the same as
that reported on teh window by Spy++ during the debug session. I know that
Spy++ is reporting Hex and Handle property is reporting IntPtr integer. The
values from one debug session are :
Spy++ : HxF09CE = 985550
abHelper.Handle : Hx8098A = 526730

I noticed in the WinFX Sample "InvokePattern and ExpandCollapsePattern Menu
Item Sample " that the target window for automation is Win32 and in fact an
instance of Notepad.exe. So I am very curious how to reconcile the sample
with a pure-WinFX example that is calling only XAML windows.

Thank you for your assistance and time investigating tthis one!

using System;
using System.Collections.Generic;
using System.Text;
using System.Threading;
using System.Windows;
using System.Windows.Automation;
using System.Windows.Interop;
using NUnit.Framework;

namespace NunitTest
{
[TestFixture]
public class Class1
{
NUnitHelpers.CrossThreadTestRunner runner = new
NUnitHelpers.CrossThreadTestRunner();

[Test]
public void truthtest()
{
Assert.IsTrue(true);
}

[Test]
public void falsetest()
{
Assert.IsTrue(false);
}

public static void TestAddressbookWorker()
{
Window ab = new AddressBookLib.Window1();
try
{
ab.Show();

WindowInteropHelper abHelper = new WindowInteropHelper(ab);
IntPtr abHwnd = abHelper.Handle;
AutomationElement aeWindow =
AutomationElement.FromHandle(abHwnd);

double x = -1d;
x = aeWindow.Current.BoundingRectangle.Location.X;
Assert.AreEqual(0, x);
}
finally
{
ab.Close();
ab = null;

}

}

[Test]
public void TestAddressBook()
{
runner.RunSTA(new ThreadStart(TestAddressbookWorker));
}

}
}


My System SpecsSystem Spec
 

Thread Tools


Similar Threads
Thread Forum
WLM to open IE in a new tab of the current window Live Messenger
How do I keep the current window on top as new one loads? Browsers & Mail
VS2005 Basic Hangs when changing from Code window to Design Window .NET General
Updating window title bar to current location PowerShell
Vista - ? Mark - Current window Help Vista General


Vista Forums is an independent web site and has not been authorized,
sponsored, or otherwise approved by Microsoft Corporation.
"Windows Vista", the Start Orb, and related materials are trademarks of Microsoft Corp.
© Designer Media Ltd

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46