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

Verifying Alert Dialogs

7 Answers 277 Views
General Discussions
This is a migrated thread and some comments may be shown as answers.
Paul
Top achievements
Rank 1
Paul asked on 09 Nov 2011, 09:52 PM
I am new to Test Studio.  I've created a script against an internal web application which requires a date input.  The script enters the date from an Excel file and then processes the data for that date.  Works great.

But if an invalid date is entered, then a Windows "Message from webpage" alert dialog pops up.  In this case, I want the script to take a different path.  I am able to insert a "Handle 'Alert' dialog" step.  But this is not conditional.

Test Studio apparently doesn't see the alert as a screen element because it's not in the DOM.  So how do I create a verification step to check if the alert has popped up or not?  Or more accurately, how do I get the test to perform different steps if the alert has popped up?

7 Answers, 1 is accepted

Sort by
0
Anthony
Telerik team
answered on 10 Nov 2011, 07:28 PM
Hi Paul,

As part of best practices, we recommend creating two test cases in a scenario like this. We often see testers fall into the trap of trying to accomplish too much in a single test.

We suggest doing it this way:
  1. ValidDateTest - this test is bound to an Excel file that only contains valid dates. Test steps reflect a valid scenario.
  2. InvalidDateTest - this test is bound to an Excel file that only contains invalid dates. Includes a Handle Alert Dialog step.

This keeps things simple for test creation and maintenance, and avoids using code when not absolutely necessary. Although these scenarios are now broken into two tests, you can still execute them sequentially in a Test List (likely with the RecycleBrowser Test List Setting as True) or called from a master test via the Test as Step feature.

Best wishes,
Anthony
the Telerik team
Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items
0
Paul
Top achievements
Rank 1
answered on 10 Nov 2011, 07:36 PM
I won't be able to control the list of dates to ensure they're valid.  Our tester will maintain the .csv file entering dates that she'll be testing with daily.  I'd like to avoid getting calls about the script failing because of bad dates.

I read something about the DialogMonitor class.  Is it possible to use this to check if the dialog pops up?  And then follow a different path if it does?
0
Anthony
Telerik team
answered on 11 Nov 2011, 10:29 PM
Hi Paul,

Please see the test I attached. It demonstrates how I overcame the issue:

  • Iteration 1 intentionally succeeds and iteration 2 intentionally fails.
  • Instead of inserting a standard Handle Alert Dialog step, I handle the Submit Click step and the Alert Handler in a coded step. This effectively handles the alert if present and does nothing if not present. (Note the using ArtOfTest.WebAii.Win32.Dialogs; statement in the code-behind file by clicking View Class.)
  • I then used a standard IF/ELSE Logical step to fork the test. The condition for the IF is whether the Valid Email Required font tag exists. It is important to use a Verify/Wait For Exists here, as a different type of verification can result in an Unable To Locate Element failure.

Here's the code from the coded step:

Manager.DialogMonitor.AddDialog(AlertDialog.CreateAlertDialog(ActiveBrowser, DialogButton.OK));
Manager.DialogMonitor.Start();
 
Pages.AviomGetAnOnSiteDemo.Submit.Click();


Please run the test and let me know if you encounter any trouble adapting this technique to your test.

Kind regards,
Anthony
the Telerik team
Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items
0
Paul
Top achievements
Rank 1
answered on 14 Nov 2011, 08:16 PM
I'm unable to open this test in Test Studio.  I'm getting the error: "An unexpected error occurred in Test Studio.  The error has been reported to the Telerik team."  Do you want to save your work?
0
Anthony
Telerik team
answered on 14 Nov 2011, 11:08 PM
Hi Paul,

That could possibly be because I created the test with a newer version of Test Studio than you are using. See the full test project attached, this time created in version 2011.2.928.

I also included screen shots of the Steps and Local Data test views to demonstrate visually what the test is doing.

All the best,
Anthony
the Telerik team
Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items
0
Paul
Top achievements
Rank 1
answered on 15 Nov 2011, 03:12 PM
Anthony,
Thanks for the example.  I am not clear on the IF step (15) which tests the presence of ValidFontTag.  I looked in the DOM and don't see anything with this value.  Are you testing for the presence of a value in the email field?  Or are you testing that the alert appeared?

Please call me to discuss this.  860-766-7009.  24-hours between forum/email communication is taking way too long to resolve this.

Thanks,
Paul
0
Anthony
Telerik team
answered on 15 Nov 2011, 04:55 PM
Hi Paul,

The ValidFontTag element is only present on the page when you omit a required field and click Submit. The second iteration in my example omits the email field. In that iteration, this element exists and has a TextContent of Vaild Email Required. So, I'm not basing the IF on the presence of the dialog, but rather an element unique to the page state when the email field is missing.

This verification is unique to this example and you'll need to find a unique element on which to base your Wait For Exists verification. This element will need to exist in scenario one (IF) but not in scenario two (ELSE).

Here is a new troubleshooting guide on IF/ELSE steps and how to craft a proper verification to attach to the IF portion.

Unfortunately we do not offer phone support. However, I assure you prompt responses despite this being a forum post. If you continue to have difficulty after reviewing the information and article above, we can schedule a GoToMeeting. 

Regards,
Anthony
the Telerik team
Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items
Tags
General Discussions
Asked by
Paul
Top achievements
Rank 1
Answers by
Anthony
Telerik team
Paul
Top achievements
Rank 1
Share this question
or