One of our users had a webpage with a form. When it was submitted partially filled, the page came back (after being processed on the backend) with some errors about incomplete form. If the user tried to navigate away from this page via a link (or close the page/browser tab) he was prompted with browser's standard "Are you sure you want to leave this page?" dialog. He needed a way for Rapise to handle this popup when recording and playing back the web test.
What's happening is that when the user tries to navigate away from this page via a link (or close the page/browser tab) he's prompted with browser's standard:
  • "Are you sure you want to leave this page?" dialog
  • with "Leave this page" and "Stay on this page" buttons
Every web browser has a slightly different message, (the message text here is from IE; other browsers will display different text, but the behavior is the same). For example, see the screenshot below:



They had tried the following code in Rapise:
  • DoSetExpectedConfirmResult() and DoSetExpectedPromptResult()

Both following pieces of code have no effect - the dialog displays anyway.

Navigator.DoSetExpectedConfirmResult(false);
SeS('Cancel').DoClick();    // click "Cancel" link
Navigator.DoCheckConfirmation("Are you sure you want to leave this page?");

Navigator.DoSetExpectedPromptResult(false);
SeS('Cancel').DoClick();    // click "Cancel" link
Navigator.DoCheckPrompt("Are you sure you want to leave this page?");

Now, some other testing tools (e.g. Selenium) that only can handle browser events by calling the browser event directly, require complex workarounds, e.g. suppressing the popup by providing empty callback function for window.onbeforeunload() as follows:

window.onunload = function() {};

However, because Rapise can also simulate mouse clicks using the DoLClick() function, there is an easier way.

When recording, simply learn the Cancel button using CTRL+2 during recording.

Now we cannot use the normal code:

SeS('Cancel').DoClick();

blocks because it sends event, and event calls onbeforeunload handler that is stuck. So we need to use the "real click" LClick method instead, like this:

SeS('Cancel').DoLClick();

// Now popup may show up, wait a bit
Global.DoSleep(500);

// Now press 'Leave'. Simplest way - just press Enter key, because leave is focused by default
Global.DoSendKeys("{ENTER}");

And voila, it will now handle the case correctly.
Attachments

Selected files will be attached to any email sent on saving ticket.

file selected files selected  () Delete Selected

  • Created:
  • by:

Select files to upload

Or drag and drop files here

Uploading …
Done!
Upload More?
There was an error.
Try again?

Save to upload the selected file(s)

Article Info
  • Last Updated: 1/18/2017
  • Article ID: KB232
  • Views: 512