How to deal with javascript window.close()

5 posts, 0 answers
  1. Ron
    Ron avatar
    48 posts
    Member since:
    Oct 2010

    Posted 01 Feb 2012 Link to this post

    We are using quite a lot modal dialogs which are closed by javascript window.close() calls. What is the preferred method to deal with this? When recording two steps are recorded when clicking a button that calls window.close():

    • Page.MyPage.Button.Click(true)
    • ActiveBrowser.Close()

    Unfortunately by the time that ActiveBrowser.Close() is called, the dialog is already close and the call to ActiveBrowser.Close() results in an error: System.OperationCanceledException: Exception occured waiting for the new browser to connect. ---> System.TimeoutException: Wait for condition has timed out

    Removing ActiveBrowser.Close() is probably not the solution either elements on the page that initiated the opening of the modal dialog, cannot be located anymore. Probably the manager is under the impression that the dialog still exists and tries to locate elements in that dialog? 

  2. Ron
    Ron avatar
    48 posts
    Member since:
    Oct 2010

    Posted 01 Feb 2012 Link to this post

    Reading the documentation the button should have the property ClosesWindow to True to handle controls that close windows. The property is set correctly though. UnexpectedDialogAction is set to HandleAndFailTest and thus the step ActiveBrowser.Close() will fail as expected. Changing the project settings for UnexpectedDialogAction to DoNotHandle allows my test to continue. Unfortunately the test as a whole is registered as Failed due to this failing step. 
  3. Anthony
    Admin
    Anthony avatar
    19 posts

    Posted 01 Feb 2012 Link to this post

    Hello Ron,

    A Modal Popup is not considered a standard Win32 Dialog by Test Studio and should not be affected by the UnexpectedDialogAction. Does closing your Modal window trigger a dialog, like an Alert or Confirm?

    When you record a test that clicks a link in a Modal window that closes it, two steps are recorded:
    • Click 'CloseWindowLink' (ClosesBrowser = True)
    • Close modal pop-up window

    If executed as is, the test fails. If you disable the Close modal step, a subsequent step fails because the ActiveBrowser focus has not returned to the parent window.

    The solution is to convert the Close modal step to code:

    ActiveBrowser.Close();

    Even though the modal window is already closed, this line properly returns focus to the parent window and restores it as ActiveBrowser. If you continue to experience difficulty, please provide more information so we can continue troubleshooting.

    Regards,
    Anthony
    the Telerik team

    Check out Telerik Trainer, the state of the art learning tool for Telerik products.
  4. Ron
    Ron avatar
    48 posts
    Member since:
    Oct 2010

    Posted 02 Feb 2012 Link to this post

    I have changed the recorded Close modal pop-up window step to a coded step containing ActiveBrowser.Close(). To my surprise this actually works. I'm happy things are working, but I was surprised to see this work because I was under the impression that a Close modal pop-up step was executed as ActiveBrowser.Close(). At least the Preview Code option in Test Studio Plug-in suggests that. I guess that the recorded step does more than just call ActiveBrowser.Close()? 
    .



  5. Anthony
    Admin
    Anthony avatar
    19 posts

    Posted 02 Feb 2012 Link to this post

    Hello Ron,

    Yes, the standard Close Modal step and its coded equivalent actually take different paths within the source code.

    We have an existing bug filed so this scenario is handled better during recording and execution.

    Regards,
    Anthony
    the Telerik team

    Check out Telerik Trainer, the state of the art learning tool for Telerik products.
Back to Top
  Cast Your Vote at DevPro Connections! Cast Your Vote at  Win IT Pro Connections!