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

How to deal with javascript window.close()

4 Answers 39 Views
General Discussions
This is a migrated thread and some comments may be shown as answers.
This question is locked. New answers and comments are not allowed.
Ron
Top achievements
Rank 1
Veteran
Ron asked on 01 Feb 2012, 11:38 AM
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? 

4 Answers, 1 is accepted

Sort by
0
Ron
Top achievements
Rank 1
Veteran
answered on 01 Feb 2012, 05:23 PM
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. 
0
Anthony
Telerik team
answered on 01 Feb 2012, 07:47 PM
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.
0
Ron
Top achievements
Rank 1
Veteran
answered on 02 Feb 2012, 02:15 PM
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()? 
.



0
Anthony
Telerik team
answered on 02 Feb 2012, 05:09 PM
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.
Tags
General Discussions
Asked by
Ron
Top achievements
Rank 1
Veteran
Answers by
Ron
Top achievements
Rank 1
Veteran
Anthony
Telerik team
Share this question
or