We are using NUnit to test a WPF control. The text fixture basically opens a test window containing the control to be tested on a new thread. Then the Microsoft UI Automation (UIA) is used to interact with the control.
The new thread shows the window and starts the dispatcher. Things work as expected.
The issue we are running into is that this control can launch a dialog. Once the dialog is launched we need to interact with it and close it. I have been unable to get a reference to this dialog to accomplish this task.
One solution that does not work is to use Application.Current.Windows to get all the windows and then iterate through them until the dialog is found. This does not work because during unit testing Application.Current = null. Now if we only care about this test we can just instantiate an Application. This will however interfere with other tests, because the Application will automatically enter shutting down mode when our Application variable goes out of scope (at the end of the test). As a result other tests will fail (most notably because InitializeComponent typically calls System.Windows.Application.LoadComponent which can't be called during shutting down mode).
I suppose what we need is an alternative to Application.Current.Windows.
Aucun commentaire:
Enregistrer un commentaire