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

Silverlight - detecting exceptions and handling a dialog

4 Answers 88 Views
General Discussions
This is a migrated thread and some comments may be shown as answers.
Jess
Top achievements
Rank 1
Jess asked on 28 Mar 2012, 03:29 PM
Hello,

I have a couple of issues I'm currently wresting with. 

To start, I'm writing "code only" tests - I only have access to the API, not the full Test Studio. So please, code-only responses.

I have a Silverlight application. It consists of many individual pages with Silverlight (and custom and 3rd party) controls on them. I'm writing a "smoke test" that just iterates through the pages of the application (each URI is kept in the database. In my test I open a connection to the database, read the URI column from the Menu table, construct the full path to the resource and use ActiveBrowser.navigateTo(URI) to go to that page) - the issue is twofold: 

If a page has an exception on it (which is what I'm testing for - pages that throw exceptions when you attempt to load them) it will bring up a dialog box with the exception info on it. How do I capture that dialog and retrieve information from it? It's hard to explain the exact nature of this dialog box - it's not a custom dialog box that we wrote, it's just the 'generic' Silverlight "Error Occured" dialog box which has the exception and a 'drop down button' which, when clicked, opens up a text area with the full exception description on it. Another way of looking at it is: I want to trap (or list or write to Console) every page that throws this type of dialog so I know when pages fail to load (or throw an exception) in my app. Like I said, this is a "smoke test" that simply loads each page in our application and makes sure there are no exceptions encountered. When I do encounter an exception, how do I "mark" it as such or extract information from it?

The second part of the question also has to do with dialog boxes - this time, we have certain pages that, when you navigate to them, the first thing they do is bring up a modal dialog box (actually it's just a control, not of type Modal Dialog box or anything) - basically it can be thought of as just a Modal Silverlight window that is brought up upon page load - I know which pages do this (they all have a certain string present in their URI which I can code for in the test and have already done so) and can attach an event handler or something upon encountering one... but the code I copped from your web site doesn't quite work for me: 

public void DoCustomDialogHandlingForBuiltInDialogs()
 {
    AlertDialog myAlertDialog = new AlertDialog(ActiveBrowser, DialogButton.OK);
    myAlertDialog.HandlerDelegate = new DialogHandlerDelegate(MyCustomAlertHandler);
   
    // Add dialog to monitor and start monitoring
    Manager.DialogMonitor.AddDialog(myAlertDialog);
    Manager.DialogMonitor.Start();
   
    Actions.InvokeScript("InvokeAlert()");
   
 }
   
///<summary>
/// Custom dialog handler delegate
///</summary>
///<param name="dialog">The dialog to handle</param>
///<returns></returns>
public bool MyCustomAlertHandler(IDialog dialog)
{
    // Simply close the dialog
    dialog.Window.Close();
   
    try
    {
         // Wait until it is closed
         dialog.Window.WaitForVisibility(false, 50);
         Log.WriteLine("Alert Handled!");
         return true;
    }
    catch
    {
         Log.WriteLine("Failed to handle alert!");
         // return false if the dialog did not close as expected
         return false;
    }
}

I have connived this into my code but not sure what I've done is correct - I also had to change the return type of the Delegate to be "void" as the compiler complained that the method had the wrong return type. I just commented out the return statements.

Any help is appreciated as always. 

Thanks,

Jess

4 Answers, 1 is accepted

Sort by
0
Asta
Top achievements
Rank 1
answered on 30 Mar 2012, 07:17 AM
maybe this will help
http://www.telerik.com/automated-testing-tools/support/documentation/user-guide/write-tests-in-code/advanced-topics/handling-html-popups-and-dialogs/built-in-dialog-handlers.aspx
0
Anthony
Telerik team
answered on 02 Apr 2012, 05:50 PM
Hello Jess,

I suspect the dialog is not a standard Win32 dialog. Is it derived from a standard Silverlight ChildWindow? If it is then our built-in dialog handlers won't be able to see it. They only handle Win32 dialogs/windows. I suspect that your dialog is a part of the Silverlight application UI, not a separate Windows dialog window. 

My colleagues previously worked on a similar scenario, yet discovered there's no Test Studio code that would run in a background thread that would monitor for the appearance of this popup window and abort the test. There may be .NET code you can use to check for the presence of your fatal error dialog and make the test abort. 

Regards,
Anthony
the Telerik team
Quickly become an expert in Test Studio, check out our new training sessions!
Test Studio Trainings
0
Jess
Top achievements
Rank 1
answered on 03 Apr 2012, 03:28 PM
yeah, I've read the documentation... not pertinent to my situation. Thanks anyway. 
0
Jess
Top achievements
Rank 1
answered on 03 Apr 2012, 03:36 PM
Thanks Anthony - yes it is rather perplexing as to what exactly this Dialog box is - it's not native Win32, it's not HTML, it's not a dialog we created in the application - it's just a Silverlight dialog box that is created when an exception on the page is encountered... There must be *some* way of handing it - I mean... there has to be. I'll figure it out (or they'll fire me and it won't matter, right?)

thanks again
Tags
General Discussions
Asked by
Jess
Top achievements
Rank 1
Answers by
Asta
Top achievements
Rank 1
Anthony
Telerik team
Jess
Top achievements
Rank 1
Share this question
or