This is a migrated thread and some comments may be shown as answers.

WindowClosed event handler not firing

7 Answers 71 Views
General Discussions
This is a migrated thread and some comments may be shown as answers.
kwee
Top achievements
Rank 1
kwee asked on 08 Sep 2014, 08:15 PM

Hi,

Environment
   - TTF: 2014.3
   - Visual Studio 2012

I am finding that I am not seeing the WindowClosed event handler getting called.
I even set things up so that I manually open and close the window; the event handler
does not seem to be fired.

I'm assuming that TTF does not require any special work to be done by the Wpf client
in order to see the event, right?

Hopefully, someone has some ideas and suggestions.

Thanks in advance,

Below is a sample code :

public class TestClass {
     private bool _winClosed;
     private void WindowClosedEventHandler(object sender, EventArgs e)
     {
         _winClosed = true;
     }
 
     public void CloseWindow()
     {
         var win = wpfClient.WaitForWindow("Header of Window", _settings.ExecuteCommandTimeout);
         win.WindowClosed += WindowClosedEventHandler; // subscribe to event
         _winClosed = false;
         win.Window.SetFocus();
 
         while(!_winClosed) // wait for event handler to set _winClosed to true
         {
             Logger.Debug("Waiting for win to close");
             Pause(500);
         }
         win.WindowClosed -= WindowClosedEventHandler; // unsubscribe to event
     }
     ...
}

7 Answers, 1 is accepted

Sort by
0
kwee
Top achievements
Rank 1
answered on 08 Sep 2014, 10:29 PM
I found a method called AttachWrappedWindow() that I added to the line
before I subscribed my event handler.
win.Window.SetFocus();
win.Window.AttachWrappedWindow();
win.WindowClosed += WindowClosedEventHandler;


However, I still cannot get the handler to fire.
0
kwee
Top achievements
Rank 1
answered on 09 Sep 2014, 03:44 PM
After more investigation, this is what I pieced together.

One, my wpfClient is invoked using wpfClient = Manager.LaunchNewApplication(ClientPath);
I think this runs the client as an out of process application.

Two, the Remarks for AttachedWrappedWindow says
"The window attached to must be in the same process as this window object for it to intercept its messages and fire its events"

So, win is clearly not in the same process as the client application, hence the events are not getting intercepted.

Hopefully, if there is more info I'm missing, please add your piece. Thanks,
0
Cody
Telerik team
answered on 11 Sep 2014, 06:16 PM
Hi Kwee,

I think this runs the client as an out of process application.

Your assesment is correct. We use the .NET Process class to launch your WPF application. This does start it as a separate process disconnected from our test runner.

Now let's come back to your problem from a high level. Why do you want to get the closed event in the first place? What automation challenge are you trying to solve? Maybe there's a different method to get the same result.

Regards,
Cody
Telerik
 
Quickly become an expert in Test Studio, check out our new training sessions!
Test Studio Trainings
 
0
kwee
Top achievements
Rank 1
answered on 11 Sep 2014, 06:54 PM
I have a Wpf application that I start with Manager.LaunchNewApplication(<path>)
and close with MainWindow.Window.Close(). I needed a way to confirm that the
application is indeed closed before I proceed to the next action.

When I tried MainWindow.Window.Wait.NotExist, but it did not work with "Unable to find"
error.

If you have other ideas, it would be helpful.
0
Cody
Telerik team
answered on 16 Sep 2014, 06:49 PM
Hello Kwee,

Try this instead:
ActiveApplication.MainWindow.Window.Close();
ActiveApplication.MainWindow.Window.WaitForVisibility(false, 5000, true);


Regards,
Cody
Telerik
 
Quickly become an expert in Test Studio, check out our new training sessions!
Test Studio Trainings
 
0
kwee
Top achievements
Rank 1
answered on 18 Sep 2014, 03:08 AM
Thanks, it works better now.
0
Cody
Telerik team
answered on 18 Sep 2014, 04:08 AM
Hi,

Excellent! Glad I could help.

Regards,
Cody
Telerik
 
Quickly become an expert in Test Studio, check out our new training sessions!
Test Studio Trainings
 
Tags
General Discussions
Asked by
kwee
Top achievements
Rank 1
Answers by
kwee
Top achievements
Rank 1
Cody
Telerik team
Share this question
or