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));
}
}
}


