WindowClosed event handler not firing

8 posts, 0 answers
  1. kwee
    kwee avatar
    28 posts
    Member since:
    Sep 2011

    Posted 08 Sep 2014 Link to this post

    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
         }
         ...
    }

  2. kwee
    kwee avatar
    28 posts
    Member since:
    Sep 2011

    Posted 08 Sep 2014 in reply to kwee Link to this post

    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.
  3. kwee
    kwee avatar
    28 posts
    Member since:
    Sep 2011

    Posted 09 Sep 2014 in reply to kwee Link to this post

    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,
  4. Cody
    Admin
    Cody avatar
    3360 posts

    Posted 11 Sep 2014 Link to this post

    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
     
  5. kwee
    kwee avatar
    28 posts
    Member since:
    Sep 2011

    Posted 11 Sep 2014 in reply to Cody Link to this post

    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.
  6. Cody
    Admin
    Cody avatar
    3360 posts

    Posted 16 Sep 2014 Link to this post

    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
     
  7. kwee
    kwee avatar
    28 posts
    Member since:
    Sep 2011

    Posted 17 Sep 2014 in reply to Cody Link to this post

    Thanks, it works better now.
  8. Cody
    Admin
    Cody avatar
    3360 posts

    Posted 17 Sep 2014 Link to this post

    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
     
Back to Top